[char.traits.specializations] # 27 Strings library [[strings]](./#strings) ## 27.2 Character traits [[char.traits]](char.traits#specializations) ### 27.2.4 char_traits specializations [char.traits.specializations] #### [27.2.4.1](#general) General [[char.traits.specializations.general]](char.traits.specializations.general) [🔗](#lib:char_traits) namespace std {template<> struct char_traits; template<> struct char_traits; template<> struct char_traits; template<> struct char_traits; template<> struct char_traits;} [1](#general-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L262) The header [](string.syn#header:%3cstring%3e "27.4.2 Header synopsis [string.syn]") defines five specializations of the class templatechar_traits:char_traits<​char>,char_traits,char_traits,char_traits, andchar_traits[.](#general-1.sentence-1) #### [27.2.4.2](#char) struct char_traits [[char.traits.specializations.char]](char.traits.specializations.char) [🔗](#lib:char_traits_) namespace std {template<> struct char_traits {using char_type = char; using int_type = int; using off_type = streamoff; using pos_type = streampos; using state_type = mbstate_t; using comparison_category = strong_ordering; static constexpr void assign(char_type& c1, const char_type& c2) noexcept; static constexpr bool eq(char_type c1, char_type c2) noexcept; static constexpr bool lt(char_type c1, char_type c2) noexcept; static constexpr int compare(const char_type* s1, const char_type* s2, size_t n); static constexpr size_t length(const char_type* s); static constexpr const char_type* find(const char_type* s, size_t n, const char_type& a); static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* assign(char_type* s, size_t n, char_type a); static constexpr int_type not_eof(int_type c) noexcept; static constexpr char_type to_char_type(int_type c) noexcept; static constexpr int_type to_int_type(char_type c) noexcept; static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; static constexpr int_type eof() noexcept; };} [1](#char-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L308) The type mbstate_t is defined in [](cwchar.syn#header:%3ccwchar%3e "28.7.3 Header synopsis [cwchar.syn]") and can represent any of the conversion states that can occur in animplementation-defined set of supported multibyte character encoding rules[.](#char-1.sentence-1) [2](#char-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L314) The two-argument member assign is defined identically to the built-in operator =[.](#char-2.sentence-1) The two-argument members eq and lt are defined identically to the built-in operators== and < for type unsigned char[.](#char-2.sentence-2) [3](#char-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L320) The membereof() returnsEOF[.](#char-3.sentence-1) #### [27.2.4.3](#char8.t) struct char_traits [[char.traits.specializations.char8.t]](char.traits.specializations.char8.t) [🔗](#lib:char_traits__) namespace std {template<> struct char_traits {using char_type = char8_t; using int_type = unsigned int; using off_type = streamoff; using pos_type = u8streampos; using state_type = mbstate_t; using comparison_category = strong_ordering; static constexpr void assign(char_type& c1, const char_type& c2) noexcept; static constexpr bool eq(char_type c1, char_type c2) noexcept; static constexpr bool lt(char_type c1, char_type c2) noexcept; static constexpr int compare(const char_type* s1, const char_type* s2, size_t n); static constexpr size_t length(const char_type* s); static constexpr const char_type* find(const char_type* s, size_t n, const char_type& a); static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* assign(char_type* s, size_t n, char_type a); static constexpr int_type not_eof(int_type c) noexcept; static constexpr char_type to_char_type(int_type c) noexcept; static constexpr int_type to_int_type(char_type c) noexcept; static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; static constexpr int_type eof() noexcept; };} [1](#char8.t-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L359) The two-argument members assign, eq, and lt are defined identically to the built-in operators =, ==, and < respectively[.](#char8.t-1.sentence-1) [2](#char8.t-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L364) The member eof() returns animplementation-defined constant that cannot appear as a valid UTF-8 code unit[.](#char8.t-2.sentence-1) #### [27.2.4.4](#char16.t) struct char_traits [[char.traits.specializations.char16.t]](char.traits.specializations.char16.t) [🔗](#lib:char_traits___) namespace std {template<> struct char_traits {using char_type = char16_t; using int_type = uint_least16_t; using off_type = streamoff; using pos_type = u16streampos; using state_type = mbstate_t; using comparison_category = strong_ordering; static constexpr void assign(char_type& c1, const char_type& c2) noexcept; static constexpr bool eq(char_type c1, char_type c2) noexcept; static constexpr bool lt(char_type c1, char_type c2) noexcept; static constexpr int compare(const char_type* s1, const char_type* s2, size_t n); static constexpr size_t length(const char_type* s); static constexpr const char_type* find(const char_type* s, size_t n, const char_type& a); static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* assign(char_type* s, size_t n, char_type a); static constexpr int_type not_eof(int_type c) noexcept; static constexpr char_type to_char_type(int_type c) noexcept; static constexpr int_type to_int_type(char_type c) noexcept; static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; static constexpr int_type eof() noexcept; };} [1](#char16.t-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L405) The two-argument members assign,eq, and lt are defined identically to the built-in operators =, ==, and<, respectively[.](#char16.t-1.sentence-1) [2](#char16.t-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L411) The member eof() returns animplementation-defined constant that cannot appear as a valid UTF-16 code unit[.](#char16.t-2.sentence-1) #### [27.2.4.5](#char32.t) struct char_traits [[char.traits.specializations.char32.t]](char.traits.specializations.char32.t) [🔗](#lib:char_traits____) namespace std {template<> struct char_traits {using char_type = char32_t; using int_type = uint_least32_t; using off_type = streamoff; using pos_type = u32streampos; using state_type = mbstate_t; using comparison_category = strong_ordering; static constexpr void assign(char_type& c1, const char_type& c2) noexcept; static constexpr bool eq(char_type c1, char_type c2) noexcept; static constexpr bool lt(char_type c1, char_type c2) noexcept; static constexpr int compare(const char_type* s1, const char_type* s2, size_t n); static constexpr size_t length(const char_type* s); static constexpr const char_type* find(const char_type* s, size_t n, const char_type& a); static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* assign(char_type* s, size_t n, char_type a); static constexpr int_type not_eof(int_type c) noexcept; static constexpr char_type to_char_type(int_type c) noexcept; static constexpr int_type to_int_type(char_type c) noexcept; static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; static constexpr int_type eof() noexcept; };} [1](#char32.t-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L451) The two-argument members assign,eq, and lt are defined identically to the built-in operators =, ==, and<, respectively[.](#char32.t-1.sentence-1) [2](#char32.t-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L457) The member eof() returns animplementation-defined constant that cannot appear as a Unicode code point[.](#char32.t-2.sentence-1) #### [27.2.4.6](#wchar.t) struct char_traits [[char.traits.specializations.wchar.t]](char.traits.specializations.wchar.t) [🔗](#lib:char_traits_____) namespace std {template<> struct char_traits {using char_type = wchar_t; using int_type = wint_t; using off_type = streamoff; using pos_type = wstreampos; using state_type = mbstate_t; using comparison_category = strong_ordering; static constexpr void assign(char_type& c1, const char_type& c2) noexcept; static constexpr bool eq(char_type c1, char_type c2) noexcept; static constexpr bool lt(char_type c1, char_type c2) noexcept; static constexpr int compare(const char_type* s1, const char_type* s2, size_t n); static constexpr size_t length(const char_type* s); static constexpr const char_type* find(const char_type* s, size_t n, const char_type& a); static constexpr char_type* move(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* copy(char_type* s1, const char_type* s2, size_t n); static constexpr char_type* assign(char_type* s, size_t n, char_type a); static constexpr int_type not_eof(int_type c) noexcept; static constexpr char_type to_char_type(int_type c) noexcept; static constexpr int_type to_int_type(char_type c) noexcept; static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; static constexpr int_type eof() noexcept; };} [1](#wchar.t-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L497) The two-argument membersassign,eq, andlt are defined identically to the built-in operators=,==, and<, respectively[.](#wchar.t-1.sentence-1) [2](#wchar.t-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L511) The membereof() returnsWEOF[.](#wchar.t-2.sentence-1)