1#ifndef ENTT_CORE_COMPRESSED_PAIR_HPP
2#define ENTT_CORE_COMPRESSED_PAIR_HPP
4#include "../stl/concepts.hpp"
5#include "../stl/cstddef.hpp"
6#include "../stl/tuple.hpp"
7#include "../stl/type_traits.hpp"
8#include "../stl/utility.hpp"
10#include "type_traits.hpp"
17template<
typename Type, stl::
size_t>
18struct compressed_pair_element {
19 using reference = Type &;
20 using const_reference =
const Type &;
23 constexpr compressed_pair_element() noexcept(stl::is_nothrow_default_constructible_v<Type>)
24 requires stl::default_initializable<Type> {}
26 template<
typename Arg>
27 constexpr compressed_pair_element(Arg &&arg)
noexcept(stl::is_nothrow_constructible_v<Type, Arg>)
28 requires (!stl::same_as<stl::remove_cvref_t<Arg>, compressed_pair_element>)
29 : value{stl::forward<Arg>(arg)} {}
31 template<
typename... Args, stl::size_t... Index>
32 constexpr compressed_pair_element(stl::tuple<Args...> args, stl::index_sequence<Index...>)
noexcept(stl::is_nothrow_constructible_v<Type, Args...>)
33 : value{stl::forward<Args>(stl::
get<Index>(args))...} {}
35 [[nodiscard]]
constexpr reference
get() noexcept {
39 [[nodiscard]]
constexpr const_reference
get() const noexcept {
47template<
typename Type, stl::
size_t Tag>
48requires is_ebco_eligible_v<Type>
49struct compressed_pair_element<Type, Tag>: Type {
50 using reference = Type &;
51 using const_reference =
const Type &;
52 using base_type = Type;
54 constexpr compressed_pair_element() noexcept(stl::is_nothrow_default_constructible_v<base_type>)
55 requires stl::default_initializable<Type>
58 template<
typename Arg>
59 constexpr compressed_pair_element(Arg &&arg)
noexcept(stl::is_nothrow_constructible_v<base_type, Arg>)
60 requires (!stl::same_as<stl::remove_cvref_t<Arg>, compressed_pair_element>)
61 : base_type{stl::forward<Arg>(arg)} {}
63 template<
typename... Args, stl::size_t... Index>
64 constexpr compressed_pair_element(stl::tuple<Args...> args, stl::index_sequence<Index...>)
noexcept(stl::is_nothrow_constructible_v<base_type, Args...>)
65 : base_type{stl::forward<Args>(stl::
get<Index>(args))...} {}
67 [[nodiscard]]
constexpr reference
get() noexcept {
71 [[nodiscard]]
constexpr const_reference
get() const noexcept {
88template<
typename First,
typename Second>
90 : internal::compressed_pair_element<First, 0u>,
91 internal::compressed_pair_element<Second, 1u> {
92 using first_base = internal::compressed_pair_element<First, 0u>;
93 using second_base = internal::compressed_pair_element<Second, 1u>;
107 constexpr compressed_pair() noexcept(
stl::is_nothrow_default_constructible_v<first_base> &&
stl::is_nothrow_default_constructible_v<second_base>)
131 template<
typename Arg,
typename Other>
132 constexpr compressed_pair(Arg &&arg, Other &&other)
noexcept(stl::is_nothrow_constructible_v<first_base, Arg> && stl::is_nothrow_constructible_v<second_base, Other>)
133 : first_base{
stl::forward<Arg>(arg)},
134 second_base{
stl::forward<Other>(other)} {}
143 template<
typename... Args,
typename... Other>
144 constexpr compressed_pair(stl::piecewise_construct_t, stl::tuple<Args...> args, stl::tuple<Other...> other)
noexcept(stl::is_nothrow_constructible_v<first_base, Args...> && stl::is_nothrow_constructible_v<second_base, Other...>)
145 : first_base{
stl::move(args),
stl::index_sequence_for<Args...>{}},
146 second_base{stl::move(other), stl::index_sequence_for<Other...>{}} {}
170 return static_cast<first_base &
>(*this).get();
175 return static_cast<const first_base &
>(*this).get();
183 return static_cast<second_base &
>(*this).get();
188 return static_cast<const second_base &
>(*this).get();
207 template<stl::
size_t Index>
208 requires (Index <= 1u)
209 [[nodiscard]]
constexpr decltype(
auto)
get() noexcept {
210 if constexpr(Index == 0u) {
218 template<stl::
size_t Index>
219 requires (Index <= 1u)
220 [[nodiscard]]
constexpr decltype(
auto)
get() const noexcept {
221 if constexpr(Index == 0u) {
234template<
typename Type,
typename Other>
244template<
typename First,
typename Second>
256template<
typename First,
typename Second>
259template<entt::stl::
size_t Index,
typename First,
typename Second>
260requires (Index <= 1u)
constexpr second_type & second() noexcept
Returns the second element that a pair stores.
constexpr void swap(compressed_pair &other) noexcept
Swaps two compressed pair objects.
constexpr const first_type & first() const noexcept
Returns the first element that a pair stores.
constexpr compressed_pair(compressed_pair &&other) noexcept=default
Move constructor.
constexpr decltype(auto) get() noexcept
Extracts an element from the compressed pair.
constexpr compressed_pair(const compressed_pair &other)=default
Copy constructor.
constexpr compressed_pair() noexcept(stl::is_nothrow_default_constructible_v< first_base > &&stl::is_nothrow_default_constructible_v< second_base >)
Default constructor, conditionally enabled.
constexpr compressed_pair(stl::piecewise_construct_t, stl::tuple< Args... > args, stl::tuple< Other... > other) noexcept(stl::is_nothrow_constructible_v< first_base, Args... > &&stl::is_nothrow_constructible_v< second_base, Other... >)
Constructs a pair by forwarding the arguments to its parts.
constexpr compressed_pair(Arg &&arg, Other &&other) noexcept(stl::is_nothrow_constructible_v< first_base, Arg > &&stl::is_nothrow_constructible_v< second_base, Other >)
Constructs a pair from its values.
constexpr first_type & first() noexcept
Returns the first element that a pair stores.
First first_type
The type of the first element that the pair stores.
constexpr compressed_pair & operator=(const compressed_pair &other)=default
Copy assignment operator.
constexpr decltype(auto) get() const noexcept
Extracts an element from the compressed pair.
~compressed_pair()=default
Default destructor.
constexpr const second_type & second() const noexcept
Returns the second element that a pair stores.
Second second_type
The type of the second element that the pair stores.
constexpr compressed_pair & operator=(compressed_pair &&other) noexcept=default
Move assignment operator.
Custom EnTT namespace for the standard template library.
constexpr void swap(compressed_pair< First, Second > &lhs, compressed_pair< First, Second > &rhs) noexcept
Swaps two compressed pair objects.
constexpr get_t< Type... > get
Variable template for lists of observed elements.
stl::integral_constant< decltype(Value), Value > integral_constant
Wraps a static constant.
compressed_pair(Type &&, Other &&) -> compressed_pair< stl::decay_t< Type >, stl::decay_t< Other > >
Deduction guide.