template<class Int_T,class Integral,typename Best_Fit<Int_T>::type Min_Range,
typename Best_Fit<Int_T>::type Max_Range>
auto operator+(Integral left,const Int<Int_T,Min_Range,Max_Range>& right)
->Int<decltype(left + right.get_data())>
{
static_assert(std::is_integral<Integral>::value,"Non integral type is not allowed.");
static_assert(std::is_integral<Int_T>::value,"Non integral type is not allowed.");
auto data = left + right.get_data();
Int<decltype(left + right.get_data())> result(data);
return result;
}
关键是我认为这两个 static_assert*s* 永远不会被触发 - 即使有人也尝试过。
那么这个问题的答案是什么?
最佳答案
struct dummy {
operator int() const
{ return 0; }
};
// Where rhs has appropriate type
dummy() + rhs;
关于c++ - 这个 static_assert 会被触发吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7792339/