diff --git a/libcxx/include/__tuple b/libcxx/include/__tuple index 8e6d2bd5915a..775d7340b54d 100644 --- a/libcxx/include/__tuple +++ b/libcxx/include/__tuple @@ -453,57 +453,19 @@ using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type; #endif // _LIBCPP_HAS_NO_VARIADICS #ifndef _LIBCPP_CXX03_LANG +template +struct __tuple_like_with_size_imp : false_type {}; -template -struct __lookup_result { - using type = _Tp; - static constexpr bool _Success = _Good; - static constexpr size_t _Size = _TSize; -}; -using __lookup_failure = __lookup_result; +template +struct __tuple_like_with_size_imp + : integral_constant {}; -template -auto __deduce_tuple_type_ovl(tuple<_Args...>&) - -> __lookup_result, sizeof...(_Args)>; - -template -auto __deduce_tuple_type_ovl(pair<_T1, _T2>&) - -> __lookup_result, 2>; - -template -auto __deduce_tuple_type_ovl(array<_Tp, _Size>&) - -> __lookup_result, _Size>; - -template -auto __deduce_tuple_type_imp(int) - -> decltype(__deduce_tuple_type_ovl(_VSTD::declval<__uncvref_t<_Tp>&>())); -template __lookup_failure __deduce_tuple_type_imp(...); - -// __deduce_tuple_like - Given a type determine if it is, or is derived from, -// a tuple-like type. This trait is used to support constructing and assigning -// to std::tuple from user-types derived from a tuple-like type. -template (0)), - bool _Good = _Result::_Success> -struct __deduce_tuple_like { - static_assert(_Good, "incorrect specialization choosen"); - static constexpr bool _Success = true; - static constexpr size_t _Size = _Result::_Size; - using _RawType = typename _Result::type; - using _QualType = - typename __propagate_value_category<_TupleLike>::template __apply<_RawType>; -}; - -template -struct __deduce_tuple_like<_TupleLike, _Result, /*_Good=*/false> { - static constexpr bool _Success = false; - static constexpr size_t _Size = (size_t)-1; -}; - -template > -using __tuple_like_with_size = integral_constant; +template ::type> +using __tuple_like_with_size = __tuple_like_with_size_imp< + __tuple_like<_RawTuple>::value, + tuple_size<_RawTuple>, _ExpectedSize + >; struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail { template diff --git a/libcxx/include/tuple b/libcxx/include/tuple index c9146fd6ef59..553d8e546f89 100644 --- a/libcxx/include/tuple +++ b/libcxx/include/tuple @@ -555,19 +555,13 @@ class _LIBCPP_TYPE_VIS_ONLY tuple { template static constexpr bool __enable_implicit() { - using _Deduced = __deduce_tuple_like<_Tuple>; - using _QualType = typename _Deduced::_QualType; - static_assert(__tuple_like::value, ""); - return __tuple_convertible<_QualType, tuple>::value; + return __tuple_convertible<_Tuple, tuple>::value; } template static constexpr bool __enable_explicit() { - using _Deduced = __deduce_tuple_like<_Tuple>; - using _QualType = typename _Deduced::_QualType; - static_assert(__tuple_like::value, ""); - return __tuple_constructible<_QualType, tuple>::value - && !__tuple_convertible<_QualType, tuple>::value; + return __tuple_constructible<_Tuple, tuple>::value + && !__tuple_convertible<_Tuple, tuple>::value; } }; @@ -820,74 +814,66 @@ public: _VSTD::forward<_Up>(__u)...) {} template , - class _TupBase = typename _Deduced::_QualType, typename enable_if < _CheckTupleLikeConstructor< - _Deduced::_Size == sizeof...(_Tp) - && !_PackExpandsToThisTuple<_TupBase>::value - >::template __enable_implicit<_TupBase>(), + __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value + && !_PackExpandsToThisTuple<_Tuple>::value + >::template __enable_implicit<_Tuple>(), bool >::type = false > _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 - tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible::value)) - : base_(_VSTD::forward<_TupBase>(__t)) {} + tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible::value)) + : base_(_VSTD::forward<_Tuple>(__t)) {} template , - class _TupBase = typename _Deduced::_QualType, typename enable_if < _CheckTupleLikeConstructor< - _Deduced::_Size == sizeof...(_Tp) - && !_PackExpandsToThisTuple<_TupBase>::value - >::template __enable_explicit<_TupBase>(), + __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value + && !_PackExpandsToThisTuple<_Tuple>::value + >::template __enable_explicit<_Tuple>(), bool >::type = false > _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit - tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible::value)) - : base_(_VSTD::forward<_TupBase>(__t)) {} + tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible::value)) + : base_(_VSTD::forward<_Tuple>(__t)) {} template , - class _TupBase = typename _Deduced::_QualType, typename enable_if < _CheckTupleLikeConstructor< - _Deduced::_Size == sizeof...(_Tp) - >::template __enable_implicit<_TupBase>(), + __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value + >::template __enable_implicit<_Tuple>(), bool >::type = false > _LIBCPP_INLINE_VISIBILITY tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) - : base_(allocator_arg_t(), __a, _VSTD::forward<_TupBase>(__t)) {} + : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {} template , - class _TupBase = typename _Deduced::_QualType, typename enable_if < _CheckTupleLikeConstructor< - _Deduced::_Size == sizeof...(_Tp) - >::template __enable_explicit<_TupBase>(), + __tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value + >::template __enable_explicit<_Tuple>(), bool >::type = false > _LIBCPP_INLINE_VISIBILITY explicit tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t) - : base_(allocator_arg_t(), __a, _VSTD::forward<_TupBase>(__t)) {} + : base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {} using _CanCopyAssign = __all::value...>; using _CanMoveAssign = __all::value...>; _LIBCPP_INLINE_VISIBILITY - tuple& operator=(typename conditional<_CanCopyAssign::value, tuple const&, __nat>::type const& __t) + tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t) _NOEXCEPT_((__all::value...>::value)) { base_.operator=(__t.base_); @@ -903,19 +889,16 @@ public: } template , - class _TupBase = typename _Deduced::_QualType, class = typename enable_if < - __tuple_assignable<_TupBase, tuple>::value + __tuple_assignable<_Tuple, tuple>::value >::type > _LIBCPP_INLINE_VISIBILITY tuple& - operator=(_Tuple&& __t) - _NOEXCEPT_((is_nothrow_assignable::value)) + operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable::value)) { - base_.operator=(_VSTD::forward<_TupBase>(__t)); + base_.operator=(_VSTD::forward<_Tuple>(__t)); return *this; } diff --git a/libcxx/include/type_traits b/libcxx/include/type_traits index c2b90ea3854e..fbfc9d33729d 100644 --- a/libcxx/include/type_traits +++ b/libcxx/include/type_traits @@ -4696,65 +4696,6 @@ struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy> #endif -#ifndef _LIBCPP_CXX03_LANG - -// __propagate_value_category -- A utility for detecting the value category -// of a given type and applying that value-category to another type. -// For example applying the cv-ref quals of a derived type to form the -// correctly cv-qualified base type. -template -struct __propagate_value_category { - template struct __checked_apply { - static_assert(!is_reference<_ToType>::value, "must be unqualified"); - static_assert(!is_const<_ToType>::value - && !is_volatile<_ToType>::value, "must be unqualified"); - using type = _ToType; - }; - template - using __apply = typename __checked_apply<_ToType>::type; -}; - -template -struct __propagate_value_category<_FromType&> { - template - using __apply = typename add_lvalue_reference< - typename __propagate_value_category<_FromType>::template __apply<_ToType> - >::type; -}; - -template -struct __propagate_value_category<_FromType&&> { - template - using __apply = typename add_rvalue_reference< - typename __propagate_value_category<_FromType>::template __apply<_ToType> - >::type; -}; - -template -struct __propagate_value_category<_FromType const> { - template - using __apply = typename add_const< - typename __propagate_value_category<_FromType>::template __apply<_ToType> - >::type; -}; - -template -struct __propagate_value_category<_FromType volatile> { - template - using __apply = typename add_volatile< - typename __propagate_value_category<_FromType>::template __apply<_ToType> - >::type; -}; - -template -struct __propagate_value_category<_FromType const volatile> { - template - using __apply = typename add_cv< - typename __propagate_value_category<_FromType>::template __apply<_ToType> - >::type; -}; -#endif - _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_TYPE_TRAITS diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/derived_from_tuple_like.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/derived_from_tuple_like.pass.cpp deleted file mode 100644 index c9496d0b5b0c..000000000000 --- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.assign/derived_from_tuple_like.pass.cpp +++ /dev/null @@ -1,115 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// template class tuple; - -// template -// tuple& operator=(const tuple& u); - -// UNSUPPORTED: c++98, c++03 - -#include -#include -#include -#include -#include - -#include "propagate_value_category.hpp" - -struct TracksIntQuals { - TracksIntQuals() : value(-1), value_category(VC_None), assigned(false) {} - - template ::type, TracksIntQuals>::value>::type> - TracksIntQuals(Tp &&x) - : value(x), value_category(getValueCategory()), assigned(false) { - static_assert(std::is_same, int>::value, ""); - } - - template ::type, TracksIntQuals>::value>::type> - TracksIntQuals &operator=(Tp &&x) { - static_assert(std::is_same, int>::value, ""); - value = x; - value_category = getValueCategory(); - assigned = true; - return *this; - } - - void reset() { - value = -1; - value_category = VC_None; - assigned = false; - } - - bool checkConstruct(int expect, ValueCategory expect_vc) const { - return value != 1 && value == expect && value_category == expect_vc && - assigned == false; - } - - bool checkAssign(int expect, ValueCategory expect_vc) const { - return value != 1 && value == expect && value_category == expect_vc && - assigned == true; - } - - int value; - ValueCategory value_category; - bool assigned; -}; - -template -struct DerivedFromTup : Tup { - using Tup::Tup; -}; - -template -void do_derived_assign_test() { - using Tup1 = std::tuple; - Tup1 t; - auto reset = [&]() { - std::get<0>(t) = -1; - std::get<1>(t).reset(); - }; - { - DerivedFromTup> d(42, 101); - t = ValueCategoryCast(d); - assert(std::get<0>(t) == 42); - assert(std::get<1>(t).checkAssign(101, VC)); - } - reset(); - { - DerivedFromTup> d(42, 101); - t = ValueCategoryCast(d); - assert(std::get<0>(t) == 42); - assert(std::get<1>(t).checkAssign(101, VC)); - } - reset(); - { - DerivedFromTup> d; - d[0] = 42; - d[1] = 101; - t = ValueCategoryCast(d); - assert(std::get<0>(t) == 42); - assert(std::get<1>(t).checkAssign(101, VC)); - } -} - -int main() { - do_derived_assign_test(); - do_derived_assign_test(); -#if defined(_LIBCPP_VERSION) - // Non-const copy assign and const move assign are libc++ extensions. - do_derived_assign_test(); - do_derived_assign_test(); -#endif -} diff --git a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/derived_from_tuple_like.pass.cpp b/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/derived_from_tuple_like.pass.cpp deleted file mode 100644 index 53b1e3029233..000000000000 --- a/libcxx/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/derived_from_tuple_like.pass.cpp +++ /dev/null @@ -1,154 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// The LLVM Compiler Infrastructure -// -// This file is dual licensed under the MIT and the University of Illinois Open -// Source Licenses. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -// - -// template class tuple; - -// template -// tuple& operator=(const tuple& u); - -// UNSUPPORTED: c++98, c++03 - -#include -#include -#include -#include -#include - -#include "propagate_value_category.hpp" - -template -struct TracksIntQuals { - TracksIntQuals() : value(-1), value_category(VC_None), assigned(false) {} - - template < - class Tp, - typename std::enable_if::type, - TracksIntQuals>::value, - bool>::type = false> - explicit TracksIntQuals(Tp &&x) - : value(x), value_category(getValueCategory()), assigned(false) { - static_assert(std::is_same, int>::value, ""); - } - - template < - class Tp, - typename std::enable_if::type, - TracksIntQuals>::value, - bool>::type = false> - TracksIntQuals(Tp &&x) - : value(x), value_category(getValueCategory()), assigned(false) { - static_assert(std::is_same, int>::value, ""); - } - - template ::type, TracksIntQuals>::value>::type> - TracksIntQuals &operator=(Tp &&x) { - static_assert(std::is_same, int>::value, ""); - value = x; - value_category = getValueCategory(); - assigned = true; - return *this; - } - - void reset() { - value = -1; - value_category = VC_None; - assigned = false; - } - - bool checkConstruct(int expect, ValueCategory expect_vc) const { - return value != 1 && value == expect && value_category == expect_vc && - assigned == false; - } - - bool checkAssign(int expect, ValueCategory expect_vc) const { - return value != 1 && value == expect && value_category == expect_vc && - assigned == true; - } - - int value; - ValueCategory value_category; - bool assigned; -}; - -template -struct DerivedFromTup : Tup { - using Tup::Tup; -}; - -template -void do_derived_construct_test() { - using Tup1 = std::tuple>; - { - DerivedFromTup> d(42, 101); - Tup1 t = ValueCategoryCast(d); - assert(std::get<0>(t) == 42); - assert(std::get<1>(t).checkConstruct(101, VC)); - } - { - DerivedFromTup> d(42, 101); - Tup1 t = ValueCategoryCast(d); - assert(std::get<0>(t) == 42); - assert(std::get<1>(t).checkConstruct(101, VC)); - } - { - DerivedFromTup> d; - d[0] = 42; - d[1] = 101; - Tup1 t = ValueCategoryCast(d); - assert(std::get<0>(t) == 42); - assert(std::get<1>(t).checkConstruct(101, VC)); - } - - using Tup2 = std::tuple>; - { - using D = DerivedFromTup>; - static_assert(!std::is_convertible, Tup2>::value, - ""); - D d(42, 101); - Tup2 t(ValueCategoryCast(d)); - assert(std::get<0>(t) == 42); - assert(std::get<1>(t).checkConstruct(101, VC)); - } - { - using D = DerivedFromTup>; - static_assert(!std::is_convertible, Tup2>::value, - ""); - D d(42, 101); - Tup2 t(ValueCategoryCast(d)); - assert(std::get<0>(t) == 42); - assert(std::get<1>(t).checkConstruct(101, VC)); - } - { - using D = DerivedFromTup>; - static_assert(!std::is_convertible, Tup2>::value, - ""); - D d; - d[0] = 42; - d[1] = 101; - Tup2 t(ValueCategoryCast(d)); - assert(std::get<0>(t) == 42); - assert(std::get<1>(t).checkConstruct(101, VC)); - } -} - -int main() { - do_derived_construct_test(); - do_derived_construct_test(); -#if defined(_LIBCPP_VERSION) - // Supporting non-const copy and const move are libc++ extensions - do_derived_construct_test(); - do_derived_construct_test(); -#endif -} diff --git a/libcxx/test/support/propagate_value_category.hpp b/libcxx/test/support/propagate_value_category.hpp deleted file mode 100644 index fc5443cdaa86..000000000000 --- a/libcxx/test/support/propagate_value_category.hpp +++ /dev/null @@ -1,145 +0,0 @@ -#ifndef TEST_SUPPORT_PROPAGATE_VALUE_CATEGORY -#define TEST_SUPPORT_PROPAGATE_VALUE_CATEGORY - -#include "test_macros.h" -#include - -#if TEST_STD_VER < 11 -#error this header may only be used in C++11 -#endif - -using UnderlyingVCType = unsigned; -enum ValueCategory : UnderlyingVCType { - VC_None = 0, - VC_LVal = 1 << 0, - VC_RVal = 1 << 1, - VC_Const = 1 << 2, - VC_Volatile = 1 << 3, - VC_ConstVolatile = VC_Const | VC_Volatile -}; - -inline constexpr ValueCategory operator&(ValueCategory LHS, ValueCategory RHS) { - return ValueCategory(LHS & (UnderlyingVCType)RHS); -} - -inline constexpr ValueCategory operator|(ValueCategory LHS, ValueCategory RHS) { - return ValueCategory(LHS | (UnderlyingVCType)RHS); -} - -inline constexpr ValueCategory operator^(ValueCategory LHS, ValueCategory RHS) { - return ValueCategory(LHS ^ (UnderlyingVCType)RHS); -} - -inline constexpr bool isValidValueCategory(ValueCategory VC) { - return (VC & (VC_LVal | VC_RVal)) != (VC_LVal | VC_RVal); -} - -inline constexpr bool hasValueCategory(ValueCategory Arg, ValueCategory Key) { - return Arg == Key || ((Arg & Key) == Key); -} - -template -using UnCVRef = - typename std::remove_cv::type>::type; - -template -constexpr ValueCategory getReferenceQuals() { - return std::is_lvalue_reference::value - ? VC_LVal - : (std::is_rvalue_reference::value ? VC_RVal : VC_None); -} -static_assert(getReferenceQuals() == VC_None, ""); -static_assert(getReferenceQuals() == VC_LVal, ""); -static_assert(getReferenceQuals() == VC_RVal, ""); - -template -constexpr ValueCategory getCVQuals() { - using Vp = typename std::remove_reference::type; - return std::is_const::value && std::is_volatile::value - ? VC_ConstVolatile - : (std::is_const::value - ? VC_Const - : (std::is_volatile::value ? VC_Volatile : VC_None)); -} -static_assert(getCVQuals() == VC_None, ""); -static_assert(getCVQuals() == VC_Const, ""); -static_assert(getCVQuals() == VC_Volatile, ""); -static_assert(getCVQuals() == VC_ConstVolatile, ""); -static_assert(getCVQuals() == VC_None, ""); -static_assert(getCVQuals() == VC_Const, ""); - -template -inline constexpr ValueCategory getValueCategory() { - return getReferenceQuals() | getCVQuals(); -} -static_assert(getValueCategory() == VC_None, ""); -static_assert(getValueCategory() == (VC_LVal | VC_Const), ""); -static_assert(getValueCategory() == - (VC_RVal | VC_ConstVolatile), - ""); - -template -struct ApplyValueCategory { -private: - static_assert(isValidValueCategory(VC), ""); - - template - using CondT = typename std::conditional::type; - -public: - template > - using ApplyCVQuals = CondT< - hasValueCategory(VC, VC_ConstVolatile), typename std::add_cv::type, - CondT::type, - CondT::type, Tp>>>; - - template ::type> - using ApplyReferenceQuals = - CondT::type, - CondT::type, Vp>>; - - template - using Apply = ApplyReferenceQuals>>; - - template ::type = true> - static Apply> cast(Tp &&t) { - using ToType = Apply>; - return static_cast(t); - } - - template ::type = true> - static Apply> cast(Tp &&t) { - using ToType = Apply>; - return static_cast(std::move(t)); - } - - template < - class Tp, bool Dummy = true, - typename std::enable_if::type = true> - static Apply> cast(Tp &&t) { - return t; - } -}; - -template -using ApplyValueCategoryT = typename ApplyValueCategory::template Apply; - -template -using PropagateValueCategory = ApplyValueCategory()>; - -template -using PropagateValueCategoryT = - typename ApplyValueCategory()>::template Apply; - -template -typename ApplyValueCategory::template Apply ValueCategoryCast(Tp &&t) { - return ApplyValueCategory::cast(std::forward(t)); -}; - -#endif // TEST_SUPPORT_PROPAGATE_VALUE_CATEGORY