简体   繁体   中英

std::basic_string specialization

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

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

I need to have a class that behaves as CustomString, but with the length function changed.

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

Then you don't even need to specify all the template parameters when instantiating a basic_string . The following definition should be enough:

typedef std::basic_string<CustomChar> CustomString;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM