【发布时间】:2017-08-25 18:19:36
【问题描述】:
尝试学习如何使用 Eric Niebler 的 range-v3 库,并阅读源代码,我看到了宏定义:
#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 \
/**/
所以,简而言之,模板定义如下:
template<typename I, typename O,
CONCEPT_REQUIRES_(InputIterator<I>() &&
WeaklyIncrementable<O>())>
void fun_signature() {}
翻译为:
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() {}
我想知道为什么那个宏是这样实现的。为什么需要这个整数,为什么它需要 false || cond 而不仅仅是 cond 模板参数?
【问题讨论】:
标签: c++ template-meta-programming range-v3