【发布时间】:2013-09-14 16:24:42
【问题描述】:
这是我之前的问题"Which parts of the C++14 Standard Library could be and which parts will be made constexpr?" 和"Guidelines to do constexpr operator-overloading?" 的后续问题
在运行时世界中,多个数据成员的nice idiom to overload operator< for a struct 是使用std::tie 将结构转换为std::tuple 并搭载在其operator< 上执行正确的事情™(字典比较各种成员)。
在 C++14 中,std::tuple 的许多部分都变成了constexpr,尤其是make_tuple、std::get 和前面提到的operator<。但是,看似相关的std::tie 似乎没有标记为constexpr。这很烦人,因为它使得定义可以在编译时进行比较的用户定义的文字类型比必要的更加冗长。
问题:对于 C++14,std::tie 没有标记为 constexpr 是否有任何技术原因?
更新:LWG issue 2301、implemented in libc++ 和 libstdc++ bug 65978
UPDATE2:在提交 libstdc++ 错误报告 3 个多小时后由 @JonathanWakely 修复!
【问题讨论】:
-
因为它只创建一个引用元组,所以真的没有理由不标记它
constexpr。 -
@Xeo 我希望一切都是 constexpr 默认情况下,编译器只会在无法评估时发出警告
标签: c++ c++11 tuples constexpr c++14