可以在constexpr中使用std :: string吗?

向量:

使用C ++ 11,Ubuntu 14.04和GCC默认工具链

此代码失败:

constexpr std::string constString = "constString";

错误:constexpr变量'constString'的类型'const string {aka const std :: basic_string}'不是字面量...因为...'std :: basic_string'具有非平凡的析构函数

是否有可能使用std::stringconstexpr(显然不是...)如果是这样,怎么办?有没有其他方法可以在constexpr?中使用字符串

tenfour:

不,您的编译器已经为您提供了全面的说明。

但是您可以这样做:

constexpr char constString[] = "constString";

在运行时,可以使用它std::string在需要时构造一个

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

可以在第三方dll中使用std :: string吗?

解析文件时可以在getline中使用std :: string_view吗?

我可以在并行执行策略中使用std :: transform吗?

我可以在OpenACC中使用std :: bitset的功能吗?

错误:使用gcc 4.8.2在命令行中编译时,“ to_string”不是“ std”的成员,可以在NetBeans中使用吗?

我可以让std :: string使用更少的内存吗?

std :: string_view可以复制吗?

可以将char *移入std :: string吗?

constexpr可以与volatile结合使用吗?

有时可以在C ++中使用std :: atomic代替std :: mutex吗?

我可以在>>运算符中使用std:fixed或std :: setprecision()吗?

可以在constexpr上下文中使用使用导致未指定(未定义!)行为的指针进行表达吗?

在JavaScript中使用String.Format吗?

可以是constexpr吗?

是std :: string不如QString吗?

我可以在成员初始化器列表中使用std :: minmax_element吗?

可以在不提供move构造函数的类中使用std :: move吗?

我可以在std :: function模板签名类型参数中使用命名参数吗?

我可以在std :: find_if的并行版本中使用非平凡的可迭代迭代器吗?

我可以在 vc++ [VS 2019] 中使用 std::find() 和 lambda 函数吗?

std :: thread(c ++ 11)中使用的函数可以有[[noreturn]]吗?

在<>中使用对象名称,因为新的ArrayList <String>是正确的,或者只使用<>可以吗?

我可以使用 std::string 变量作为运算符的参数吗?

每当需要字符串文字时,可以使用std :: string :: c_str()吗?

我可以使用std :: string * argv作为主要函数参数吗?

可以在构造时修改命名的std :: string吗?

std :: string不可以移动或分配吗?

std::string::c_str() 可以返回 nullptr 吗?

您可以重用已移动的std :: string吗?