Jamba C++ API  5.1.1
Cpp17.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 pongasoft
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  *
16  * @author Yan Pujante
17  */
18 
19 #pragma once
20 
21 #include <type_traits>
22 
24 
30 namespace experimental {
31  // 3.3.3, Logical operator traits
32  template <class...> using void_t = void;
33 
34  // 3.3.4, Detection idiom
35  template <class...> using void_t = void;
36 
37  struct nonesuch {
38  nonesuch() = delete;
39  ~nonesuch() = delete;
40  nonesuch (nonesuch const&) = delete;
41  void operator=(nonesuch const&) = delete;
42  };
43 
44  template <class _Default, class _AlwaysVoid, template <class...> class _Op, class... _Args>
45  struct _DETECTOR {
46  using value_t = std::false_type;
47  using type = _Default;
48  };
49 
50  template <class _Default, template <class...> class _Op, class... _Args>
51  struct _DETECTOR<_Default, void_t<_Op<_Args...>>, _Op, _Args...> {
52  using value_t = std::true_type;
53  using type = _Op<_Args...>;
54  };
55 
56 
57  template <template<class...> class _Op, class... _Args>
58  using is_detected = typename _DETECTOR<nonesuch, void, _Op, _Args...>::value_t;
59  template <template<class...> class _Op, class... _Args>
60  using detected_t = typename _DETECTOR<nonesuch, void, _Op, _Args...>::type;
61  template <template<class...> class _Op, class... _Args>
62  constexpr bool is_detected_v = is_detected<_Op, _Args...>::value;
63 
64  template <class Default, template<class...> class _Op, class... _Args>
65  using detected_or = _DETECTOR<Default, void, _Op, _Args...>;
66  template <class Default, template<class...> class _Op, class... _Args>
67  using detected_or_t = typename detected_or<Default, _Op, _Args...>::type;
68 
69  template <class Expected, template<class...> class _Op, class... _Args>
70  using is_detected_exact = std::is_same<Expected, detected_t<_Op, _Args...>>;
71  template <class Expected, template<class...> class _Op, class... _Args>
72  constexpr bool is_detected_exact_v = is_detected_exact<Expected, _Op, _Args...>::value;
73 
74  template <class To, template<class...> class _Op, class... _Args>
75  using is_detected_convertible = std::is_convertible<detected_t<_Op, _Args...>, To>;
76  template <class To, template<class...> class _Op, class... _Args>
77  constexpr bool is_detected_convertible_v = is_detected_convertible<To, _Op, _Args...>::value;
78 
79 
80 }}
std::false_type value_t
Definition: Cpp17.h:46
constexpr bool is_detected_convertible_v
Definition: Cpp17.h:77
typename detected_or< Default, _Op, _Args... >::type detected_or_t
Definition: Cpp17.h:67
void void_t
Definition: Cpp17.h:32
constexpr bool is_detected_exact_v
Definition: Cpp17.h:72
Definition: Cpp17.h:23
std::is_convertible< detected_t< _Op, _Args... >, To > is_detected_convertible
Definition: Cpp17.h:75
constexpr bool is_detected_v
Definition: Cpp17.h:62
typename _DETECTOR< nonesuch, void, _Op, _Args... >::type detected_t
Definition: Cpp17.h:60
typename _DETECTOR< nonesuch, void, _Op, _Args... >::value_t is_detected
Definition: Cpp17.h:58
std::is_same< Expected, detected_t< _Op, _Args... > > is_detected_exact
Definition: Cpp17.h:70