EnTT 3.14.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
11namespace internal {
12
13template<typename>
14struct is_tuple_impl: std::false_type {};
15
16template<typename... Args>
17struct is_tuple_impl<std::tuple<Args...>>: std::true_type {};
18
19} // namespace internal
27template<typename Type>
28struct is_tuple: internal::is_tuple_impl<std::remove_cv_t<Type>> {};
29
34template<typename Type>
35inline constexpr bool is_tuple_v = is_tuple<Type>::value;
36
44template<typename Type>
45constexpr decltype(auto) unwrap_tuple(Type &&value) noexcept {
46 if constexpr(std::tuple_size_v<std::remove_reference_t<Type>> == 1u) {
47 return std::get<0>(std::forward<Type>(value));
48 } else {
49 return std::forward<Type>(value);
50 }
51}
52
57template<typename Func>
58struct forward_apply: private Func {
64 template<typename... Args>
65 constexpr forward_apply(Args &&...args) noexcept(std::is_nothrow_constructible_v<Func, Args...>)
66 : Func{std::forward<Args>(args)...} {}
67
74 template<typename Type>
75 constexpr decltype(auto) operator()(Type &&args) noexcept(noexcept(std::apply(std::declval<Func &>(), args))) {
76 return std::apply(static_cast<Func &>(*this), std::forward<Type>(args));
77 }
78
80 template<typename Type>
81 constexpr decltype(auto) operator()(Type &&args) const noexcept(noexcept(std::apply(std::declval<const Func &>(), args))) {
82 return std::apply(static_cast<const Func &>(*this), std::forward<Type>(args));
83 }
84};
85
90template<typename Func>
92
93} // namespace entt
94
95#endif
EnTT default namespace.
Definition dense_map.hpp:22
constexpr bool is_tuple_v
Helper variable template.
Definition tuple.hpp:35
forward_apply(Func) -> forward_apply< std::remove_reference_t< std::remove_cv_t< Func > > >
Deduction guide.
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
Definition memory.hpp:219
constexpr decltype(auto) unwrap_tuple(Type &&value) noexcept
Utility function to unwrap tuples of a single element.
Definition tuple.hpp:45
Utility class to forward-and-apply tuple objects.
Definition tuple.hpp:58
constexpr forward_apply(Args &&...args) noexcept(std::is_nothrow_constructible_v< Func, Args... >)
Constructs a forward-and-apply object.
Definition tuple.hpp:65
Provides the member constant value to true if a given type is a tuple, false otherwise.
Definition tuple.hpp:28