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; } 

The point is that I don't think that those two static_assert*s* will ever be triggered - even if one tries too.
So what's the answer to this Q?

6
  • I don't see why not, you could come up with a class which satisfies the constraints (Best_Fit and Int - whatever they are), but fails is_integral... Commented Oct 17, 2011 at 10:24
  • 3
    I think it is impossible to answer without definitions for Int<>, Best_Fit<> because anyone of those could trigger SFINAE Commented Oct 17, 2011 at 10:26
  • @sehe && Kerrek sorry for not providing those defs. Please find them here: stackoverflow.com/questions/7790524/… Commented Oct 17, 2011 at 10:30
  • @KerrekSB Could be promoted to a larger type, e.g. if Integral has a higher rank than Int_T. Commented Oct 17, 2011 at 10:44
  • @LucDanton: Oh, yes, I misread that. Never mind! Commented Oct 17, 2011 at 10:50

2 Answers 2

1
struct dummy { operator int() const { return 0; } }; // Where rhs has appropriate type dummy() + rhs; 
Sign up to request clarification or add additional context in comments.

Comments

0
std::string x; Int<int, 3, 5> i; auto z = x + i; 

Triggered it.

4 Comments

That's odd. I would have expected the decltype(left + right.get_data()) to SFINAE out operator+. And in fact I can't reproduce your finding on my copy of GCC.
Well, try any type that is convertible or addable to int and even SFINAE won't help you. Eg. double.
std::string is not such a type.
No it's not, and it looks like GCC will SFINAE std::string out while MSVC doesn't do SFINAE for this case. Even on GCC, however, a type like double will allow addition to an int while not passing is_integral.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.