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

EnTT 3.16.0

Loading...
Searching...
No Matches
tuple.hpp
1#ifndef ENTT_CORE_TUPLE_HPP
2#define ENTT_CORE_TUPLE_HPP
3
4#include <tuple>
5#include <type_traits>
6#include <utility>
7
8namespace entt {
9
15template<typename Type>
16 struct is_tuple: std::false_type {};
17
22template<typename... Args>
23 struct is_tuple<std::tuple<Args...>>: std::true_type {};
24
29template<typename Type>
30 inline constexpr bool is_tuple_v = is_tuple<Type>::value;
31
39template<typename Type>
40 constexpr decltype(auto) unwrap_tuple(Type &&value) noexcept {
41 if constexpr(std::tuple_size_v<std::remove_reference_t<Type>> == 1u) {
42 return std::get<0>(std::forward<Type>(value));
43 } else {
44 return std::forward<Type>(value);
45 }
46}
47
52template<typename Func>
53 struct forward_apply: private Func {
59 template<typename... Args>
60 constexpr forward_apply(Args &&...args) noexcept(std::is_nothrow_constructible_v<Func, Args...>)
61 : Func{std::forward<Args>(args)...} {}
62
69 template<typename Type>
70 constexpr decltype(auto) operator()(Type &&args) noexcept(noexcept(std::apply(std::declval<Func &>(), args))) {
71 return std::apply(static_cast<Func &>(*this), std::forward<Type>(args));
72 }
73
75 template<typename Type>
76 constexpr decltype(auto) operator()(Type &&args) const noexcept(noexcept(std::apply(std::declval<const Func &>(), args))) {
77 return std::apply(static_cast<const Func &>(*this), std::forward<Type>(args));
78 }
79};
80
85template<typename Func>
86forward_apply(Func) -> forward_apply<std::remove_reference_t<std::remove_const_t<Func>>>;
87
88} // namespace entt
89
90#endif
entt
EnTT default namespace.
Definition dense_map.hpp:22
entt::forward_apply
forward_apply(Func) -> forward_apply< std::remove_reference_t< std::remove_const_t< Func > > >
Deduction guide.
entt::is_tuple_v
constexpr bool is_tuple_v
Helper variable template.
Definition tuple.hpp:30
entt::unwrap_tuple
constexpr decltype(auto) unwrap_tuple(Type &&value) noexcept
Utility function to unwrap tuples of a single element.
Definition tuple.hpp:40
entt::forward_apply
Utility class to forward-and-apply tuple objects.
Definition tuple.hpp:53
entt::forward_apply::operator()
constexpr decltype(auto) operator()(Type &&args) noexcept(noexcept(std::apply(std::declval< Func & >(), args)))
Forwards and applies the arguments with the underlying function.
Definition tuple.hpp:70
entt::forward_apply::forward_apply
constexpr forward_apply(Args &&...args) noexcept(std::is_nothrow_constructible_v< Func, Args... >)
Constructs a forward-and-apply object.
Definition tuple.hpp:60
entt::is_tuple
Provides the member constant value to true if a given type is a tuple, false otherwise.
Definition tuple.hpp:16