uTL
micro Template library
detection.h
Go to the documentation of this file.
1 
22 #ifndef __utl_meta_detection_h__
23 #define __utl_meta_detection_h__
24 
25 #include <utl/core/impl.h>
26 #include <utl/meta/operations.h>
27 #include <type_traits>
28 
34 
36 namespace utl {
37 namespace meta {
38 
42  #if defined(UTL_WORKAROUND_CWG_1558)
44  template<typename... _Ts>
45  struct void_ {
46  using type = void;
47  };
49  template<typename... _Ts>
50  using void_t = eval<void_<_Ts...>>;
51  #else
52  template <typename...> using void_ = void;
55  template <typename...> using void_t = void;
56  #endif
57 
63  struct nat_ {
64  nat_() = delete;
65  ~nat_() = delete;
66  nat_(nat_ const&) = delete;
67  void operator = (nat_ const&) = delete;
68  };
69 
72  namespace detail {
73  template <typename Default,
74  typename AlwaysVoid,
75  template<typename...> class Op, typename... Args>
76  struct detector {
77  using detected = false_;
78  using type = Default;
79  };
80 
81  template <typename Default,
82  template<typename...> class Op, typename... Args>
83  struct detector <Default, void_t<Op<Args...>>, Op, Args...> {
84  using detected = true_;
85  using type = Op<Args...>;
86  };
87 
89  template <typename Default,
90  template<typename...> class Op, typename... Args>
91  using detected_or = detector<Default, void, Op, Args...>;
92  } // namespace detail
94 
98 
117  template <template<typename...> class Op, typename... Args>
118  using is_detected = typename detail::detector<nat_, void, Op, Args...>::detected;
119 
121  template< template<typename...> class Op, typename... Args>
122  constexpr bool is_detected_v = is_detected<Op, Args...>::value;
123 
143  template <template<typename...> class Op, typename... Args>
144  using detected_t = eval <
145  detail::detector<nat_, void, Op, Args...>
146  >;
147 
168  template <typename Default,
169  template<typename...> class Op, typename... Args>
170  using detected_or_t = eval <
171  detail::detected_or<Default, Op, Args...>
172  >;
173 
195  template <typename Expected,
196  template<typename...> class Op, typename... Args >
197  using is_detected_exact = eval <
198  same_<Expected, detected_t<Op, Args...>>
199  >;
200 
202  template <typename Expected,
203  template<typename...> class Op, typename... Args >
204  constexpr bool is_detected_exact_v = is_detected_exact< Expected, Op, Args...>::value;
205 
227  template <typename To,
228  template<typename...> class Op, typename... Args >
229  using is_detected_convertible = eval <
230  std::is_convertible< detected_t<Op, Args...>, To >
231  >;
232 
235  template <typename To,
236  template<typename...> class Op, typename... Args >
237  constexpr bool is_detected_convertible_v =
238  is_detected_convertible<To, Op, Args...>::value;
240 
241 }}
243 
244 #endif /* __utl_meta_detection_h__ */
void void_t
void_t type alias
Definition: detection.h:55
constexpr bool is_detected_exact_v
evaluates to true if evaluation of Op<Args...> is Expected and to false if not
Definition: detection.h:204
bool_< true > true_
The type used as a compile-time boolean with true value.
Definition: integral.h:68
eval< std::is_convertible< detected_t< Op, Args... >, To > > is_detected_convertible
Definition: detection.h:231
Integral constant operations and logical operations.
void void_
void_ type alias
Definition: detection.h:53
bool_< false > false_
The type used as a compile-time boolean with false value.
Definition: integral.h:69
typename Tp::type eval
Type alias for Tp::type. Used to evaluate/extract return type of metafunctions.
Definition: integral.h:49
constexpr bool is_detected_convertible_v
Definition: detection.h:237
STL&#39;s core language concepts.
Definition: _1wire.h:30
eval< detail::detector< nat_, void, Op, Args... > > detected_t
Definition: detection.h:146
eval< same_< Expected, detected_t< Op, Args... > > > is_detected_exact
Definition: detection.h:199
typename detail::detector< nat_, void, Op, Args... >::detected is_detected
Definition: detection.h:118
constexpr bool is_detected_v
Detection predicate.
Definition: detection.h:122
Implementation detail main forward header.
eval< detail::detected_or< Default, Op, Args... > > detected_or_t
Definition: detection.h:172