Skip to content

Commit a376a3f

Browse files
committed
[libc++] Make __compressed_pair fully constexpr
Make `__compressed_pair` fully constexpr Reviewed By: ldionne, #libc, nilayvaish Spies: libcxx-commits Differential Revision: https://reviews.llvm.org/D115687
1 parent d5d8b1c commit a376a3f

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

libcxx/include/__memory/compressed_pair.h

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ struct __compressed_pair_elem {
5858
: __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
5959
#endif
6060

61-
62-
_LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; }
63-
_LIBCPP_INLINE_VISIBILITY
64-
const_reference __get() const _NOEXCEPT { return __value_; }
61+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 reference __get() _NOEXCEPT { return __value_; }
62+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return __value_; }
6563

6664
private:
6765
_Tp __value_;
@@ -97,9 +95,8 @@ struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
9795
: __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
9896
#endif
9997

100-
_LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; }
101-
_LIBCPP_INLINE_VISIBILITY
102-
const_reference __get() const _NOEXCEPT { return *this; }
98+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 reference __get() _NOEXCEPT { return *this; }
99+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __get() const _NOEXCEPT { return *this; }
103100
};
104101

105102
template <class _T1, class _T2>
@@ -143,23 +140,19 @@ class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
143140
typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
144141
#endif
145142

146-
_LIBCPP_INLINE_VISIBILITY
147-
typename _Base1::reference first() _NOEXCEPT {
143+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename _Base1::reference first() _NOEXCEPT {
148144
return static_cast<_Base1&>(*this).__get();
149145
}
150146

151-
_LIBCPP_INLINE_VISIBILITY
152-
typename _Base1::const_reference first() const _NOEXCEPT {
147+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename _Base1::const_reference first() const _NOEXCEPT {
153148
return static_cast<_Base1 const&>(*this).__get();
154149
}
155150

156-
_LIBCPP_INLINE_VISIBILITY
157-
typename _Base2::reference second() _NOEXCEPT {
151+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename _Base2::reference second() _NOEXCEPT {
158152
return static_cast<_Base2&>(*this).__get();
159153
}
160154

161-
_LIBCPP_INLINE_VISIBILITY
162-
typename _Base2::const_reference second() const _NOEXCEPT {
155+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename _Base2::const_reference second() const _NOEXCEPT {
163156
return static_cast<_Base2 const&>(*this).__get();
164157
}
165158

@@ -172,22 +165,18 @@ class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
172165
return static_cast<_Base2*>(__pair);
173166
}
174167

175-
_LIBCPP_INLINE_VISIBILITY
176-
void swap(__compressed_pair& __x)
177-
_NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
178-
__is_nothrow_swappable<_T2>::value)
179-
{
168+
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 void swap(__compressed_pair& __x)
169+
_NOEXCEPT_(__is_nothrow_swappable<_T1>::value && __is_nothrow_swappable<_T2>::value) {
180170
using _VSTD::swap;
181171
swap(first(), __x.first());
182172
swap(second(), __x.second());
183173
}
184174
};
185175

186176
template <class _T1, class _T2>
187-
inline _LIBCPP_INLINE_VISIBILITY
177+
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
188178
void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
189-
_NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
190-
__is_nothrow_swappable<_T2>::value) {
179+
_NOEXCEPT_(__is_nothrow_swappable<_T1>::value && __is_nothrow_swappable<_T2>::value) {
191180
__x.swap(__y);
192181
}
193182

0 commit comments

Comments
 (0)