1
firemiles 2015-08-29 22:16:48 +08:00 1
expression 必须要能在编译时计算,函数在运行时计算,你在 expression 内嵌入了两个函数,所以这个 expression 也变成了 function ,而 noexcept 规定只能用于 expression 。
|
2
linux40 OP @firemiles 这个 noexcept 不会对表达式求值啊,为什么不会变成判断 T1 这个类型的接受一个 Other1 的构造函数抛不抛异常?
|
5
bazingaterry 2015-08-30 00:21:47 +08:00
打开 gist 竟然提示
![]( ) |
6
firemiles 2015-08-30 09:20:10 +08:00
@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 2015-08-30 14:19:14 +08:00
@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 。 |