GetFundamentalType.hpp
1 // 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 
11 namespace tt {
12 // @{
13 /// \ingroup TypeTraitsGroup
14 /// \brief Extracts the fundamental type for a container
15 ///
16 /// \details Designates a type alias `get_fundamental_type::type`
17 /// as `T` when `T` itself is an appropriate fundamental type, and the
18 /// contained type of a container which specifies a `value_type`.
19 ///
20 /// `get_fundamental_type_t<T>` is provided as a type alias to
21 /// `type` from `get_fundamental_type<T>`
22 ///
23 /// \snippet Test_GetFundamentalType.cpp get_fundamental_type
24 template <typename T, typename Enable = std::void_t<>>
26  using type = tmpl::conditional_t<std::is_fundamental_v<T>, T, NoSuchType>;
27 };
28 
29 /// \cond
30 template <typename T>
31 struct get_fundamental_type<T, std::void_t<typename T::value_type>> {
32  using type = typename get_fundamental_type<typename T::value_type>::type;
33 };
34 /// \endcond
35 
36 template <typename T>
37 using get_fundamental_type_t = typename get_fundamental_type<T>::type;
38 // @}
39 } // namespace tt
NoSuchType
Used to mark "no type" or "bad state" for metaprogramming.
Definition: NoSuchType.hpp:10
tt::get_fundamental_type
Extracts the fundamental type for a container.
Definition: GetFundamentalType.hpp:25
tt
Definition: TensorExpression.hpp:113
type_traits
TMPL.hpp