【发布时间】:2015-03-16 19:24:04
【问题描述】:
为什么std::runtime_error 不提供接受std::string&& 的构造函数?查看the constructors for std::string,它有一个移动构造函数,但noexcept 规范仅适用于C++14,不适用于C++11。这是一个错误,错过了最后期限还是我错过了什么?
【问题讨论】:
-
如果
std::runtime_error有一个构造函数采用std::string&&,它肯定不会是一个移动构造函数。移动构造函数将采用std::runtime_error&&。 -
我不确定我是否遵循:从一开始就判断您的问题似乎是关于
runtime_error,但随后您切换到std::string。你想表达什么观点? -
@AndyProwl:
std::runtime_error目前可能由const std::string&或const char* what_arg构建。他在问为什么它不能从std::string&&构建。 -
@LightnessRacesinOrbit:是的,但他似乎通过提到
string的移动构造函数的noexcept资格来说明异常安全性,我并不完全遵循。 -
是的,如果问题引起了混乱,我很抱歉。问题是为什么
std::runtime_error(std::string&&)不存在。
标签: string exception c++11 move c++14