|
Thinking In C++. Volume 2: Practical ProgrammingInline member functions of a class template, on the other hand, can be included in a header file, and thus facilitate compile-time optimization. In Chapter 3 you saw how traits are used to control the character-processing functionality used by the string classes. The classes std::string and std::wstring are specializations of the std::basic_string template, which is defined as follows: template<class charT, В class traits = char_traits<charT>, В class allocator = allocator<charT> > В class basic_string; The template parameter charT represents the underlying character type, which is usually either char or wchar_t. The primary char_traits template is typically empty, and specializations for char and wchar_t are provided by the standard library. Here is the specification of the specialization char_traits<char> according to the C++ standard:. When you declare a string variable, such as:. std::string s; you are actually declaring s as follows (because of the default template arguments in the specification of basic_string): std::basic_string<char, std::char_traits<char>, В В В std::allocator<char> > s; Because the character traits have been separated from the basic_string class template, you can supply a custom traits class to replace std::char_traits ...» |
Код для вставки книги в блог HTML
phpBB
текст
|
|