EnTT: src/entt/core/utility.hpp Source File

EnTT 3.16.0

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