This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51710] decltype and SFINAE
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 30 Dec 2011 12:53:27 +0000
- Subject: [Bug c++/51710] decltype and SFINAE
- Auto-submitted: auto-generated
- References: <bug-51710-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51710
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-12-30 12:53:27 UTC ---
I think the code is invalid because the expression decltype(foo(e1,e2)) does
not occur in the "immediate context" of the function type
It works if you replace enable_if<cond, decltype(expr)> with
enable_if_foo<cond, type> where enable_if_foo evaluates decltype(expr)
template<bool, typename E1, typename E2>
struct enable_if_foo
{
typedef decltype(foo(std::declval<E1>(), std::declval<E2>())) type;
};
template<typename E1, typename E2>
struct enable_if_foo<false, E1, E2>
{ };
/// operator+ is overloaded for E1,E2 satisfying some_condition only
template <typename E1, typename E2>
inline auto operator+(E1&& e1, E2&& e2)
-> typename enable_if_foo<
some_condition<E1,E2>::value, // We check condition
E1, E2
>::type
{
return foo(e1, e2);
}