0

Using C++11 (or C++14), I'd like to specialize std::char_traits for unsigned char, but only if !std::is_same<char, unsigned char>::value. (Since std::char_traits<char> already exists.)

So I currently have such a specialization, which begins like this:

namespace std {
template<>
struct char_traits<unsigned char> {
    using char_type = unsigned char;
    etc...

The question is if there is a way I can make this specialization "not exist" via SFINAE if std::is_same<char, unsigned char>::value. All the examples I can find for enabling/disabling specializations depend on the non-specialized template having a dummy template parameter for enabling. I obviously can't change std::char_traits in this way. Is there a path I am missing?

md5i
  • 3,018
  • 1
  • 18
  • 32
  • 4
    1) `char` and `unsigned char` are always distinct types, even if `char` is unsigned. 2) I don't think `char_traits` is exempt from the "user specializations must depend on a user-defined type" rule – T.C. Dec 03 '15 at 08:28
  • T.C.: 1) Good point. That should obviate my need. 2) Ugh. I see that in the standard. So specializing `uint8_t` is technically prohibited? (I use `static_assert` to ensure that `uint8_t` is an `unsigned char`.) – md5i Dec 03 '15 at 14:08

0 Answers0