
1 firemiles Aug 29, 2015 expression 必须要能在编译时计算,函数在运行时计算,你在 expression 内嵌入了两个函数,所以这个 expression 也变成了 function ,而 noexcept 规定只能用于 expression 。 |
5 bazingaterry Aug 30, 2015 打开 gist 竟然提示  |
6 firemiles Aug 30, 2015 @linux40 template <typename T1, typename T2> struct pair { //... template <typename Other1, typename Other2> constexpr pair (Other1 &&o1, Other2 &&o2 ) noexcept ( noexcept (first (forward<Other1>(o1 ))) && noexcept (second (forward<Other2>(o2 ))) ): first (forward<Other1>(o1 )), second (forward<Other2>(o2 )) {} //... }; forward<Ohter1>(o1 ) 应该不是一个 constexpr 吧,这样不是进行了一次函数调用吗 |
10 firemiles Aug 30, 2015 @linux40 template <typename T1, typename T2> struct pair { //... template <typename Other1, typename Other2> constexpr pair (Other1 &&o1, Other2 &&o2 ) noexcept ( noexcept (T1 (std::forward<Other1>(o1 ))) && noexcept (T2 (std::forward<Other2>(o2 ))) ): first (std::forward<Other1>(o1 )), second (std::forward<Other2>(o2 )) {} //... T1 first; T2 second; }; int main () { pair<int, double> a (1, 1.2 ); } 我试着这么写可以通过编译,不知道满不满足你的要求,那两个 first 和 second 在 noexcept 里的我改成了 T1 和 T2 。 |