EnTT 3.14.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
10struct identity {
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 {
36}
37
44template<typename Func>
45[[nodiscard]] constexpr auto overload(Func *func) noexcept {
46 return func;
47}
48
53template<typename... Func>
54struct overloaded: Func... {
55 using Func::operator()...;
56};
57
62template<typename... Func>
63overloaded(Func...) -> overloaded<Func...>;
64
69template<typename Func>
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 default namespace.
Definition dense_map.hpp:22
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
Definition memory.hpp:219
constexpr auto overload(Type Class::*member) noexcept
Constant utility to disambiguate overloaded members of a class.
Definition utility.hpp:34
Identity function object (waiting for C++20).
Definition utility.hpp:10
constexpr Type && operator()(Type &&value) const noexcept
Returns its argument unchanged.
Definition utility.hpp:21
void is_transparent
Indicates that this is a transparent function object.
Definition utility.hpp:12
Helper type for visitors.
Definition utility.hpp:54
Basic implementation of a y-combinator.
Definition utility.hpp:70
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