public static member function
<string>

std::char_traits::eq

static bool eq (const char_type& c, const char_type& d);
static constexpr bool eq (char_type c, char_type d) noexcept;
Compare characters for equality
Returns whether characters c and d are considered equal.

In the standard specializations of char_traits, this function behaves as the built-in operator==, but custom character traits classes may provide an alternative behavior.
In the standard specializations of char_traits, this function behaves as the built-in operator== for type unsigned char, but custom character traits classes may provide an alternative behavior.

Parameters

c, d
Character values.
Member type char_type is the character type (i.e., the class template parameter in char_traits).

Return Value

true if c is considered equal to d.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// char_traits::eq
#include <iostream>   // std::cout
#include <string>     // std::basic_string, std::char_traits
#include <cctype>     // std::tolower
#include <cstddef>    // std::size_t

// traits with case-insensitive eq:
struct custom_traits: std::char_traits<char> {
  static bool eq (char c, char d) { return std::tolower(c)==std::tolower(d); }
  // some (non-conforming) implementations of basic_string::find call this instead of eq:
  static const char* find (const char* s, std::size_t n, char c)
  { while( n-- && (!eq(*s,c)) ) ++s; return s; }
};

int main ()
{
  std::basic_string<char,custom_traits> str ("Test");
  std::cout << "T found at position " << str.find('t') << '\n';
  return 0;
}


Output:
T found at position 0

Complexity

Constant.

Exception safety

No-throw guarantee: this member function never throws exceptions in any of the standard specializations.

See also