Add char_traits<uint8_t>
@microsoft-github-policy-service agree
This PR introduces undefined behavior: https://eel.is/c++draft/requirements#namespace.std-2
There is no program-defined type here. This also fails if 2 libraries try to do this.
I guess a proper fix would be
- introducing a customized traits type (shown as
custom_char_traits<uint8_t>later, but not necessary templatized), - using
basic_string<uint8_t, custom_char_traits<uint8_t>>instead ofbasic_string<uint8_t>, and finally, - making
basic_ostream::printa function template to accept different traits types.
Using unsigned types with any of the string and stream templates is a can of worms. As far as I know the C++ standard does not mandate the standard library to support unsigned char types in those. I think ideally only the standard char types should be used, and applications using stream apis should convert from and to unsigned types if they need to in application code. But it would unfortunately be a breaking change.
As far as I know the C++ standard does not mandate the standard library to support unsigned char types in those.
basic_string is required to support using them as element types ([strings.general]/1). But char_traits, along with stream and locale stuffs, are not.