I need to define several constant strings that will be used across an entire C++20 project.
I am considering the following options :
constexpr char[] str1 = "foo";
constexpr std::string str2 = "foo";
constexpr std::string_view str3 = "foo";
but I hesitate about which one I must choose.
constexpr char[] is efficient but is not modern C++.
constexpr std::string is modern C++ and takes advantage of the fact "since C++20 std::string is a constexpr class to perform operations at compile time" but even so, I heard it uses dynamic allocation anyway so it may not be the best option.
constexpr std::string_view is probably the optimal choice but I have checked several resources including Professional C++ (5th Edition) by Marc Gregoire and I didn't find clear guidelines it was the recommended way to define global constant strings. I just read it was the best choice to pass a read-only string to a function (compared to passing const std::string& or const char*).
So which technique is the right one for C++20 ?