EnTT 4.0.0
Loading...
Searching...
No Matches
utility.hpp
1#ifndef ENTT_CORE_UTILITY_HPP
2#define ENTT_CORE_UTILITY_HPP
3
4#include "../stl/type_traits.hpp"
5#include "../stl/utility.hpp"
6
7namespace entt {
8
16template<typename Type, typename Class>
17[[nodiscard]] constexpr auto overload(Type Class::*member) noexcept {
18 return member;
19}
20
27template<typename Func>
28[[nodiscard]] constexpr auto overload(Func *func) noexcept {
29 return func;
30}
31
36template<typename... Func>
37struct overloaded: Func... {
38 using Func::operator()...;
39};
40
45template<typename... Func>
46overloaded(Func...) -> overloaded<Func...>;
47
52template<typename Func>
58 constexpr y_combinator(Func recursive) noexcept(stl::is_nothrow_move_constructible_v<Func>)
59 : func{stl::move(recursive)} {}
60
67 template<typename... Args>
68 constexpr decltype(auto) operator()(Args &&...args) const noexcept(stl::is_nothrow_invocable_v<Func, const y_combinator &, Args...>) {
69 return func(*this, stl::forward<Args>(args)...);
70 }
71
73 template<typename... Args>
74 constexpr decltype(auto) operator()(Args &&...args) noexcept(stl::is_nothrow_invocable_v<Func, y_combinator &, Args...>) {
75 return func(*this, stl::forward<Args>(args)...);
76 }
77
78private:
79 Func func;
80};
81
82} // namespace entt
83
84#endif
Custom EnTT namespace for the standard template library.
Definition entt.hpp:5
EnTT default namespace.
Definition dense_map.hpp:25
overloaded(Func...) -> overloaded< Func... >
Deduction guide.
constexpr auto overload(Type Class::*member) noexcept
Constant utility to disambiguate overloaded members of a class.
Definition utility.hpp:17
Helper type for visitors.
Definition utility.hpp:37
constexpr y_combinator(Func recursive) noexcept(stl::is_nothrow_move_constructible_v< Func >)
Constructs a y-combinator from a given function.
Definition utility.hpp:58
constexpr decltype(auto) operator()(Args &&...args) const noexcept(stl::is_nothrow_invocable_v< Func, const y_combinator &, Args... >)
Invokes a y-combinator and therefore its underlying function.
Definition utility.hpp:68