EnTT  3.10.0
utility.hpp
1 #ifndef ENTT_CORE_UTILITY_HPP
2 #define ENTT_CORE_UTILITY_HPP
3 
4 #include <utility>
5 #include "../config/config.h"
6 
7 namespace entt {
8 
10 struct identity {
12  using is_transparent = void;
13 
20  template<class Type>
21  [[nodiscard]] constexpr Type &&operator()(Type &&value) const ENTT_NOEXCEPT {
22  return std::forward<Type>(value);
23  }
24 };
25 
33 template<typename Type, typename Class>
34 [[nodiscard]] constexpr auto overload(Type Class::*member) ENTT_NOEXCEPT {
35  return member;
36 }
37 
44 template<typename Func>
45 [[nodiscard]] constexpr auto overload(Func *func) ENTT_NOEXCEPT {
46  return func;
47 }
48 
53 template<class... Func>
54 struct overloaded: Func... {
55  using Func::operator()...;
56 };
57 
62 template<class... Func>
63 overloaded(Func...) -> overloaded<Func...>;
64 
69 template<class Func>
70 struct y_combinator {
75  y_combinator(Func recursive)
76  : func{std::move(recursive)} {}
77 
84  template<class... Args>
85  decltype(auto) operator()(Args &&...args) const {
86  return func(*this, std::forward<Args>(args)...);
87  }
88 
90  template<class... Args>
91  decltype(auto) operator()(Args &&...args) {
92  return func(*this, std::forward<Args>(args)...);
93  }
94 
95 private:
96  Func func;
97 };
98 
99 } // namespace entt
100 
101 #endif
EnTT default namespace.
Definition: dense_map.hpp:22
overloaded(Func...) -> overloaded< Func... >
Deduction guide.
constexpr auto overload(Type Class::*member)
Constant utility to disambiguate overloaded members of a class.
Definition: utility.hpp:34
Identity function object (waiting for C++20).
Definition: utility.hpp:10
void is_transparent
Indicates that this is a transparent function object.
Definition: utility.hpp:12
constexpr Type && operator()(Type &&value) const
Returns its argument unchanged.
Definition: utility.hpp:21
Helper type for visitors.
Definition: utility.hpp:54
Basic implementation of a y-combinator.
Definition: utility.hpp:70
y_combinator(Func recursive)
Constructs a y-combinator from a given function.
Definition: utility.hpp:75