CreateGetTypeAliasOrDefault.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include "Utilities/TypeTraits/CreateHasTypeAlias.hpp"
7 
8 /*!
9  * \ingroup TypeTraitsGroup
10  * \brief Generate a metafunction that will retrieve the specified type alias,
11  * or if not present, assign a default type.
12  *
13  * \note This macro requires the type traits created by `CREATE_HAS_TYPE_ALIAS`
14  * and `CREATE_HAS_TYPE_ALIAS_V` but does not create them -- both of those
15  * macros should be called before this macro to generate the needed type traits.
16  */
17 #define CREATE_GET_TYPE_ALIAS_OR_DEFAULT(ALIAS_NAME) \
18  template <typename CheckingType, typename Default, \
19  bool present = has_##ALIAS_NAME##_v<CheckingType>> \
20  struct get_##ALIAS_NAME##_or_default { \
21  using type = Default; \
22  }; \
23  template <typename CheckingType, typename Default> \
24  struct get_##ALIAS_NAME##_or_default<CheckingType, Default, true> { \
25  using type = typename CheckingType::ALIAS_NAME; \
26  }; \
27  template <typename CheckingType, typename Default> \
28  using get_##ALIAS_NAME##_or_default_t = \
29  typename get_##ALIAS_NAME##_or_default<CheckingType, Default>::type;