Why doesn't SFINAE apply here?

http://ideone.com/MJnTv2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <type_traits>
#include <map>

template<int C>
struct Test
{
	auto blah() const
	-> typename std::enable_if
	<
		C == 1,
		bool
	>::type
	{
		return false;
	}
};

int main()
{
	std::map<int, Test<0>> meh; //error
}
I'm very confused as to why SFINAE does not apply here, let alone why it even affects my ability to use it as the mapped type in a map.

Note: Specialization is completely out of the question in my case - there is a lot more complexity than just one template parameter and one conditional function ;)

EDIT: Clang's error message isn't much more helpful:
http://coliru.stacked-crooked.com/a/35fb1ad1dd2b0e36
Last edited on
Need to make blah a dependant name resolved during the second phase of a two phase lookup.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <type_traits>
#include <map>

template< int C > struct Test 
{
    // blah<ENABLER> is a dependant name; subject to the two phase lookup rule
    // resolution of dependant name 'blah<ENABLER>' is postponed to phase two
    template < bool ENABLER = (C==1) > // makes ENABLER a dependant name
    typename std::enable_if< ENABLER, bool >::type blah() const{ return false ; } 
};

int main()
{
    std::map< int, Test<1> > meh1 { { 1, {} } }; // fine
    
    meh1[1].blah() ; // fine; Test<1>::blah() ;
    
    std::map< int, Test<0> > meh0 { { 0, {} } }; // fine
    
    // meh0[0].blah() ; // *** error: ‘Test<0>’ has no member named ‘blah’
}

http://coliru.stacked-crooked.com/a/497eed7cdcf502d5
Topic archived. No new replies allowed.