libzypp 17.37.10

type_traits.h
Go to the documentation of this file.
1#ifndef ZYPPNG_META_TYPE_TRAITS_INCLUDED
2#define ZYPPNG_META_TYPE_TRAITS_INCLUDED
3
4#include <type_traits>
5#include <memory>
6
7#if !defined ( __cpp_lib_void_t )
8
9 namespace std {
10 //define void_t since it is only available starting with C++17 in some compilers
11 template<typename... Ts> struct make_void { typedef void type;};
12 template<typename... Ts> using void_t = typename make_void<Ts...>::type;
13}
14
15#endif
16
17 namespace std {
18
19
20//implementation of the detector idiom, used to help with SFINAE
21//from https://en.cppreference.com/w/cpp/experimental/is_detected
22
23 namespace detail {
24 template <class Default, class AlwaysVoid,
25 template<class...> class Op, class... Args>
26 struct detector {
27 using value_t = std::false_type;
28 using type = Default;
29};
30
31 template <class Default, template<class...> class Op, class... Args>
32 struct detector<Default, std::void_t<Op<Args...>>, Op, Args...> {
33 using value_t = std::true_type;
34 using type = Op<Args...>;
35};
36
37 struct nonesuch{
38 ~nonesuch( ) = delete;
39 nonesuch( nonesuch const& ) = delete;
40 void operator = ( nonesuch const& ) = delete;
41};
42
43} // namespace detail
44
45 template <bool B> using bool_constant = integral_constant<bool, B>;
46
47 template <template<class...> class Op, class... Args>
48 using is_detected = typename detail::detector<detail::nonesuch, void, Op, Args...>::value_t;
49
50 template <template<class...> class Op, class... Args>
51 using detected_t = typename detail::detector<detail::nonesuch, void, Op, Args...>::type;
52
53 template <class Default, template<class...> class Op, class... Args>
54 using detected_or = detail::detector<Default, void, Op, Args...>;
55
56 template< template<class...> class Op, class... Args >
57 constexpr bool is_detected_v = is_detected<Op, Args...>::value;
58
59 template< class Default, template<class...> class Op, class... Args >
60 using detected_or_t = typename detected_or<Default, Op, Args...>::type;
61
62 template <class Expected, template<class...> class Op, class... Args>
63 using is_detected_exact = std::is_same<Expected, detected_t<Op, Args...>>;
64
65 template <class Expected, template<class...> class Op, class... Args>
66 constexpr bool is_detected_exact_v = is_detected_exact<Expected, Op, Args...>::value;
67
68 template <class To, template<class...> class Op, class... Args>
69 using is_detected_convertible = std::is_convertible<detected_t<Op, Args...>, To>;
70
71 template <class To, template<class...> class Op, class... Args>
72 constexpr bool is_detected_convertible_v = is_detected_convertible<To, Op, Args...>::value_t::value;
73
74
75#if __cplusplus < 202002L
76
77 template< class T >
78 struct remove_cvref {
79 using type = std::remove_cv_t<std::remove_reference_t<T>>;
80};
81
82 template< class T >
83 using remove_cvref_t = typename remove_cvref<T>::type;
84
85#endif
86
87#if __cplusplus < 201703L
88
89//https://en.cppreference.com/w/cpp/types/conjunction)
90 template<class...> struct conjunction : std::true_type { };
91 template<class B1> struct conjunction<B1> : B1 { };
92 template<class B1, class... Bn>
93 struct conjunction<B1, Bn...>
94 : std::conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};
95
96//https://en.cppreference.com/w/cpp/types/disjunction
97 template<class...> struct disjunction : std::false_type { };
98 template<class B1> struct disjunction<B1> : B1 { };
99 template<class B1, class... Bn>
100 struct disjunction<B1, Bn...>
101 : std::conditional_t<bool(B1::value), B1, disjunction<Bn...>> { };
102
103//https://en.cppreference.com/w/cpp/types/negation
104 template<class B>
105 struct negation : std::bool_constant< !bool(B::value)> { };
106
107#endif
108}
109
110
111 namespace zyppng {
112 //check wether something is a instance of a template type
113 template < template< class ... > class Templ, class Type >
114 struct is_instance_of : std::false_type{};
115
116 template < template< typename ... > class Templ, typename... Args >
117 struct is_instance_of<Templ, Templ<Args...>> : std::true_type{};
118
119 template < template< class ... > class Templ, class Type >
120 constexpr bool is_instance_of_v = is_instance_of<Templ,Type>::value;
121
122 //Provides the member typedef type which is the type pointed to by T, or, if T is not a pointer, then type is the same as T.
123 template< typename T>
124 struct remove_smart_ptr{ using type = std::remove_cv_t<T>; };
125
126 template< typename T>
127 struct remove_smart_ptr<std::shared_ptr<T>>{ using type = std::remove_cv_t<T>; };
128
129 template< typename T>
130 struct remove_smart_ptr<std::unique_ptr<T>>{ using type = std::remove_cv_t<T>; };
131
132 template< typename T>
133 using remove_smart_ptr_t = typename remove_smart_ptr<T>::type;
134
135 //helper template to print type parameters
136 template <typename ...T>
137 class myerror_t;
138}
139
140#endif
B1
bool
shared_ptr
zyppng::myerror_t
Definition type_traits.h:137
std::detail
Definition type_traits.h:23
std
Definition Arch.h:364
std::detected_or
detail::detector< Default, void, Op, Args... > detected_or
Definition type_traits.h:54
std::is_detected
typename detail::detector< detail::nonesuch, void, Op, Args... >::value_t is_detected
Definition type_traits.h:48
std::is_detected_exact
std::is_same< Expected, detected_t< Op, Args... > > is_detected_exact
Definition type_traits.h:63
std::detected_t
typename detail::detector< detail::nonesuch, void, Op, Args... >::type detected_t
Definition type_traits.h:51
std::is_detected_exact_v
constexpr bool is_detected_exact_v
Definition type_traits.h:66
std::is_detected_convertible
std::is_convertible< detected_t< Op, Args... >, To > is_detected_convertible
Definition type_traits.h:69
std::is_detected_convertible_v
constexpr bool is_detected_convertible_v
Definition type_traits.h:72
std::bool_constant
integral_constant< bool, B > bool_constant
Definition type_traits.h:45
std::void_t
typename make_void< Ts... >::type void_t
Definition type_traits.h:12
std::conditional_t
typename conditional< B, T, F >::type conditional_t
Definition TypeTraits.h:39
std::is_detected_v
constexpr bool is_detected_v
Definition type_traits.h:57
std::remove_cvref_t
typename remove_cvref< T >::type remove_cvref_t
Definition type_traits.h:83
std::detected_or_t
typename detected_or< Default, Op, Args... >::type detected_or_t
Definition type_traits.h:60
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::is_instance_of_v
constexpr bool is_instance_of_v
Definition type_traits.h:120
zyppng::remove_smart_ptr_t
typename remove_smart_ptr< T >::type remove_smart_ptr_t
Definition type_traits.h:133
std::conjunction
Definition type_traits.h:90
std::detail::detector< Default, std::void_t< Op< Args... > >, Op, Args... >::type
Op< Args... > type
Definition type_traits.h:34
std::detail::detector< Default, std::void_t< Op< Args... > >, Op, Args... >::value_t
std::true_type value_t
Definition type_traits.h:33
std::detail::detector
Definition type_traits.h:26
std::detail::detector::value_t
std::false_type value_t
Definition type_traits.h:27
std::detail::detector::type
Default type
Definition type_traits.h:28
std::detail::nonesuch
Definition type_traits.h:37
std::detail::nonesuch::nonesuch
nonesuch(nonesuch const &)=delete
std::detail::nonesuch::operator=
void operator=(nonesuch const &)=delete
std::detail::nonesuch::~nonesuch
~nonesuch()=delete
std::disjunction
Definition type_traits.h:97
std::make_void
Definition type_traits.h:11
std::make_void::type
void type
Definition type_traits.h:11
std::negation
Definition type_traits.h:105
std::remove_cvref
Definition type_traits.h:78
std::remove_cvref::type
std::remove_cv_t< std::remove_reference_t< T > > type
Definition type_traits.h:79
zyppng::is_instance_of
Definition type_traits.h:114
zyppng::remove_smart_ptr< std::shared_ptr< T > >::type
std::remove_cv_t< T > type
Definition type_traits.h:127
zyppng::remove_smart_ptr< std::unique_ptr< T > >::type
std::remove_cv_t< T > type
Definition type_traits.h:130
zyppng::remove_smart_ptr
Definition type_traits.h:124
zyppng::remove_smart_ptr::type
std::remove_cv_t< T > type
Definition type_traits.h:124