@@ -257,6 +257,7 @@ 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>
262263#include < __utility/integer_sequence.h>
@@ -283,25 +284,25 @@ _LIBCPP_BEGIN_NAMESPACE_STD
283284
284285// __tuple_leaf
285286
286- template <size_t _Ip, class _Hp , bool = is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value >
287+ template <size_t _Ip, class _Hp >
287288class __tuple_leaf ;
288289
289- template <size_t _Ip, class _Hp , bool _Ep >
290+ template <size_t _Ip, class _Hp >
290291inline _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>) {
292+ swap (__tuple_leaf<_Ip, _Hp>& __x, __tuple_leaf<_Ip, _Hp>& __y) noexcept (__is_nothrow_swappable_v<_Hp>) {
292293 swap (__x.get (), __y.get ());
293294}
294295
295- template <size_t _Ip, class _Hp , bool _Ep >
296+ template <size_t _Ip, class _Hp >
296297_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>) {
298+ swap (const __tuple_leaf<_Ip, _Hp>& __x,
299+ const __tuple_leaf<_Ip, _Hp>& __y) noexcept (__is_nothrow_swappable_v<const _Hp>) {
299300 swap (__x.get (), __y.get ());
300301}
301302
302- template <size_t _Ip, class _Hp , bool >
303+ template <size_t _Ip, class _Hp >
303304class __tuple_leaf {
304- _Hp __value_;
305+ __conditional_no_unique_address<is_empty< _Hp>::value && !__libcpp_is_final<_Hp>::value, _Hp> __value_;
305306
306307 template <class _Tp >
307308 static _LIBCPP_HIDE_FROM_ABI constexpr bool __can_bind_reference () {
@@ -315,23 +316,24 @@ class __tuple_leaf {
315316public:
316317 _LIBCPP_CONSTEXPR_SINCE_CXX14 __tuple_leaf& operator =(const __tuple_leaf&) = delete ;
317318
318- _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf () noexcept (is_nothrow_default_constructible<_Hp>::value) : __value_() {
319+ _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf () noexcept (is_nothrow_default_constructible<_Hp>::value)
320+ : __value_(in_place) {
319321 static_assert (!is_reference<_Hp>::value, " Attempted to default construct a reference element in a tuple" );
320322 }
321323
322324 template <class _Alloc >
323- _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf (integral_constant<int , 0 >, const _Alloc&) : __value_() {
325+ _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf (integral_constant<int , 0 >, const _Alloc&) : __value_(in_place ) {
324326 static_assert (!is_reference<_Hp>::value, " Attempted to default construct a reference element in a tuple" );
325327 }
326328
327329 template <class _Alloc >
328330 _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf (integral_constant<int , 1 >, const _Alloc& __a)
329- : __value_(allocator_arg_t (), __a) {
331+ : __value_(in_place, allocator_arg_t (), __a) {
330332 static_assert (!is_reference<_Hp>::value, " Attempted to default construct a reference element in a tuple" );
331333 }
332334
333335 template <class _Alloc >
334- _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf (integral_constant<int , 2 >, const _Alloc& __a) : __value_(__a) {
336+ _LIBCPP_HIDE_FROM_ABI constexpr __tuple_leaf (integral_constant<int , 2 >, const _Alloc& __a) : __value_(in_place, __a) {
335337 static_assert (!is_reference<_Hp>::value, " Attempted to default construct a reference element in a tuple" );
336338 }
337339
@@ -340,30 +342,30 @@ public:
340342 __enable_if_t <_And<_IsNotSame<__remove_cvref_t <_Tp>, __tuple_leaf>, is_constructible<_Hp, _Tp> >::value, int > = 0 >
341343 _LIBCPP_HIDE_FROM_ABI
342344 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf (_Tp&& __t ) noexcept (is_nothrow_constructible<_Hp, _Tp>::value)
343- : __value_(std::forward<_Tp>(__t )) {
345+ : __value_(in_place, std::forward<_Tp>(__t )) {
344346 static_assert (__can_bind_reference<_Tp&&>(),
345347 " Attempted construction of reference element binds to a temporary whose lifetime has ended" );
346348 }
347349
348350 template <class _Tp , class _Alloc >
349351 _LIBCPP_HIDE_FROM_ABI
350352 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf (integral_constant<int , 0 >, const _Alloc&, _Tp&& __t )
351- : __value_(std::forward<_Tp>(__t )) {
353+ : __value_(in_place, std::forward<_Tp>(__t )) {
352354 static_assert (__can_bind_reference<_Tp&&>(),
353355 " Attempted construction of reference element binds to a temporary whose lifetime has ended" );
354356 }
355357
356358 template <class _Tp , class _Alloc >
357359 _LIBCPP_HIDE_FROM_ABI
358360 _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 )) {
361+ : __value_(in_place, allocator_arg_t (), __a, std::forward<_Tp>(__t )) {
360362 static_assert (!is_reference<_Hp>::value, " Attempted to uses-allocator construct a reference element in a tuple" );
361363 }
362364
363365 template <class _Tp , class _Alloc >
364366 _LIBCPP_HIDE_FROM_ABI
365367 _LIBCPP_CONSTEXPR_SINCE_CXX14 explicit __tuple_leaf (integral_constant<int , 2 >, const _Alloc& __a, _Tp&& __t )
366- : __value_(std::forward<_Tp>(__t ), __a) {
368+ : __value_(in_place, std::forward<_Tp>(__t ), __a) {
367369 static_assert (!is_reference<_Hp>::value, " Attempted to uses-allocator construct a reference element in a tuple" );
368370 }
369371
@@ -382,65 +384,8 @@ public:
382384 return 0 ;
383385 }
384386
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- }
387+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _Hp& get () _NOEXCEPT { return __value_.__v ; }
388+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 const _Hp& get () const _NOEXCEPT { return __value_.__v ; }
444389};
445390
446391template <class ... _Tp>
0 commit comments