https://mooseframework.inl.gov
HasMembers.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "libmesh/libmesh_common.h"
13 
14 #define BuiltInSpecializations(Type, BuiltinType) \
15  template <> \
16  class HasMemberType_##Type<BuiltinType> \
17  { \
18  public: \
19  static constexpr bool value = false; \
20  }
21 
22 // Idiom taken from https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Member_Detector
23 #define GENERATE_HAS_MEMBER_TYPE0(Type) \
24  template <class T> \
25  class HasMemberType_##Type \
26  { \
27  private: \
28  using Yes = char[2]; \
29  using No = char[1]; \
30  \
31  struct Fallback \
32  { \
33  struct Type \
34  { \
35  }; \
36  }; \
37  struct Derived : T, Fallback \
38  { \
39  }; \
40  \
41  template <class U> \
42  static No & test(typename U::Type *); \
43  template <typename U> \
44  static Yes & test(U *); \
45  \
46  public: \
47  static constexpr bool value = sizeof(test<Derived>(nullptr)) == sizeof(Yes); \
48  }; \
49  BuiltInSpecializations(Type, char); \
50  BuiltInSpecializations(Type, short); \
51  BuiltInSpecializations(Type, int); \
52  BuiltInSpecializations(Type, long); \
53  BuiltInSpecializations(Type, unsigned char); \
54  BuiltInSpecializations(Type, unsigned short); \
55  BuiltInSpecializations(Type, unsigned int); \
56  BuiltInSpecializations(Type, unsigned long); \
57  BuiltInSpecializations(Type, float); \
58  BuiltInSpecializations(Type, double); \
59  BuiltInSpecializations(Type, long double)
60 
61 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
62 #define GENERATE_HAS_MEMBER_TYPE(Type) \
63  GENERATE_HAS_MEMBER_TYPE0(Type); \
64  BuiltInSpecializations(Type, Real)
65 #else
66 #define GENERATE_HAS_MEMBER_TYPE(Type) GENERATE_HAS_MEMBER_TYPE0(Type)
67 #endif
68 
69 GENERATE_HAS_MEMBER_TYPE(OutputShape);
70 GENERATE_HAS_MEMBER_TYPE(value_type);
GENERATE_HAS_MEMBER_TYPE(OutputShape)