私はこれをあまりにも長い間見つめていたと思いますが、ここでエラーを見つけることができません:
struct
{
bool empty() const
{
return true;
}
} hasEmpty;
template<typename T>
struct has_empty
{
private:
template<typename U, U>
class check {};
template<typename C>
static char f(check<void (C::*)() const, &C::empty> *);
template<typename C>
static long f(...);
public:
static const bool value = (sizeof(f<T>(nullptr)) == sizeof(char));
};
template<typename T>
typename std::enable_if<has_empty<T>::value>::type foo(const T& t)
{
}
void x()
{
foo(hasEmpty);
}
Visual Studio 2012 レポート:
error C2893: Failed to specialize function template 'std::enable_if<has_empty<T>::value>::type foo(const T &)'
1> With the following template arguments:
1> '<unnamed-type-hasEmpty>'
(注:ここで説明されているように、このテストの新しい C++11 バージョンが非常に気に入っていますが、VS2012 はまだ constexpr をサポートしていません。)