using msvc 14, i would like to check a const char* argument as a non-type template argument.
template <typename T, const char Key[] = nullptr > class Base { public: Base() {} void f_not_null() { static_assert(Key != nullptr, "may be not null"); } void f_null() { static_assert(Key == nullptr, "may be null"); } }; extern const char A_STRING[] = "a string"; Base<int, A_STRING> test; test.f_not_null(); Base<int> test1; test1.f_null(); The code below does not compile due to error C2131: expression did not evaluate to a constant on static_assert(Key != nullptr, "may be not null") when declaring Base<int, A_STRING>.
If possible I would not like to use a wrapper as a workaround:
template <const char *str> class Str { }; Base<int, Str<A_STRING> > test; [...] Is there a way to make this possible?