Std :: basic_string specialization

I need to override only the length function from std :: basic_string, because it is not suitable for a custom char type on a specific platform. This is the current declaration for, say, CustomString

typedef STL::basic_string<CustomChar, STL::char_traits<CustomChar>, STL::allocator<CustomChar> > CustomString; 

I need a class that behaves like a CustomString, but with a modified length function.

+4
source share
1 answer

You need to specialize the structure of std::char_traits and override its function static size_t length(const char_type* s); , to do this.

Then you do not even need to specify all the template parameters when creating the basic_string instance. The following definition should be sufficient:

 typedef std::basic_string<CustomChar> CustomString; 
+7
source

All Articles