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 : #include "Utilities/NoSuchType.hpp" 9 : #include "Utilities/TMPL.hpp" 10 : #include "Utilities/TypeTraits/CreateHasTypeAlias.hpp" 11 : 12 : namespace tt { 13 : namespace detail { 14 : // NOLINTBEGIN(clang-diagnostic-unused-const-variable) 15 : CREATE_HAS_TYPE_ALIAS(ElementType) 16 : CREATE_HAS_TYPE_ALIAS_V(ElementType) 17 : CREATE_HAS_TYPE_ALIAS(value_type) 18 : CREATE_HAS_TYPE_ALIAS_V(value_type) 19 : // NOLINTEND(clang-diagnostic-unused-const-variable) 20 : } // namespace detail 21 : /// @{ 22 : /// \ingroup TypeTraitsGroup 23 : /// \brief Extracts the fundamental type for a container 24 : /// 25 : /// \details Designates a type alias `get_fundamental_type::type` 26 : /// as `T` when `T` itself is an appropriate fundamental type, and the 27 : /// contained type of a container which specifies a `value_type`. 28 : /// 29 : /// `get_fundamental_type_t<T>` is provided as a type alias to 30 : /// `type` from `get_fundamental_type<T>` 31 : /// 32 : /// \snippet Test_GetFundamentalType.cpp get_fundamental_type 33 : template <typename T, typename = std::nullptr_t> 34 1 : struct get_fundamental_type { 35 0 : using type = tmpl::conditional_t<std::is_fundamental_v<T>, T, NoSuchType>; 36 : }; 37 : 38 : /// \cond 39 : // Specialization for Blaze expressions 40 : template <typename T> 41 : struct get_fundamental_type<T, Requires<detail::has_ElementType_v<T>>> { 42 : using type = typename get_fundamental_type<typename T::ElementType>::type; 43 : }; 44 : // Specialization for containers 45 : template <typename T> 46 : struct get_fundamental_type<T, Requires<detail::has_value_type_v<T> and 47 : not detail::has_ElementType_v<T>>> { 48 : using type = typename get_fundamental_type<typename T::value_type>::type; 49 : }; 50 : /// \endcond 51 : 52 : template <typename T> 53 0 : using get_fundamental_type_t = typename get_fundamental_type<T>::type; 54 : /// @} 55 : } // namespace tt