I want to make a custom char_traits class for my own type. I have declared all the functions, but I am having some confusion regarding vague semantics given in the standard.
What are
fpos_type,off_typeandstate_typeexpected to do? Where are they required, if at all?Standard says to keep
traits::eof()and valid code points separate and thus asks to use anint_typewhich is bigger than thechar_type. But can I then make mychar_typeas a signed number where I know valid code points are only in the non-negative range. It leaves me with negative values as possible values oftraits::eof(). Or should it be thatint_typeshould be a proper superset ofchar_typeso that nochar_typecan ever take the value ofeof()? Being more to the point, can I makeint_typeandchar_typeto be same?
std::fposis a class that encapsulates file positioning semantics for file streams. It uses the current conversion state to identify file positions.off_typeandpos_typeare types defined instd::char_traitsthat are types for offset types and position types respectively.pos_typeis used as arguments to seek functions and is the type returned from the tell functions. It is a type denoting absolute positions.off_typeis used in the overloads of the seek functions for specifying offsets from a provided file position.state_typeis also defined instd::char_traits. It is used for specifying the conversion state of a multibyte sequence.You can look up all the requirements for these types in
[char.traits.require].This is the definition of
traits::int_type-[char.traits.typedef]This definition carries with it the implication that
int_typemerely be able to to represent values of typechar_type, and also theeof()value. It defines no further requirements for the type other than what types it aliases for certain specializations ofstd::char_traits