Dune Core Modules (2.9.0)

type_traits.hh
1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 // vi: set et ts=4 sw=2 sts=2:
3 // SPDX-FileCopyrightInfo: Copyright (C) DUNE Project contributors, see file LICENSE.md in module root
4 // SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
5 #ifndef DUNE_COMMON_STD_TYPE_TRAITS_HH
6 #define DUNE_COMMON_STD_TYPE_TRAITS_HH
7 
8 #include <type_traits>
11 
12 #if __has_include(<experimental/type_traits>)
13 #include <experimental/type_traits>
14 #endif
15 
16 namespace Dune
17 {
18 
20 
29 namespace Std
30 {
31 
34  using std::bool_constant;
35 
36 #if DUNE_HAVE_CXX_EXPERIMENTAL_IS_DETECTED
37 
38  using std::experimental::nonesuch;
48 
49 #else // DUNE_HAVE_CXX_EXPERIMENTAL_IS_DETECTED
50 
51  // fallback version of std::experimental::is_detected et al., heavily scribbled
52  // from cppreference.com (but there is actually not much implementation to the thing)
53 
54 #ifndef DOXYGEN
55 
56  namespace Impl {
57 
58  // default version of detector, this gets matched on failure
59  template<typename Default, typename Void, template<typename...> class Op, typename... Args>
60  struct detector
61  {
62  using value_t = std::false_type;
63  using type = Default;
64  };
65 
66  // specialization of detector that matches if Op<Args...> can be instantiated
67  template<typename Default, template<typename...> class Op, typename... Args>
68  struct detector<Default, std::void_t<Op<Args...>>, Op, Args...>
69  {
70  using value_t = std::true_type;
71  using type = Op<Args...>;
72  };
73 
74  }
75 
76 #endif // DOXYGEN
77 
79 
87  struct nonesuch
88  {
89  nonesuch() = delete;
90  ~nonesuch() = delete;
91  nonesuch(const nonesuch&) = delete;
92  void operator=(const nonesuch&) = delete;
93  };
94 
96 
127  template<typename Default, template<typename...> class Op, typename... Args>
128  using detected_or = Impl::detector<Default,void,Op,Args...>;
129 
131 
140  template<template<typename...> class Op, typename... Args>
141  using is_detected = typename detected_or<nonesuch,Op,Args...>::value_t;
142 
143 #ifdef __cpp_variable_templates
145 
154  template<template<typename...> class Op, typename... Args>
155  constexpr bool is_detected_v = is_detected<Op,Args...>::value;
156 #endif // __cpp_variable_templates
157 
159 
169  template<template<typename...> class Op, typename... Args>
170  using detected_t = typename detected_or<nonesuch,Op,Args...>::type;
171 
172 
174 
184  template<typename Default, template<typename...> class Op, typename... Args>
185  using detected_or_t = typename detected_or<Default,Op,Args...>::type;
186 
188 
194  template<typename Expected, template<typename...> class Op, typename... Args>
195  using is_detected_exact = std::is_same<Expected,detected_t<Op,Args...>>;
196 
197 #ifdef __cpp_variable_templates
199 
205  template<typename Expected, template<typename...> class Op, typename... Args>
206  constexpr bool is_detected_exact_v = is_detected_exact<Expected,Op,Args...>::value;
207 #endif // __cpp_variable_templates
208 
210 
216  template<typename Target, template<typename...> class Op, typename... Args>
217  using is_detected_convertible = std::is_convertible<Target,detected_t<Op,Args...>>;
218 
219 #ifdef __cpp_variable_templates
221 
227  template<typename Target, template<typename...> class Op, typename... Args>
228  constexpr bool is_detected_convertible_v = is_detected_convertible<Target,Op,Args...>::value;
229 #endif // __cpp_variable_templates
230 
231 #endif // DUNE_HAVE_CXX_EXPERIMENTAL_IS_DETECTED
232 
233 
234 
235  // conjunction
236  // -----------
237 
245  template< class... B >
246  struct [[deprecated("Will be removed after release 2.8. Use std::conjunction instead.")]] conjunction
247  : std::conjunction<B...>
248  {};
249 
250 
251  // disjunction
252  // -----------
253 
261  template< class... B >
262  struct [[deprecated("Will be removed after release 2.8. Use std::disjunction instead.")]] disjunction
263  : std::disjunction<B...>
264  {};
265 
266 
267  // negation
268  // --------
269 
277  template<class B>
278  struct [[deprecated("Will be removed after release 2.8. Use std::negation instead.")]] negation
279  : std::negation<B>
280  {};
281 
282 } // namespace Std
283 
284 
285 namespace detail
286 {
287  template <class Type>
288  [[deprecated("Type extraction of `TargetType` has failed. Inspect the code calling `detected_or_fallback_t` for getting the source of this warning!")]]
289  Type warningIfNotDefined(const Std::nonesuch*);
290 
291  template <class Type, class T>
292  Type warningIfNotDefined(const T*);
293 }
294 
296 template <template<typename...> class Fallback,
297  template<typename...> class TargetType, typename... Args>
299  detail::warningIfNotDefined<Std::detected_t<Fallback, Args...> >(std::declval<const Std::detected_t<TargetType, Args...>*>())),
300  TargetType, Args...>;
301 
302 
303 } // namespace Dune
304 
305 #endif // #ifndef DUNE_COMMON_STD_TYPE_TRAITS_HH
Traits for type conversions and type information.
constexpr bool is_detected_exact_v
Convenient access to the result value of is_detected_exact.
Definition: type_traits.hh:206
constexpr bool is_detected_convertible_v
Convenient access to the result value of is_detected_convertible.
Definition: type_traits.hh:228
typename detected_or< Default, Op, Args... >::type detected_or_t
Returns Op<Args...> if that is valid; otherwise returns the fallback type Default.
Definition: type_traits.hh:185
std::is_same< Expected, detected_t< Op, Args... > > is_detected_exact
Checks whether Op<Args...> is Expected without causing an error if Op<Args...> is invalid.
Definition: type_traits.hh:195
typename detected_or< nonesuch, Op, Args... >::type detected_t
Returns Op<Args...> if that is valid; otherwise returns nonesuch.
Definition: type_traits.hh:170
typename Impl::voider< Types... >::type void_t
Is void for all valid input types. The workhorse for C++11 SFINAE-techniques.
Definition: typetraits.hh:40
constexpr bool is_detected_v
Detects whether Op<Args...> is valid and makes the result available as a value.
Definition: type_traits.hh:155
typename detected_or< nonesuch, Op, Args... >::value_t is_detected
Detects whether Op<Args...> is valid.
Definition: type_traits.hh:141
Impl::detector< Default, void, Op, Args... > detected_or
Detects whether Op<Args...> is valid and makes the result available.
Definition: type_traits.hh:128
std::is_convertible< Target, detected_t< Op, Args... > > is_detected_convertible
Checks whether Op<Args...> is convertible to Target without causing an error if Op<Args....
Definition: type_traits.hh:217
Dune namespace.
Definition: alignedallocator.hh:13
Std::detected_or_t< decltype(detail::warningIfNotDefined< Std::detected_t< Fallback, Args... > >(std::declval< const Std::detected_t< TargetType, Args... > * >())), TargetType, Args... > detected_or_fallback_t
This type will be either TargetType<Args...> if it exists, or the Fallback<Args......
Definition: type_traits.hh:300
forms the logical conjunction of the type traits B...
Definition: type_traits.hh:248
forms the logical disjunction of the type traits B...
Definition: type_traits.hh:264
forms the logical negation of the type traits B...
Definition: type_traits.hh:280
Type representing a lookup failure by std::detected_or and friends.
Definition: type_traits.hh:88
Utilities for type computations, constraining overloads, ...
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.80.0 (Apr 26, 22:29, 2024)