1
#include <type_traits>

using namespace std;

template<class T, class = typename enable_if<is_same<T, char>::value>::type> // OK
struct A {};

#define ENABLE_IF(expr) class = typename enable_if<expr>::type

template<class T, ENABLE_IF((is_same<T, char>::value))> // OK
struct B {};

template<class T, ENABLE_IF(is_same<T, char>::value)> // warning C4002 and error C1004
struct C {};

int main()
{}

My compiler is VC++ 2013 RC.

The macro ENABLE_IF(x) doesn't work as expected:

warning C4002: too many actual parameters for macro 'ENABLE_IF' fatal

error C1004: unexpected end-of-file found

Yet ENABLE_IF((x)) works fine.

Why?

xmllmx
  • 39,765
  • 26
  • 162
  • 323

1 Answers1

3

is_same<T, char>::value

there is a comma in middle, thus the preprocessor consider it as two arguments to the macro,

is_same<T, and char>::value

Zac Wrangler
  • 1,445
  • 9
  • 8