解释模板代码测试如果类具有成员变量

时间:2019-04-02 01:36:48

标签: c++ templates

我需要一些帮助来了解raja中的某些C ++模板。这段代码测试变量是否是结构的成员,或者生成某种东西来测试是否是这种情况。我最难理解的是它定义的第一个检查功能。

我对此也有很多疑问,就像我不知道从哪里开始使用谷歌搜索来解决这个问题。

#define MEMBER_HAS(NAME)                                                     \
  template <class T>                                                         \
  class NAME                                                                 \
  {                                                                          \
    template <                                                               \
        typename U,                                                          \
        typename = typename std::enable_if<!std::is_member_pointer<decltype( \
            &U::NAME)>::value>::type>                                        \
    static std::true_type check(int);                                        \
    template <typename>                                                      \
    static std::false_type check(...);                                       \
                                                                             \
  public:                                                                    \
    static constexpr bool value = decltype(check<T>(0))::value;              \
  }

此代码来自RAJA,来自https://github.com/LLNL/RAJA/blob/fa891b149d374b37ec2ac27d00bc26f6a19f5e34/include/RAJA/policy/openacc/type_traits.hpp

0 个答案:

没有答案