In the case where the OP is interested in how strings are implemented in the STL, they use the entire invocation of the char_traits helper class. This is a class in which there is nothing but static member functions, and char_traits is specialized for char and wchar_t to use C runtime library functions such as memmove.
For example, you have a comparison function that returns the value <0, 0, or> 0. If the type is char, it can use memcmp. Where is the type wchar_t, it can use a wide equivalent.
It works something like this:
template< typename Element >
class char_traits
{
public:
static int compare( const Element * left, const Element * right, size_t length )
{
for( const Element * end = left + length; left != end; ++left )
{
if( left < right )
return -1;
else if( left > right )
return 1;
}
return 0;
}
};
template <> class char_traits<char> // I think this is the syntax
{
public:
int compare( const char * left, const char * right, size_t len )
{
return memcmp( left, right, len );
}
};
source
share