#include <iostream>
#include <type_traits>
#include <map>
template<int C>
struct Test
{
auto blah() const
-> typename std::enable_if
<
C == 1,
bool
>::type
{
returnfalse;
}
};
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 ;)
#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{ returnfalse ; }
};
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’
}