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