Debian Codegraph @

packages/kokkos/tpls/mdspan/include/experimental/__p0009_bits/compressed_pair.hpp

raw
1 //@HEADER
2 // ************************************************************************
3 //
4 // Kokkos v. 4.0
5 // Copyright (2022) National Technology & Engineering
6 // Solutions of Sandia, LLC (NTESS).
7 //
8 // Under the terms of Contract DE-NA0003525 with NTESS,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
12 // See https://kokkos.org/LICENSE for license information.
13 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
14 //
15 //@HEADER
16 #pragma once
17
18 #include "macros.hpp"
19 #include "trait_backports.hpp"
20
21 #if !defined(_MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS)
22 # include "no_unique_address.hpp"
23 #endif
24
25 namespace MDSPAN_IMPL_STANDARD_NAMESPACE {
26 namespace detail {
27
28 // For no unique address emulation, this is the case taken when neither are empty.
29 // For real `[[no_unique_address]]`, this case is always taken.
30 template <class _T1, class _T2, class _Enable = void> struct __compressed_pair {
31 _MDSPAN_NO_UNIQUE_ADDRESS _T1 __t1_val{};
32 _MDSPAN_NO_UNIQUE_ADDRESS _T2 __t2_val{};
33 MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T1 &__first() noexcept { return __t1_val; }
34 MDSPAN_FORCE_INLINE_FUNCTION constexpr _T1 const &__first() const noexcept {
35 return __t1_val;
36 }
37 MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T2 &__second() noexcept { return __t2_val; }
38 MDSPAN_FORCE_INLINE_FUNCTION constexpr _T2 const &__second() const noexcept {
39 return __t2_val;
40 }
41
42 MDSPAN_INLINE_FUNCTION_DEFAULTED
43 constexpr __compressed_pair() = default;
44 MDSPAN_INLINE_FUNCTION_DEFAULTED
45 constexpr __compressed_pair(__compressed_pair const &) = default;
46 MDSPAN_INLINE_FUNCTION_DEFAULTED
47 constexpr __compressed_pair(__compressed_pair &&) = default;
48 MDSPAN_INLINE_FUNCTION_DEFAULTED
49 _MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
50 operator=(__compressed_pair const &) = default;
51 MDSPAN_INLINE_FUNCTION_DEFAULTED
52 _MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
53 operator=(__compressed_pair &&) = default;
54 MDSPAN_INLINE_FUNCTION_DEFAULTED
55 ~__compressed_pair() = default;
56 template <class _T1Like, class _T2Like>
57 MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_T1Like &&__t1, _T2Like &&__t2)
58 : __t1_val((_T1Like &&) __t1), __t2_val((_T2Like &&) __t2) {}
59 };
60
61 #if !defined(_MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS)
62
63 // First empty.
64 template <class _T1, class _T2>
65 struct __compressed_pair<
66 _T1, _T2,
67 std::enable_if_t<_MDSPAN_TRAIT(std::is_empty, _T1) && !_MDSPAN_TRAIT(std::is_empty, _T2)>>
68 : private _T1 {
69 _T2 __t2_val{};
70 MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T1 &__first() noexcept {
71 return *static_cast<_T1 *>(this);
72 }
73 MDSPAN_FORCE_INLINE_FUNCTION constexpr _T1 const &__first() const noexcept {
74 return *static_cast<_T1 const *>(this);
75 }
76 MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T2 &__second() noexcept { return __t2_val; }
77 MDSPAN_FORCE_INLINE_FUNCTION constexpr _T2 const &__second() const noexcept {
78 return __t2_val;
79 }
80
81 MDSPAN_INLINE_FUNCTION_DEFAULTED
82 constexpr __compressed_pair() = default;
83 MDSPAN_INLINE_FUNCTION_DEFAULTED
84 constexpr __compressed_pair(__compressed_pair const &) = default;
85 MDSPAN_INLINE_FUNCTION_DEFAULTED
86 constexpr __compressed_pair(__compressed_pair &&) = default;
87 MDSPAN_INLINE_FUNCTION_DEFAULTED
88 _MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
89 operator=(__compressed_pair const &) = default;
90 MDSPAN_INLINE_FUNCTION_DEFAULTED
91 _MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
92 operator=(__compressed_pair &&) = default;
93 MDSPAN_INLINE_FUNCTION_DEFAULTED
94 ~__compressed_pair() = default;
95 template <class _T1Like, class _T2Like>
96 MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_T1Like &&__t1, _T2Like &&__t2)
97 : _T1((_T1Like &&) __t1), __t2_val((_T2Like &&) __t2) {}
98 };
99
100 // Second empty.
101 template <class _T1, class _T2>
102 struct __compressed_pair<
103 _T1, _T2,
104 std::enable_if_t<!_MDSPAN_TRAIT(std::is_empty, _T1) && _MDSPAN_TRAIT(std::is_empty, _T2)>>
105 : private _T2 {
106 _T1 __t1_val{};
107 MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T1 &__first() noexcept { return __t1_val; }
108 MDSPAN_FORCE_INLINE_FUNCTION constexpr _T1 const &__first() const noexcept {
109 return __t1_val;
110 }
111 MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T2 &__second() noexcept {
112 return *static_cast<_T2 *>(this);
113 }
114 MDSPAN_FORCE_INLINE_FUNCTION constexpr _T2 const &__second() const noexcept {
115 return *static_cast<_T2 const *>(this);
116 }
117
118 MDSPAN_INLINE_FUNCTION_DEFAULTED
119 constexpr __compressed_pair() = default;
120 MDSPAN_INLINE_FUNCTION_DEFAULTED
121 constexpr __compressed_pair(__compressed_pair const &) = default;
122 MDSPAN_INLINE_FUNCTION_DEFAULTED
123 constexpr __compressed_pair(__compressed_pair &&) = default;
124 MDSPAN_INLINE_FUNCTION_DEFAULTED
125 _MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
126 operator=(__compressed_pair const &) = default;
127 MDSPAN_INLINE_FUNCTION_DEFAULTED
128 _MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
129 operator=(__compressed_pair &&) = default;
130 MDSPAN_INLINE_FUNCTION_DEFAULTED
131 ~__compressed_pair() = default;
132
133 template <class _T1Like, class _T2Like>
134 MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_T1Like &&__t1, _T2Like &&__t2)
135 : _T2((_T2Like &&) __t2), __t1_val((_T1Like &&) __t1) {}
136 };
137
138 // Both empty.
139 template <class _T1, class _T2>
140 struct __compressed_pair<
141 _T1, _T2,
142 std::enable_if_t<_MDSPAN_TRAIT(std::is_empty, _T1) && _MDSPAN_TRAIT(std::is_empty, _T2)>>
143 // We need to use the __no_unique_address_emulation wrapper here to avoid
144 // base class ambiguities.
145 #ifdef _MDSPAN_COMPILER_MSVC
146 // MSVC doesn't allow you to access public static member functions of a type
147 // when you *happen* to privately inherit from that type.
148 : protected __no_unique_address_emulation<_T1, 0>,
149 protected __no_unique_address_emulation<_T2, 1>
150 #else
151 : private __no_unique_address_emulation<_T1, 0>,
152 private __no_unique_address_emulation<_T2, 1>
153 #endif
154 {
155 using __first_base_t = __no_unique_address_emulation<_T1, 0>;
156 using __second_base_t = __no_unique_address_emulation<_T2, 1>;
157
158 MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T1 &__first() noexcept {
159 return this->__first_base_t::__ref();
160 }
161 MDSPAN_FORCE_INLINE_FUNCTION constexpr _T1 const &__first() const noexcept {
162 return this->__first_base_t::__ref();
163 }
164 MDSPAN_FORCE_INLINE_FUNCTION _MDSPAN_CONSTEXPR_14 _T2 &__second() noexcept {
165 return this->__second_base_t::__ref();
166 }
167 MDSPAN_FORCE_INLINE_FUNCTION constexpr _T2 const &__second() const noexcept {
168 return this->__second_base_t::__ref();
169 }
170
171 MDSPAN_INLINE_FUNCTION_DEFAULTED
172 constexpr __compressed_pair() = default;
173 MDSPAN_INLINE_FUNCTION_DEFAULTED
174 constexpr __compressed_pair(__compressed_pair const &) = default;
175 MDSPAN_INLINE_FUNCTION_DEFAULTED
176 constexpr __compressed_pair(__compressed_pair &&) = default;
177 MDSPAN_INLINE_FUNCTION_DEFAULTED
178 _MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
179 operator=(__compressed_pair const &) = default;
180 MDSPAN_INLINE_FUNCTION_DEFAULTED
181 _MDSPAN_CONSTEXPR_14_DEFAULTED __compressed_pair &
182 operator=(__compressed_pair &&) = default;
183 MDSPAN_INLINE_FUNCTION_DEFAULTED
184 ~__compressed_pair() = default;
185 template <class _T1Like, class _T2Like>
186 MDSPAN_INLINE_FUNCTION constexpr __compressed_pair(_T1Like &&__t1, _T2Like &&__t2) noexcept
187 : __first_base_t(_T1((_T1Like &&) __t1)),
188 __second_base_t(_T2((_T2Like &&) __t2))
189 { }
190 };
191
192 #endif // !defined(_MDSPAN_USE_ATTRIBUTE_NO_UNIQUE_ADDRESS)
193
194 } // end namespace detail
195 } // end namespace MDSPAN_IMPL_STANDARD_NAMESPACE