Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include <type_traits> 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 : * \warning Please use defaults responsibly. In many cases it is 14 : * better to require the type alias is present so the 15 : * functionality isn't hidden. Also make sure to document the 16 : * compile-time interface, e.g. with a \ref protocols "protocol". 17 : */ 18 1 : #define CREATE_GET_TYPE_ALIAS_OR_DEFAULT(ALIAS_NAME) \ 19 : template <typename CheckingType, typename Default, typename = std::void_t<>> \ 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< \ 25 : CheckingType, Default, std::void_t<typename CheckingType::ALIAS_NAME>> { \ 26 : using type = typename CheckingType::ALIAS_NAME; \ 27 : }; \ 28 : template <typename CheckingType, typename Default> \ 29 : using get_##ALIAS_NAME##_or_default_t = \ 30 : typename get_##ALIAS_NAME##_or_default<CheckingType, Default>::type;