24 Strings library [strings]

24.2 Character traits [char.traits]

24.2.3 char_­traits specializations [char.traits.specializations]

namespace std {
  template<> struct char_traits<char>;
  template<> struct char_traits<char16_t>;
  template<> struct char_traits<char32_t>;
  template<> struct char_traits<wchar_t>;
}

Заголовок <string> определяет четыре специализации шаблона класса char_­traits: char_­traits<​char>, char_­traits<char16_­t>, char_­traits<char32_­t>, и char_­traits<wchar_­t>.

Требования к участникам этих специализаций приведены в п [char.traits.require].

24.2.3.1 struct char_­traits<char> [char.traits.specializations.char]

namespace std {
  template<> struct char_traits<char> {
    using char_type  = char;
    using int_type   = int;
    using off_type   = streamoff;
    using pos_type   = streampos;
    using state_type = mbstate_t;

    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 char_type* move(char_type* s1, const char_type* s2, size_t n);
    static char_type* copy(char_type* s1, const char_type* s2, size_t n);
    static 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;
  };
}

Определенные типы для int_­type, pos_­type, off_­typeи state_­type должно быть int, streampos, streamoffи mbstate_­t соответственно.

Типstreampos должен быть типом , определяемым реализацией, который удовлетворяет требованиям pos_­type в [iostreams.limits.pos] и [iostream.forward].

Типstreamoff должен быть типом , определяемым реализацией, который удовлетворяет требованиям off_­type в [iostreams.limits.pos] и [iostream.forward].

Тип mbstate_­t определяется <cwchar> и может представлять любое из состояний преобразования, которое может происходить в определяемом реализацией наборе поддерживаемых правил кодирования многобайтовых символов.

Член с двумя аргументами assign должен быть определен идентично встроенному оператору =. Члены с двумя аргументами eq и lt должны быть определены идентично встроенным операторам == и < типу unsigned char.

Член eof() должен вернуться EOF.

24.2.3.2 struct char_­traits<char16_­t> [char.traits.specializations.char16_t]

namespace std {
  template<> struct char_traits<char16_t> {
    using char_type  = char16_t;
    using int_type   = uint_least16_t;
    using off_type   = streamoff;
    using pos_type   = u16streampos;
    using state_type = mbstate_t;

    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 char_type* move(char_type* s1, const char_type* s2, size_t n);
    static char_type* copy(char_type* s1, const char_type* s2, size_t n);
    static 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;
  };
}

Типu16streampos должен быть типом , определяемым реализацией, который удовлетворяет требованиям pos_­type в [iostreams.limits.pos] и [iostream.forward].

Члены двух аргументов assign, eqи lt должны быть определены тождественны встроенными операторами =, ==и < соответственно.

Член eof() должен возвращать константу, определяемую реализацией, которая не может отображаться как допустимая кодовая единица UTF-16.

24.2.3.3 struct char_­traits<char32_­t> [char.traits.specializations.char32_t]

namespace std {
  template<> struct char_traits<char32_t> {
    using char_type  = char32_t;
    using int_type   = uint_least32_t;
    using off_type   = streamoff;
    using pos_type   = u32streampos;
    using state_type = mbstate_t;

    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 char_type* move(char_type* s1, const char_type* s2, size_t n);
    static char_type* copy(char_type* s1, const char_type* s2, size_t n);
    static 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;
  };
}

Типu32streampos должен быть типом , определяемым реализацией, который удовлетворяет требованиям pos_­type в [iostreams.limits.pos] и [iostream.forward].

Члены двух аргументов assign, eqи lt должны быть определены тождественны встроенными операторами =, ==и < соответственно.

Член eof() должен возвращать константу, определяемую реализацией, которая не может отображаться как кодовая точка Unicode.

24.2.3.4 struct char_­traits<wchar_­t> [char.traits.specializations.wchar.t]

namespace std {
  template<> struct char_traits<wchar_t> {
    using char_type  = wchar_t;
    using int_type   = wint_t;
    using off_type   = streamoff;
    using pos_type   = wstreampos;
    using state_type = mbstate_t;

    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 char_type* move(char_type* s1, const char_type* s2, size_t n);
    static char_type* copy(char_type* s1, const char_type* s2, size_t n);
    static 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;
  };
}

Определенные типы для int_­type, pos_­typeи state_­type должны быть wint_­t, wstreamposи mbstate_­t соответственно.

Типwstreampos должен быть типом , определяемым реализацией, который удовлетворяет требованиям pos_­type в [iostreams.limits.pos] и [iostream.forward].

Тип mbstate_­t определяется <cwchar> и может представлять любое из состояний преобразования, которое может происходить в определяемом реализацией наборе поддерживаемых правил кодирования многобайтовых символов.

Члены двух аргументов assign, eqи lt должны быть определены тождественны встроенными операторами =, ==и < соответственно.

Член eof() должен вернуться WEOF.