2
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 * 永远不会被触发——即使有人也尝试过。
那么这个Q的答案是什么?

4

2 回答 2

1
struct dummy {
    operator int() const
    { return 0; }
};

// Where rhs has appropriate type
dummy() + rhs;
于 2011-10-17T10:45:27.157 回答
0
std::string x;
Int<int, 3, 5> i;

auto z = x + i;

触发了它。

于 2011-10-17T10:34:18.943 回答