OGLplus  (0.59.0) a C++ wrapper for rendering APIs

type_identity.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_TYPE_IDENTITY_HPP
10 #define EAGINE_TYPE_IDENTITY_HPP
11 
12 #include <type_traits>
13 
14 namespace eagine {
15 
18 template <typename T>
19 struct type_identity {
21  using type = T;
22 
24  template <
25  typename X,
26  typename = std::enable_if_t<std::is_same_v<T, X> && !std::is_array_v<X>>>
27  constexpr auto operator()(X v) const -> X {
28  return v;
29  }
30 };
31 
35 template <typename T, typename F>
36 struct get_type {
37  template <typename X>
38  static auto _get(X*) -> typename X::type;
39 
40  template <typename X>
41  static auto _get(...) -> F;
42 
43  using type = decltype(_get<T>(static_cast<T*>(nullptr)));
44 };
45 
48 template <typename T, typename F = void>
49 using type_t = typename get_type<T, F>::type;
50 
53 template <typename T>
54 static constexpr auto make_identity(const T&) noexcept -> type_identity<T> {
55  return {};
56 }
57 
58 } // namespace eagine
59 
60 #endif // EAGINE_TYPE_IDENTITY_HPP
static constexpr auto make_identity(const T &) noexcept -> type_identity< T >
Makes type_identity for type T of the argument.
Definition: type_identity.hpp:54
Implementation detail of the type_t template.
Definition: type_identity.hpp:36
typename get_type< T, F >::type type_t
Template returning nested alias type of type T or void.
Definition: type_identity.hpp:49
Common code is placed in this namespace.
Definition: eagine.hpp:21
std::remove_cv_t< T[C][R]> type
Alias for the argument of this template.
Definition: type_identity.hpp:21
Template type used mostly for function type-tag dispatching.
Definition: type_identity.hpp:19
constexpr auto operator()(X v) const -> X
Call operator returning a copy of its argument unchanged.
Definition: type_identity.hpp:27

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).