【发布时间】:2016-06-26 05:21:56
【问题描述】:
#include<iostream>
#include<utility>
using namespace std;
struct A
{
void set(const int &){}
void set(int &&) noexcept
{}
};
template<class Assign,class T,class Func>
struct B
{
B& operator=(const Assign &)
{
return *this;
}
B& operator=(Assign &&) noexcept(noexcept(declval<T>().set(declval<Assign>())))
{
return *this;
}
};
int main()
{
cout<<is_nothrow_assignable<B<int,A,void(A::*)(int &&)>&,int&&>::value<<endl;
}
我要打线
B& operator=(Assign &&) noexcept(noexcept(declval<T>().set(declval<Assign>())))
到
B& operator=(Assign &&) noexcept(noexcept(declval<T>().Func(declval<Assign>())))
(但是会出现编译错误。)
这样用户就可以指定应该使用哪个成员函数。
在不知道应该提前调用哪个成员函数的情况下有任何可能这样做吗?
【问题讨论】:
标签: c++ expression noexcept