LeviLamina
Loading...
Searching...
No Matches
TightPair.h
1#pragma once
2
3#include <type_traits>
4
5namespace ll::data {
6
7constexpr inline struct ZeroThenVariadicArgs {
8} zeroThenVariadicArgs;
9constexpr inline struct OneThenVariadicArgs {
10} oneThenVariadicArgs;
11
12template <class Base, class Other, bool = std::is_empty_v<Base> && !std::is_final_v<Base>>
13class TightPair final : private Base {
14 Other sec;
15
16public:
17 using first_type = Base;
18 using second_type = Other;
19
20 template <class... Ts2>
21 constexpr explicit TightPair(
23 Ts2&&... val2
24 ) noexcept(std::is_nothrow_default_constructible_v<Base> && std::is_nothrow_constructible_v<Other, Ts2...>)
25 : Base(),
26 sec(std::forward<Ts2>(val2)...) {}
27
28 template <class T1, class... Ts2>
29 constexpr TightPair(
31 T1&& val1,
32 Ts2&&... val2
33 ) noexcept(std::is_nothrow_constructible_v<Base, T1> && std::is_nothrow_constructible_v<Other, Ts2...>)
34 : Base(std::forward<T1>(val1)),
35 sec(std::forward<Ts2>(val2)...) {}
36
37 constexpr first_type& first() noexcept { return *this; }
38
39 constexpr first_type const& first() const noexcept { return *this; }
40
41 constexpr second_type& second() noexcept { return sec; }
42
43 constexpr second_type const& second() const noexcept { return sec; }
44};
45
46template <class Base, class Other>
47class TightPair<Base, Other, false> final {
48 Base fst;
49 Other sec;
50
51public:
52 using first_type = Base;
53 using second_type = Other;
54
55 template <class... Ts2>
56 constexpr explicit TightPair(
58 Ts2&&... val2
59 ) noexcept(std::is_nothrow_default_constructible_v<Base> && std::is_nothrow_constructible_v<Other, Ts2...>)
60 : fst(),
61 sec(std::forward<Ts2>(val2)...) {}
62
63 template <class T1, class... Ts2>
64 constexpr TightPair(
66 T1&& val1,
67 Ts2&&... val2
68 ) noexcept(std::is_nothrow_constructible_v<Base, T1> && std::is_nothrow_constructible_v<Other, Ts2...>)
69 : fst(std::forward<T1>(val1)),
70 sec(std::forward<Ts2>(val2)...) {}
71
72 constexpr first_type& first() noexcept { return fst; }
73
74 constexpr first_type const& first() const noexcept { return fst; }
75
76 constexpr second_type& second() noexcept { return sec; }
77
78 constexpr second_type const& second() const noexcept { return sec; }
79};
80} // namespace ll::data
Definition TightPair.h:13
Definition TightPair.h:9
Definition TightPair.h:7