char-traits

What is the point of STL Character Traits?

牧云@^-^@ 提交于 2019-12-17 17:23:48
问题 I notice that in my copy of the SGI STL reference, there is a page about Character Traits but I can't see how these are used? Do they replace the string.h functions? They don't seem to be used by std::string , e.g. the length() method on std::string doesn't make use of the Character Traits length() method. Why do Character Traits exist and are they ever used in practice? 回答1: Character traits are an extremely important component of the streams and strings libraries because they allow the

C++ std::basic_string/char_traits specialization

倾然丶 夕夏残阳落幕 提交于 2019-12-14 03:12:59
问题 This is related to: std::basic_string specialization and Circumventing template specialization I tried the solution from std::basic_string specialization, but the problem is that CustomChar is a typedef for wchar_t and I have redefinition(conflict with specialization from std). How may I avoid usage of chart_traits when I'm not allowed to change CustomChar typedef? 回答1: You could use Boost's/C++0x's disable_if to disable if there are known previous instantiations, like in the case of char and

Why does this specialized char_traits<uint8_t> and codecvt<uint8_t> for use with the basic_ifstream template throw std::bad_cast?

拈花ヽ惹草 提交于 2019-11-29 13:23:59
问题 There are already questions here on Stackoverflow asking why basic_fstream<uint8_t> doesn't work. The answers say that char_traits is only specialized for char and wchar_t (plus char16_t , char32_t in C++11) and you should stick with basic_fstream<char> to read binary data and cast it if required. Well darn it, that isn't good enough! :) None of the answers (that I can find) say how to specialize char_traits<uint8_t> and use it with a basic_fstream template, or if it's even possible. So I

What is the point of STL Character Traits?

偶尔善良 提交于 2019-11-28 02:41:16
I notice that in my copy of the SGI STL reference, there is a page about Character Traits but I can't see how these are used? Do they replace the string.h functions? They don't seem to be used by std::string , e.g. the length() method on std::string doesn't make use of the Character Traits length() method. Why do Character Traits exist and are they ever used in practice? Character traits are an extremely important component of the streams and strings libraries because they allow the stream/string classes to separate out the logic of what characters are being stored from the logic of what