I have a problem encountered at a condtion like below:
#include <iostream>
#include <type_traits>
#define TRACE void operator()() const { std::cerr << "@" << __LINE__ << std::endl; }
template <class T>
struct check : std::true_type {};
template <class F, class T, class Check=void>
struct convert {
TRACE;// first case
};
template <class F, class T>
struct convert<F*, T, typename std::enable_if<(check<F>::value && check<T>::value), void>::type> {
TRACE; // second case
};
template <class T>
struct convert<int*, T, typename std::enable_if<(check<T>::value), void>::type> {
TRACE; // third case
};
Then
convert<int*, int> c;
c();
will report ambiguous class template instantiation in g++-4.5, g++-4.6, g++-4.7 and clang++-3.1(all with option -std=c++0x)
But if i replace the check in third case to
typename std::enable_if<(check<int>::value && check<T>::value), void>:type
Then clang++-3.1 works fine.
Is it compilers bug or by standard?