tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
common_type.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_TYPE_TRAITS_COMMON_TYPE_HPP
4#define TETL_TYPE_TRAITS_COMMON_TYPE_HPP
5
9
10namespace etl {
11
17template <typename... T>
19
20template <typename T>
21struct common_type<T> : common_type<T, T> { };
22
23namespace detail {
24template <typename T1, typename T2>
25using cond_t = decltype(false ? declval<T1>() : declval<T2>());
26
27template <typename T1, typename T2, typename = void>
28struct common_type_2_impl { };
29
30template <typename T1, typename T2>
31struct common_type_2_impl<T1, T2, void_t<cond_t<T1, T2>>> {
32 using type = decay_t<cond_t<T1, T2>>;
33};
34
35template <typename AlwaysVoid, typename T1, typename T2, typename... R>
36struct common_type_multi_impl { };
37
38template <typename T1, typename T2, typename... R>
39struct common_type_multi_impl<void_t<typename common_type<T1, T2>::type>, T1, T2, R...>
40 : common_type<typename common_type<T1, T2>::type, R...> { };
41} // namespace detail
42
43template <typename T1, typename T2>
44struct common_type<T1, T2> : detail::common_type_2_impl<decay_t<T1>, decay_t<T2>> { };
45
46template <typename T1, typename T2, typename... R>
47struct common_type<T1, T2, R...> : detail::common_type_multi_impl<void, T1, T2, R...> { };
48
49template <typename... T>
50using common_type_t = typename common_type<T...>::type;
51
52} // namespace etl
53
54#endif // TETL_TYPE_TRAITS_COMMON_TYPE_HPP
void void_t
Definition void_t.hpp:10
Definition adjacent_find.hpp:8
auto declval() noexcept -> add_rvalue_reference_t< T >
typename etl::decay< T >::type decay_t
Definition decay.hpp:32
typename common_type< T... >::type common_type_t
Definition common_type.hpp:50
Determines the common type among all types T..., that is the type all T... can be implicitly converte...
Definition common_type.hpp:18