cpprestsdk icon indicating copy to clipboard operation
cpprestsdk copied to clipboard

Add char_traits<uint8_t>

Open placintaalexandru opened this issue 8 months ago • 5 comments

Fixes 1812

char_traits<uint8_t> type was not supplied

placintaalexandru avatar Apr 10 '25 13:04 placintaalexandru

@microsoft-github-policy-service agree

placintaalexandru avatar Apr 10 '25 13:04 placintaalexandru

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.

BillyONeal avatar May 05 '25 19:05 BillyONeal

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 of basic_string<uint8_t>, and finally,
  • making basic_ostream::print a function template to accept different traits types.

frederick-vs-ja avatar Nov 04 '25 10:11 frederick-vs-ja

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.

leakingmemory avatar Nov 04 '25 10:11 leakingmemory

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.

frederick-vs-ja avatar Nov 05 '25 03:11 frederick-vs-ja