dimanche 24 novembre 2019

std::enable_if based on expression [duplicate]

This question already has an answer here:

Is the following code legal C++11?

template<typename T>
typename std::enable_if<T::Data() == nullptr>::type test (T t)
{
  static_assert (t.Data() == nullptr, "pData is not null");
}

template<typename T>
typename std::enable_if<T::Data() != nullptr>::type test (T t)
{
  static_assert (t.Data() != nullptr, "pData is not null");
}

clang compiles it without error, but MSVC generates the following error message:

error C2995: 'std::enable_if<,void>::type test(T)': function template has already been defined
note: see declaration of 'test'

How should I rewrite the above code to let it compile on the common C++ compilers (GCC, Clang, MSVC)?

Aucun commentaire:

Enregistrer un commentaire