VS2019 16.10 is supposed to include support for the C++20 constexpr for std::string and std::vector. So why doesn't this work? What have I overlooked??
1 2 3 4 5 6 7 8 9
#include <string>
#include <vector>
int main()
{
constexpr std::string s {"qwe"};
constexpr std::vector<int> vi {1, 2, 3, 4, 5};
}
1>Source.cpp
1>C:\develop\vc\test64\Source.cpp(6,26): error C2131: expression did not evaluate to a constant
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xstring(4602,50): message : failure was caused by allocated storage not being deallocated
1>C:\develop\vc\test64\Source.cpp(8,32): error C2131: expression did not evaluate to a constant
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\vector(1711,47): message : failure was caused by allocated storage not being deallocated
1>c:\develop\vc\Library\files.hpp(76,18): warning C4018: '<=': signed/unsigned mismatch
1>Done building project "test64.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
My understanding is that you can construct a string in a constexpr context but the assigned storage can not be carried over to the runtime context. see around 6:10 in the video.
OK. So for compile time definition, you can use constexpr with std:array and c-style arrays and with c-style strings (char*) and with std::string_view but not with std::string or std::vector.