Trying to learn how to use Eric Niebler's ranges-v3 library, and reading the source code, I saw that macro definition:
#define CONCEPT_PP_CAT_(X, Y) X ## Y
#define CONCEPT_PP_CAT(X, Y) CONCEPT_PP_CAT_(X, Y)
/// \addtogroup group-concepts
/// @{
#define CONCEPT_REQUIRES_(...) \
int CONCEPT_PP_CAT(_concept_requires_, __LINE__) = 42, \
typename std::enable_if< \
(CONCEPT_PP_CAT(_concept_requires_, __LINE__) == 43) || (__VA_ARGS__), \
int \
>::type = 0 \
/**/
So, in short, a template definition like:
template<typename I, typename O,
CONCEPT_REQUIRES_(InputIterator<I>() &&
WeaklyIncrementable<O>())>
void fun_signature() {}
is translated as:
template<typename I, typename O,
int a_unique_name = 42,
typename std::enable_if
<false || (InputIterator<I>() &&
WeaklyIncrementable<O>()), int>::type = 0
>
void fun_signature() {}
I would like to know why is that macro implement that way. Why is that integer needed, and why does it need a false || cond
and not just a cond
template argument?
int
, I understand that if a user instantiatesS
, the compiler will issue an error, even if the functionf
isn't called and thus not instantiated? – Rah