forked from OSchip/llvm-project
Revert r289727 due to PR31384
This patch reverts the changes to tuple which fixed construction from types derived from tuple. It breaks the code mentioned in llvm.org/PR31384. I'll follow this commit up with a test case. llvm-svn: 289773
This commit is contained in:
parent
628b43aab6
commit
347a1cc221
|
@ -453,57 +453,19 @@ using tuple_element_t = typename tuple_element <_Ip, _Tp...>::type;
|
|||
#endif // _LIBCPP_HAS_NO_VARIADICS
|
||||
|
||||
#ifndef _LIBCPP_CXX03_LANG
|
||||
template <bool _IsTuple, class _SizeTrait, size_t _Expected>
|
||||
struct __tuple_like_with_size_imp : false_type {};
|
||||
|
||||
template <class _Tp, size_t _TSize, bool _Good = true>
|
||||
struct __lookup_result {
|
||||
using type = _Tp;
|
||||
static constexpr bool _Success = _Good;
|
||||
static constexpr size_t _Size = _TSize;
|
||||
};
|
||||
using __lookup_failure = __lookup_result<void, (size_t)-1, false>;
|
||||
template <class _SizeTrait, size_t _Expected>
|
||||
struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected>
|
||||
: integral_constant<bool, _SizeTrait::value == _Expected> {};
|
||||
|
||||
template <class ..._Args>
|
||||
auto __deduce_tuple_type_ovl(tuple<_Args...>&)
|
||||
-> __lookup_result<tuple<_Args...>, sizeof...(_Args)>;
|
||||
|
||||
template <class _T1, class _T2>
|
||||
auto __deduce_tuple_type_ovl(pair<_T1, _T2>&)
|
||||
-> __lookup_result<pair<_T1, _T2>, 2>;
|
||||
|
||||
template <class _Tp, size_t _Size>
|
||||
auto __deduce_tuple_type_ovl(array<_Tp, _Size>&)
|
||||
-> __lookup_result<array<_Tp, _Size>, _Size>;
|
||||
|
||||
template <class _Tp>
|
||||
auto __deduce_tuple_type_imp(int)
|
||||
-> decltype(__deduce_tuple_type_ovl(_VSTD::declval<__uncvref_t<_Tp>&>()));
|
||||
template <class> __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 <class _TupleLike,
|
||||
class _Result = decltype(__deduce_tuple_type_imp<_TupleLike>(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 <class _TupleLike, class _Result>
|
||||
struct __deduce_tuple_like<_TupleLike, _Result, /*_Good=*/false> {
|
||||
static constexpr bool _Success = false;
|
||||
static constexpr size_t _Size = (size_t)-1;
|
||||
};
|
||||
|
||||
template <class _TupleLike, size_t _ExpectedSize,
|
||||
class _Deduced = __deduce_tuple_like<_TupleLike>>
|
||||
using __tuple_like_with_size = integral_constant<bool,
|
||||
_Deduced::_Success && _Deduced::_Size == _ExpectedSize>;
|
||||
template <class _Tuple, size_t _ExpectedSize,
|
||||
class _RawTuple = typename __uncvref<_Tuple>::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 <class ...>
|
||||
|
|
|
@ -555,19 +555,13 @@ class _LIBCPP_TYPE_VIS_ONLY tuple
|
|||
{
|
||||
template <class _Tuple>
|
||||
static constexpr bool __enable_implicit() {
|
||||
using _Deduced = __deduce_tuple_like<_Tuple>;
|
||||
using _QualType = typename _Deduced::_QualType;
|
||||
static_assert(__tuple_like<typename _Deduced::_RawType>::value, "");
|
||||
return __tuple_convertible<_QualType, tuple>::value;
|
||||
return __tuple_convertible<_Tuple, tuple>::value;
|
||||
}
|
||||
|
||||
template <class _Tuple>
|
||||
static constexpr bool __enable_explicit() {
|
||||
using _Deduced = __deduce_tuple_like<_Tuple>;
|
||||
using _QualType = typename _Deduced::_QualType;
|
||||
static_assert(__tuple_like<typename _Deduced::_RawType>::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 _Tuple,
|
||||
class _Deduced = __deduce_tuple_like<_Tuple>,
|
||||
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<base, _TupBase>::value))
|
||||
: base_(_VSTD::forward<_TupBase>(__t)) {}
|
||||
tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
|
||||
: base_(_VSTD::forward<_Tuple>(__t)) {}
|
||||
|
||||
template <class _Tuple,
|
||||
class _Deduced = __deduce_tuple_like<_Tuple>,
|
||||
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<base, _TupBase>::value))
|
||||
: base_(_VSTD::forward<_TupBase>(__t)) {}
|
||||
tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<base, _Tuple>::value))
|
||||
: base_(_VSTD::forward<_Tuple>(__t)) {}
|
||||
|
||||
template <class _Alloc, class _Tuple,
|
||||
class _Deduced = __deduce_tuple_like<_Tuple>,
|
||||
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 _Alloc, class _Tuple,
|
||||
class _Deduced = __deduce_tuple_like<_Tuple>,
|
||||
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<is_copy_assignable<_Tp>::value...>;
|
||||
using _CanMoveAssign = __all<is_move_assignable<_Tp>::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<is_nothrow_copy_assignable<_Tp>::value...>::value))
|
||||
{
|
||||
base_.operator=(__t.base_);
|
||||
|
@ -903,19 +889,16 @@ public:
|
|||
}
|
||||
|
||||
template <class _Tuple,
|
||||
class _Deduced = __deduce_tuple_like<_Tuple>,
|
||||
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<base&, _TupBase>::value))
|
||||
operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<base&, _Tuple>::value))
|
||||
{
|
||||
base_.operator=(_VSTD::forward<_TupBase>(__t));
|
||||
base_.operator=(_VSTD::forward<_Tuple>(__t));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <class _FromType>
|
||||
struct __propagate_value_category {
|
||||
template <class _ToType> 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 <class _ToType>
|
||||
using __apply = typename __checked_apply<_ToType>::type;
|
||||
};
|
||||
|
||||
template <class _FromType>
|
||||
struct __propagate_value_category<_FromType&> {
|
||||
template <class _ToType>
|
||||
using __apply = typename add_lvalue_reference<
|
||||
typename __propagate_value_category<_FromType>::template __apply<_ToType>
|
||||
>::type;
|
||||
};
|
||||
|
||||
template <class _FromType>
|
||||
struct __propagate_value_category<_FromType&&> {
|
||||
template <class _ToType>
|
||||
using __apply = typename add_rvalue_reference<
|
||||
typename __propagate_value_category<_FromType>::template __apply<_ToType>
|
||||
>::type;
|
||||
};
|
||||
|
||||
template <class _FromType>
|
||||
struct __propagate_value_category<_FromType const> {
|
||||
template <class _ToType>
|
||||
using __apply = typename add_const<
|
||||
typename __propagate_value_category<_FromType>::template __apply<_ToType>
|
||||
>::type;
|
||||
};
|
||||
|
||||
template <class _FromType>
|
||||
struct __propagate_value_category<_FromType volatile> {
|
||||
template <class _ToType>
|
||||
using __apply = typename add_volatile<
|
||||
typename __propagate_value_category<_FromType>::template __apply<_ToType>
|
||||
>::type;
|
||||
};
|
||||
|
||||
template <class _FromType>
|
||||
struct __propagate_value_category<_FromType const volatile> {
|
||||
template <class _ToType>
|
||||
using __apply = typename add_cv<
|
||||
typename __propagate_value_category<_FromType>::template __apply<_ToType>
|
||||
>::type;
|
||||
};
|
||||
#endif
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
||||
#endif // _LIBCPP_TYPE_TRAITS
|
||||
|
|
|
@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <tuple>
|
||||
|
||||
// template <class... Types> class tuple;
|
||||
|
||||
// template <class... UTypes>
|
||||
// tuple& operator=(const tuple<UTypes...>& u);
|
||||
|
||||
// UNSUPPORTED: c++98, c++03
|
||||
|
||||
#include <tuple>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "propagate_value_category.hpp"
|
||||
|
||||
struct TracksIntQuals {
|
||||
TracksIntQuals() : value(-1), value_category(VC_None), assigned(false) {}
|
||||
|
||||
template <class Tp,
|
||||
class = typename std::enable_if<!std::is_same<
|
||||
typename std::decay<Tp>::type, TracksIntQuals>::value>::type>
|
||||
TracksIntQuals(Tp &&x)
|
||||
: value(x), value_category(getValueCategory<Tp &&>()), assigned(false) {
|
||||
static_assert(std::is_same<UnCVRef<Tp>, int>::value, "");
|
||||
}
|
||||
|
||||
template <class Tp,
|
||||
class = typename std::enable_if<!std::is_same<
|
||||
typename std::decay<Tp>::type, TracksIntQuals>::value>::type>
|
||||
TracksIntQuals &operator=(Tp &&x) {
|
||||
static_assert(std::is_same<UnCVRef<Tp>, int>::value, "");
|
||||
value = x;
|
||||
value_category = getValueCategory<Tp &&>();
|
||||
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 <class Tup>
|
||||
struct DerivedFromTup : Tup {
|
||||
using Tup::Tup;
|
||||
};
|
||||
|
||||
template <ValueCategory VC>
|
||||
void do_derived_assign_test() {
|
||||
using Tup1 = std::tuple<long, TracksIntQuals>;
|
||||
Tup1 t;
|
||||
auto reset = [&]() {
|
||||
std::get<0>(t) = -1;
|
||||
std::get<1>(t).reset();
|
||||
};
|
||||
{
|
||||
DerivedFromTup<std::tuple<int, int>> d(42, 101);
|
||||
t = ValueCategoryCast<VC>(d);
|
||||
assert(std::get<0>(t) == 42);
|
||||
assert(std::get<1>(t).checkAssign(101, VC));
|
||||
}
|
||||
reset();
|
||||
{
|
||||
DerivedFromTup<std::pair<int, int>> d(42, 101);
|
||||
t = ValueCategoryCast<VC>(d);
|
||||
assert(std::get<0>(t) == 42);
|
||||
assert(std::get<1>(t).checkAssign(101, VC));
|
||||
}
|
||||
reset();
|
||||
{
|
||||
DerivedFromTup<std::array<int, 2>> d;
|
||||
d[0] = 42;
|
||||
d[1] = 101;
|
||||
t = ValueCategoryCast<VC>(d);
|
||||
assert(std::get<0>(t) == 42);
|
||||
assert(std::get<1>(t).checkAssign(101, VC));
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
do_derived_assign_test<VC_LVal | VC_Const>();
|
||||
do_derived_assign_test<VC_RVal>();
|
||||
#if defined(_LIBCPP_VERSION)
|
||||
// Non-const copy assign and const move assign are libc++ extensions.
|
||||
do_derived_assign_test<VC_LVal>();
|
||||
do_derived_assign_test<VC_RVal | VC_Const>();
|
||||
#endif
|
||||
}
|
|
@ -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.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// <tuple>
|
||||
|
||||
// template <class... Types> class tuple;
|
||||
|
||||
// template <class... UTypes>
|
||||
// tuple& operator=(const tuple<UTypes...>& u);
|
||||
|
||||
// UNSUPPORTED: c++98, c++03
|
||||
|
||||
#include <tuple>
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <cassert>
|
||||
|
||||
#include "propagate_value_category.hpp"
|
||||
|
||||
template <bool Explicit = false>
|
||||
struct TracksIntQuals {
|
||||
TracksIntQuals() : value(-1), value_category(VC_None), assigned(false) {}
|
||||
|
||||
template <
|
||||
class Tp,
|
||||
typename std::enable_if<Explicit &&
|
||||
!std::is_same<typename std::decay<Tp>::type,
|
||||
TracksIntQuals>::value,
|
||||
bool>::type = false>
|
||||
explicit TracksIntQuals(Tp &&x)
|
||||
: value(x), value_category(getValueCategory<Tp &&>()), assigned(false) {
|
||||
static_assert(std::is_same<UnCVRef<Tp>, int>::value, "");
|
||||
}
|
||||
|
||||
template <
|
||||
class Tp,
|
||||
typename std::enable_if<!Explicit &&
|
||||
!std::is_same<typename std::decay<Tp>::type,
|
||||
TracksIntQuals>::value,
|
||||
bool>::type = false>
|
||||
TracksIntQuals(Tp &&x)
|
||||
: value(x), value_category(getValueCategory<Tp &&>()), assigned(false) {
|
||||
static_assert(std::is_same<UnCVRef<Tp>, int>::value, "");
|
||||
}
|
||||
|
||||
template <class Tp,
|
||||
class = typename std::enable_if<!std::is_same<
|
||||
typename std::decay<Tp>::type, TracksIntQuals>::value>::type>
|
||||
TracksIntQuals &operator=(Tp &&x) {
|
||||
static_assert(std::is_same<UnCVRef<Tp>, int>::value, "");
|
||||
value = x;
|
||||
value_category = getValueCategory<Tp &&>();
|
||||
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 <class Tup>
|
||||
struct DerivedFromTup : Tup {
|
||||
using Tup::Tup;
|
||||
};
|
||||
|
||||
template <ValueCategory VC>
|
||||
void do_derived_construct_test() {
|
||||
using Tup1 = std::tuple<long, TracksIntQuals</*Explicit*/ false>>;
|
||||
{
|
||||
DerivedFromTup<std::tuple<int, int>> d(42, 101);
|
||||
Tup1 t = ValueCategoryCast<VC>(d);
|
||||
assert(std::get<0>(t) == 42);
|
||||
assert(std::get<1>(t).checkConstruct(101, VC));
|
||||
}
|
||||
{
|
||||
DerivedFromTup<std::pair<int, int>> d(42, 101);
|
||||
Tup1 t = ValueCategoryCast<VC>(d);
|
||||
assert(std::get<0>(t) == 42);
|
||||
assert(std::get<1>(t).checkConstruct(101, VC));
|
||||
}
|
||||
{
|
||||
DerivedFromTup<std::array<int, 2>> d;
|
||||
d[0] = 42;
|
||||
d[1] = 101;
|
||||
Tup1 t = ValueCategoryCast<VC>(d);
|
||||
assert(std::get<0>(t) == 42);
|
||||
assert(std::get<1>(t).checkConstruct(101, VC));
|
||||
}
|
||||
|
||||
using Tup2 = std::tuple<long, TracksIntQuals</*Explicit*/ true>>;
|
||||
{
|
||||
using D = DerivedFromTup<std::tuple<int, int>>;
|
||||
static_assert(!std::is_convertible<ApplyValueCategoryT<VC, D>, Tup2>::value,
|
||||
"");
|
||||
D d(42, 101);
|
||||
Tup2 t(ValueCategoryCast<VC>(d));
|
||||
assert(std::get<0>(t) == 42);
|
||||
assert(std::get<1>(t).checkConstruct(101, VC));
|
||||
}
|
||||
{
|
||||
using D = DerivedFromTup<std::pair<int, int>>;
|
||||
static_assert(!std::is_convertible<ApplyValueCategoryT<VC, D>, Tup2>::value,
|
||||
"");
|
||||
D d(42, 101);
|
||||
Tup2 t(ValueCategoryCast<VC>(d));
|
||||
assert(std::get<0>(t) == 42);
|
||||
assert(std::get<1>(t).checkConstruct(101, VC));
|
||||
}
|
||||
{
|
||||
using D = DerivedFromTup<std::array<int, 2>>;
|
||||
static_assert(!std::is_convertible<ApplyValueCategoryT<VC, D>, Tup2>::value,
|
||||
"");
|
||||
D d;
|
||||
d[0] = 42;
|
||||
d[1] = 101;
|
||||
Tup2 t(ValueCategoryCast<VC>(d));
|
||||
assert(std::get<0>(t) == 42);
|
||||
assert(std::get<1>(t).checkConstruct(101, VC));
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
do_derived_construct_test<VC_LVal | VC_Const>();
|
||||
do_derived_construct_test<VC_RVal>();
|
||||
#if defined(_LIBCPP_VERSION)
|
||||
// Supporting non-const copy and const move are libc++ extensions
|
||||
do_derived_construct_test<VC_LVal>();
|
||||
do_derived_construct_test<VC_RVal | VC_Const>();
|
||||
#endif
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
#ifndef TEST_SUPPORT_PROPAGATE_VALUE_CATEGORY
|
||||
#define TEST_SUPPORT_PROPAGATE_VALUE_CATEGORY
|
||||
|
||||
#include "test_macros.h"
|
||||
#include <type_traits>
|
||||
|
||||
#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 <class Tp>
|
||||
using UnCVRef =
|
||||
typename std::remove_cv<typename std::remove_reference<Tp>::type>::type;
|
||||
|
||||
template <class Tp>
|
||||
constexpr ValueCategory getReferenceQuals() {
|
||||
return std::is_lvalue_reference<Tp>::value
|
||||
? VC_LVal
|
||||
: (std::is_rvalue_reference<Tp>::value ? VC_RVal : VC_None);
|
||||
}
|
||||
static_assert(getReferenceQuals<int>() == VC_None, "");
|
||||
static_assert(getReferenceQuals<int &>() == VC_LVal, "");
|
||||
static_assert(getReferenceQuals<int &&>() == VC_RVal, "");
|
||||
|
||||
template <class Tp>
|
||||
constexpr ValueCategory getCVQuals() {
|
||||
using Vp = typename std::remove_reference<Tp>::type;
|
||||
return std::is_const<Vp>::value && std::is_volatile<Vp>::value
|
||||
? VC_ConstVolatile
|
||||
: (std::is_const<Vp>::value
|
||||
? VC_Const
|
||||
: (std::is_volatile<Vp>::value ? VC_Volatile : VC_None));
|
||||
}
|
||||
static_assert(getCVQuals<int>() == VC_None, "");
|
||||
static_assert(getCVQuals<int const>() == VC_Const, "");
|
||||
static_assert(getCVQuals<int volatile>() == VC_Volatile, "");
|
||||
static_assert(getCVQuals<int const volatile>() == VC_ConstVolatile, "");
|
||||
static_assert(getCVQuals<int &>() == VC_None, "");
|
||||
static_assert(getCVQuals<int const &>() == VC_Const, "");
|
||||
|
||||
template <class Tp>
|
||||
inline constexpr ValueCategory getValueCategory() {
|
||||
return getReferenceQuals<Tp>() | getCVQuals<Tp>();
|
||||
}
|
||||
static_assert(getValueCategory<int>() == VC_None, "");
|
||||
static_assert(getValueCategory<int const &>() == (VC_LVal | VC_Const), "");
|
||||
static_assert(getValueCategory<int const volatile &&>() ==
|
||||
(VC_RVal | VC_ConstVolatile),
|
||||
"");
|
||||
|
||||
template <ValueCategory VC>
|
||||
struct ApplyValueCategory {
|
||||
private:
|
||||
static_assert(isValidValueCategory(VC), "");
|
||||
|
||||
template <bool Pred, class Then, class Else>
|
||||
using CondT = typename std::conditional<Pred, Then, Else>::type;
|
||||
|
||||
public:
|
||||
template <class Tp, class Vp = UnCVRef<Tp>>
|
||||
using ApplyCVQuals = CondT<
|
||||
hasValueCategory(VC, VC_ConstVolatile), typename std::add_cv<Vp>::type,
|
||||
CondT<hasValueCategory(VC, VC_Const), typename std::add_const<Vp>::type,
|
||||
CondT<hasValueCategory(VC, VC_Volatile),
|
||||
typename std::add_volatile<Vp>::type, Tp>>>;
|
||||
|
||||
template <class Tp, class Vp = typename std::remove_reference<Tp>::type>
|
||||
using ApplyReferenceQuals =
|
||||
CondT<hasValueCategory(VC, VC_LVal),
|
||||
typename std::add_lvalue_reference<Vp>::type,
|
||||
CondT<hasValueCategory(VC, VC_RVal),
|
||||
typename std::add_rvalue_reference<Vp>::type, Vp>>;
|
||||
|
||||
template <class Tp>
|
||||
using Apply = ApplyReferenceQuals<ApplyCVQuals<UnCVRef<Tp>>>;
|
||||
|
||||
template <class Tp, bool Dummy = true,
|
||||
typename std::enable_if<Dummy && (VC & VC_LVal), bool>::type = true>
|
||||
static Apply<UnCVRef<Tp>> cast(Tp &&t) {
|
||||
using ToType = Apply<UnCVRef<Tp>>;
|
||||
return static_cast<ToType>(t);
|
||||
}
|
||||
|
||||
template <class Tp, bool Dummy = true,
|
||||
typename std::enable_if<Dummy && (VC & VC_RVal), bool>::type = true>
|
||||
static Apply<UnCVRef<Tp>> cast(Tp &&t) {
|
||||
using ToType = Apply<UnCVRef<Tp>>;
|
||||
return static_cast<ToType>(std::move(t));
|
||||
}
|
||||
|
||||
template <
|
||||
class Tp, bool Dummy = true,
|
||||
typename std::enable_if<Dummy && ((VC & (VC_LVal | VC_RVal)) == VC_None),
|
||||
bool>::type = true>
|
||||
static Apply<UnCVRef<Tp>> cast(Tp &&t) {
|
||||
return t;
|
||||
}
|
||||
};
|
||||
|
||||
template <ValueCategory VC, class Tp>
|
||||
using ApplyValueCategoryT = typename ApplyValueCategory<VC>::template Apply<Tp>;
|
||||
|
||||
template <class Tp>
|
||||
using PropagateValueCategory = ApplyValueCategory<getValueCategory<Tp>()>;
|
||||
|
||||
template <class Tp, class Up>
|
||||
using PropagateValueCategoryT =
|
||||
typename ApplyValueCategory<getValueCategory<Tp>()>::template Apply<Up>;
|
||||
|
||||
template <ValueCategory VC, class Tp>
|
||||
typename ApplyValueCategory<VC>::template Apply<Tp> ValueCategoryCast(Tp &&t) {
|
||||
return ApplyValueCategory<VC>::cast(std::forward<Tp>(t));
|
||||
};
|
||||
|
||||
#endif // TEST_SUPPORT_PROPAGATE_VALUE_CATEGORY
|
Loading…
Reference in New Issue