@@ -257,8 +257,10 @@ template <class... Types>
257257#include < __type_traits/remove_cvref.h>
258258#include < __type_traits/remove_reference.h>
259259#include < __type_traits/unwrap_ref.h>
260+ #include < __utility/conditional_no_unique_address.h>
260261#include < __utility/declval.h>
261262#include < __utility/forward.h>
263+ #include < __utility/in_place.h>
262264#include < __utility/integer_sequence.h>
263265#include < __utility/move.h>
264266#include < __utility/piecewise_construct.h>
@@ -283,25 +285,26 @@ _LIBCPP_BEGIN_NAMESPACE_STD
283285
284286// __tuple_leaf
285287
286- template <size_t _Ip, class _Hp , bool = is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value >
288+ template <size_t _Ip, class _Hp >
287289class __tuple_leaf ;
288290
289- template <size_t _Ip, class _Hp , bool _Ep >
291+ template <size_t _Ip, class _Hp >
290292inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
291- swap (__tuple_leaf<_Ip, _Hp, _Ep >& __x, __tuple_leaf<_Ip, _Hp, _Ep >& __y) noexcept (__is_nothrow_swappable_v<_Hp>) {
293+ swap (__tuple_leaf<_Ip, _Hp>& __x, __tuple_leaf<_Ip, _Hp>& __y) noexcept (__is_nothrow_swappable_v<_Hp>) {
292294 swap (__x.get (), __y.get ());
293295}
294296
295- template <size_t _Ip, class _Hp , bool _Ep >
297+ template <size_t _Ip, class _Hp >
296298_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void
297- swap (const __tuple_leaf<_Ip, _Hp, _Ep >& __x,
298- const __tuple_leaf<_Ip, _Hp, _Ep >& __y) noexcept (__is_nothrow_swappable_v<const _Hp>) {
299+ swap (const __tuple_leaf<_Ip, _Hp>& __x,
300+ const __tuple_leaf<_Ip, _Hp>& __y) noexcept (__is_nothrow_swappable_v<const _Hp>) {
299301 swap (__x.get (), __y.get ());
300302}
301303
302- template <size_t _Ip, class _Hp , bool >
304+ template <size_t _Ip, class _Hp >
303305class __tuple_leaf {
304- _Hp __value_;
306+ _LIBCPP_NO_UNIQUE_ADDRESS __conditional_no_unique_address<is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value, _Hp>
307+ __value_;
305308
306309 template <class _Tp >
307310 static _LIBCPP_HIDE_FROM_ABI constexpr bool __can_bind_reference () {
@@ -315,23 +318,24 @@ class __tuple_leaf {
315318public:
316319 _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator =(const __tuple_leaf&) = delete ;
317320
318- _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf () noexcept (is_nothrow_default_constructible<_Hp>::value) : __value_() {
321+ _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf () noexcept (is_nothrow_default_constructible<_Hp>::value)
322+ : __value_(in_place) {
319323 static_assert (!is_reference<_Hp>::value, " Attempted to default construct a reference element in a tuple" );
320324 }
321325
322326 template <class _Alloc >
323- _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf (integral_constant<int , 0 >, const _Alloc&) : __value_() {
327+ _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf (integral_constant<int , 0 >, const _Alloc&) : __value_(in_place ) {
324328 static_assert (!is_reference<_Hp>::value, " Attempted to default construct a reference element in a tuple" );
325329 }
326330
327331 template <class _Alloc >
328332 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf (integral_constant<int , 1 >, const _Alloc& __a)
329- : __value_(allocator_arg_t (), __a) {
333+ : __value_(in_place, allocator_arg_t (), __a) {
330334 static_assert (!is_reference<_Hp>::value, " Attempted to default construct a reference element in a tuple" );
331335 }
332336
333337 template <class _Alloc >
334- _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf (integral_constant<int , 2 >, const _Alloc& __a) : __value_(__a) {
338+ _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf (integral_constant<int , 2 >, const _Alloc& __a) : __value_(in_place, __a) {
335339 static_assert (!is_reference<_Hp>::value, " Attempted to default construct a reference element in a tuple" );
336340 }
337341
@@ -340,30 +344,30 @@ public:
340344 __enable_if_t <_And<_IsNotSame<__remove_cvref_t <_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp> >::value, int > = 0 >
341345 _LIBCPP_HIDE_FROM_ABI
342346 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf (_Tp&& __t ) noexcept (is_nothrow_constructible<_Hp, _Tp>::value)
343- : __value_(std::forward<_Tp>(__t )) {
347+ : __value_(in_place, std::forward<_Tp>(__t )) {
344348 static_assert (__can_bind_reference<_Tp&&>(),
345349 " Attempted construction of reference element binds to a temporary whose lifetime has ended" );
346350 }
347351
348352 template <class _Tp , class _Alloc >
349353 _LIBCPP_HIDE_FROM_ABI
350354 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf (integral_constant<int , 0 >, const _Alloc&, _Tp&& __t )
351- : __value_(std::forward<_Tp>(__t )) {
355+ : __value_(in_place, std::forward<_Tp>(__t )) {
352356 static_assert (__can_bind_reference<_Tp&&>(),
353357 " Attempted construction of reference element binds to a temporary whose lifetime has ended" );
354358 }
355359
356360 template <class _Tp , class _Alloc >
357361 _LIBCPP_HIDE_FROM_ABI
358362 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf (integral_constant<int , 1 >, const _Alloc& __a, _Tp&& __t )
359- : __value_(allocator_arg_t (), __a, std::forward<_Tp>(__t )) {
363+ : __value_(in_place, allocator_arg_t (), __a, std::forward<_Tp>(__t )) {
360364 static_assert (!is_reference<_Hp>::value, " Attempted to uses-allocator construct a reference element in a tuple" );
361365 }
362366
363367 template <class _Tp , class _Alloc >
364368 _LIBCPP_HIDE_FROM_ABI
365369 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf (integral_constant<int , 2 >, const _Alloc& __a, _Tp&& __t )
366- : __value_(std::forward<_Tp>(__t ), __a) {
370+ : __value_(in_place, std::forward<_Tp>(__t ), __a) {
367371 static_assert (!is_reference<_Hp>::value, " Attempted to uses-allocator construct a reference element in a tuple" );
368372 }
369373
@@ -382,65 +386,8 @@ public:
382386 return 0 ;
383387 }
384388
385- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get () _NOEXCEPT { return __value_; }
386- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get () const _NOEXCEPT { return __value_; }
387- };
388-
389- template <size_t _Ip, class _Hp >
390- class __tuple_leaf <_Ip, _Hp, true > : private _Hp {
391- public:
392- _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator =(const __tuple_leaf&) = delete ;
393-
394- _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf () noexcept (is_nothrow_default_constructible<_Hp>::value) {}
395-
396- template <class _Alloc >
397- _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf (integral_constant<int , 0 >, const _Alloc&) {}
398-
399- template <class _Alloc >
400- _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf (integral_constant<int , 1 >, const _Alloc& __a)
401- : _Hp(allocator_arg_t (), __a) {}
402-
403- template <class _Alloc >
404- _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf (integral_constant<int , 2 >, const _Alloc& __a) : _Hp(__a) {}
405-
406- template <class _Tp ,
407- __enable_if_t < _And< _IsNotSame<__remove_cvref_t <_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp> >::value,
408- int > = 0 >
409- _LIBCPP_HIDE_FROM_ABI
410- _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf (_Tp&& __t ) noexcept (is_nothrow_constructible<_Hp, _Tp>::value)
411- : _Hp(std::forward<_Tp>(__t )) {}
412-
413- template <class _Tp , class _Alloc >
414- _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf (integral_constant<int , 0 >, const _Alloc&, _Tp&& __t )
415- : _Hp(std::forward<_Tp>(__t )) {}
416-
417- template <class _Tp , class _Alloc >
418- _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf (integral_constant<int , 1 >, const _Alloc& __a, _Tp&& __t )
419- : _Hp(allocator_arg_t (), __a, std::forward<_Tp>(__t )) {}
420-
421- template <class _Tp , class _Alloc >
422- _LIBCPP_HIDE_FROM_ABI constexpr explicit __tuple_leaf (integral_constant<int , 2 >, const _Alloc& __a, _Tp&& __t )
423- : _Hp(std::forward<_Tp>(__t ), __a) {}
424-
425- __tuple_leaf (__tuple_leaf const &) = default ;
426- __tuple_leaf (__tuple_leaf&&) = default ;
427-
428- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int
429- swap (__tuple_leaf& __t ) noexcept (__is_nothrow_swappable_v<__tuple_leaf>) {
430- std::swap (*this , __t );
431- return 0 ;
432- }
433-
434- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int swap (const __tuple_leaf& __rhs) const
435- noexcept (__is_nothrow_swappable_v<const __tuple_leaf>) {
436- std::swap (*this , __rhs);
437- return 0 ;
438- }
439-
440- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get () _NOEXCEPT { return static_cast <_Hp&>(*this ); }
441- _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get () const _NOEXCEPT {
442- return static_cast <const _Hp&>(*this );
443- }
389+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get () _NOEXCEPT { return __value_.__v ; }
390+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get () const _NOEXCEPT { return __value_.__v ; }
444391};
445392
446393template <class ... _Tp>
0 commit comments