为什么STL中没有常量表达式字符串构造函数?

Why there is no constant expression string constructor in the STL?

似乎在 C++ 中,在 静态内存 中完全拥有字符串文字的唯一方法是将它们声明为:

class A
{
    static const char const * = "Hello World";
};

我注意到 std::string 没有 常量表达式构造函数 。 我知道 std::string 实现是基于 动态分配 ,但为什么没有另一个字符串 class,符合 std::string,哪个可以胜任?

您可能正在寻找 std::experimental::string_view,它允许以统一、高效的方式访问标准字符串类型和 C 字符串。

它是 Library Fundamentals TS 的一部分,它已经发布并且可能会进入 C++17。