First of all, I assume with C++20 we have a constexpr std::string in C++20. If that is the case, it should be possible to write something like:
struct MyType { constexpr MyType(int n_):n{n_}{}; int n; };
template < auto a > struct Something {};
template <> struct Something< MyType{1} > { void Do() { std::cout << "Special One" << std::endl;} };
template <> struct Something< MyType{2} > { void Do() { std::cout << "Super Two" << std::endl;} };
int main()
{
Something<MyType{1}> s; // works fine as expected
s.Do();
Something< std::string("Hallo")> s2; // did not work. See error message below
}
But gcc 10.1 complains, that std::string
is not a literal type because the destructor is not constexpr
. But if I understand the current standard correctly, std::string
should be "fully" constexpr.
I am wrong? Or is the current STL from gcc not c++20 "ready"?
Full error message from gcc 10.1 ( same with current g++ trunk ).
/usr/include/c++/10/bits/basic_string.h:77:11: note: 'std::__cxx11::basic_string<char>' is not literal because:
77 | class basic_string
| ^~~~~~~~~~~~
/usr/include/c++/10/bits/basic_string.h:77:11: note: 'std::__cxx11::basic_string<char>' does not have 'constexpr' destructor