function template has already been defined

Hi,

I have
1
2
template<typename T> have_sort test_sort(decltype(&T::sort), decltype(&T::sort));
template<typename T> have_range test_sort(decltype(&T::begin), decltype(&T::end));


where:
1
2
3
4
5
6
7
8
9
10
struct have_sort
	{
		char c;
	};

struct have_range
{
	char d;
	have_sort  e;
};


with which i do:

1
2
3
4
5
6
7
8
9
10
11
12
13
template<typename T>
typename std::enable_if<sizeof(test_sort<T> 
                (NULL,NULL))==sizeof(have_sort)>::type fast_sort(T& x)
{
	x.sort();
}

template<typename T>
typename std::enable_if<sizeof(test_sort<T> 
               (NULL,NULL))==sizeof(have_range)>::type fast_sort(T& x)
{
	std::sort(x.begin(), x.end());
}


which should compile but I get the error:


std::enable_if<0,void>::type useEnableIf::fast_sort(T &)': function template has already been defined



why?

If you pass NULL as argument to test_sort how is it supposed to know which overload to pick?
enable_if should only permit instantiation of the correct function!!
should not clash!
Can you provide a compilable example?

What is the idea behind

1
2
std::enable_if<sizeof(test_sort<T> 
               (NULL,NULL))==sizeof(....)>::type

?

You may use std::is_same<..., ...>::value. See

http://www.cplusplus.com/reference/type_traits/is_same/

But is there any need for this? What is the type of T?
JUANDENT, you might be right. My understanding of SFINAE is weak. But wouldn't it be a problem with std::list that has both begin and sort? Note that std::list::sort uses templates which seems to affect things, but I don't understand. Anyhow, my understanding is that you're not allowed to form pointers to standard library functions.

Last edited on
yes Peter87 but that is another issue. For now lets not think about that...
Topic archived. No new replies allowed.