summaryrefslogtreecommitdiffstats
path: root/libcxx/include/any
diff options
context:
space:
mode:
authorEric Fiselier <eric@efcs.ca>2016-10-07 21:27:45 +0000
committerEric Fiselier <eric@efcs.ca>2016-10-07 21:27:45 +0000
commitb18fd9654f67876d366dc7d5577a5c91287d8353 (patch)
tree19539be19870ba70f2fe9c75d55ef4aaa9e28f4d /libcxx/include/any
parentc50b1a263bcb7edd1d6f2e08cb47a6dcc0562eb7 (diff)
downloadbcm5719-llvm-b18fd9654f67876d366dc7d5577a5c91287d8353.tar.gz
bcm5719-llvm-b18fd9654f67876d366dc7d5577a5c91287d8353.zip
Fix various issues in std::any and the related tests.
* Fix self-swap. Patch from Casey Carter. * Remove workarounds and tests for types with deleted move constructors. This was originally added as part of a LWG proposed resolution that has since changed. * Re-apply most recent PR for LWG 2769. * Re-apply most recent PR for LWG 2754. Specifically fix the SFINAE checks to use the decayed type. * Fix tests to allow moved-from std::any's to have a non-empty state. This is the behavior of MSVC's std::any. * Various whitespace and test fixes. llvm-svn: 283606
Diffstat (limited to 'libcxx/include/any')
-rw-r--r--libcxx/include/any108
1 files changed, 46 insertions, 62 deletions
diff --git a/libcxx/include/any b/libcxx/include/any
index 6f742cbdf73..69fdbddd621 100644
--- a/libcxx/include/any
+++ b/libcxx/include/any
@@ -197,30 +197,33 @@ public:
template <
class _ValueType
+ , class _Tp = decay_t<_ValueType>
, class = enable_if_t<
- !is_same<decay_t<_ValueType>, any>::value &&
+ !is_same<_Tp, any>::value &&
!__is_inplace_type<_ValueType>::value &&
- is_copy_constructible<_ValueType>::value>
+ is_copy_constructible<_Tp>::value>
>
_LIBCPP_INLINE_VISIBILITY
any(_ValueType && __value);
- template <class _Tp, class ..._Args,
+ template <class _ValueType, class ..._Args,
+ class _Tp = decay_t<_ValueType>,
class = enable_if_t<
is_constructible<_Tp, _Args...>::value &&
is_copy_constructible<_Tp>::value
>
>
_LIBCPP_INLINE_VISIBILITY
- explicit any(in_place_type_t<_Tp>, _Args&&... __args);
+ explicit any(in_place_type_t<_ValueType>, _Args&&... __args);
- template <class _Tp, class _Up, class ..._Args,
+ template <class _ValueType, class _Up, class ..._Args,
+ class _Tp = decay_t<_ValueType>,
class = enable_if_t<
is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value &&
is_copy_constructible<_Tp>::value>
>
_LIBCPP_INLINE_VISIBILITY
- explicit any(in_place_type_t<_Tp>, initializer_list<_Up>, _Args&&... __args);
+ explicit any(in_place_type_t<_ValueType>, initializer_list<_Up>, _Args&&... __args);
_LIBCPP_INLINE_VISIBILITY
~any() { this->reset(); }
@@ -242,15 +245,17 @@ public:
// ValueType constructor?
template <
class _ValueType
+ , class _Tp = decay_t<_ValueType>
, class = enable_if_t<
- !is_same<decay_t<_ValueType>, any>::value
- && is_copy_constructible<_ValueType>::value
+ !is_same<_Tp, any>::value
+ && is_copy_constructible<_Tp>::value
&& !__is_inplace_type<_ValueType>::value>
>
_LIBCPP_INLINE_VISIBILITY
any & operator=(_ValueType && __rhs);
- template <class _Tp, class ..._Args,
+ template <class _ValueType, class ..._Args,
+ class _Tp = decay_t<_ValueType>,
class = enable_if_t<
is_constructible<_Tp, _Args...>::value &&
is_copy_constructible<_Tp>::value>
@@ -258,7 +263,8 @@ public:
_LIBCPP_INLINE_VISIBILITY
void emplace(_Args&&... args);
- template <class _Tp, class _Up, class ..._Args,
+ template <class _ValueType, class _Up, class ..._Args,
+ class _Tp = decay_t<_ValueType>,
class = enable_if_t<
is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value &&
is_copy_constructible<_Tp>::value>
@@ -490,60 +496,49 @@ namespace __any_imp
} // namespace __any_imp
-template <class _ValueType, class>
+template <class _ValueType, class _Tp, class>
any::any(_ValueType && __v) : __h(nullptr)
{
- typedef typename decay<_ValueType>::type _Tp;
- static_assert(is_copy_constructible<_Tp>::value,
- "_ValueType must be CopyConstructible.");
- using _ForwardTp = conditional_t<
- is_move_constructible<_Tp>::value, _ValueType, _ValueType&>;
- typedef __any_imp::_Handler<_Tp> _HandlerType;
- _HandlerType::__create(*this, _VSTD::forward<_ForwardTp>(__v));
+ __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_ValueType>(__v));
}
-template <class _Tp, class ..._Args, class>
-any::any(in_place_type_t<_Tp>, _Args&&... __args) {
- using _Hp = __any_imp::_Handler<_Tp>;
- _Hp::__create(*this, _VSTD::forward<_Args>(__args)...);
+template <class _ValueType, class ..._Args, class _Tp, class>
+any::any(in_place_type_t<_ValueType>, _Args&&... __args) {
+ __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_Args>(__args)...);
};
-template <class _Tp, class _Up, class ..._Args, class>
-any::any(in_place_type_t<_Tp>, initializer_list<_Up> __il, _Args&&... __args) {
- using _Hp = __any_imp::_Handler<_Tp>;
- _Hp::__create(*this, __il, _VSTD::forward<_Args>(__args)...);
+template <class _ValueType, class _Up, class ..._Args, class _Tp, class>
+any::any(in_place_type_t<_ValueType>, initializer_list<_Up> __il, _Args&&... __args) {
+ __any_imp::_Handler<_Tp>::__create(*this, __il, _VSTD::forward<_Args>(__args)...);
}
-template <class _ValueType, class>
+template <class _ValueType, class, class>
inline _LIBCPP_INLINE_VISIBILITY
any & any::operator=(_ValueType && __v)
{
- typedef typename decay<_ValueType>::type _Tp;
- static_assert(is_copy_constructible<_Tp>::value,
- "_ValueType must be CopyConstructible.");
any(_VSTD::forward<_ValueType>(__v)).swap(*this);
return *this;
}
-template <class _Tp, class ..._Args, class>
+template <class _ValueType, class ..._Args, class _Tp, class>
inline _LIBCPP_INLINE_VISIBILITY
void any::emplace(_Args&&... __args) {
- using _Hp = __any_imp::_Handler<_Tp>;
reset();
- _Hp::__create(*this, _VSTD::forward<_Args>(__args)...);
+ __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_Args>(__args)...);
}
-template <class _Tp, class _Up, class ..._Args, class>
+template <class _ValueType, class _Up, class ..._Args, class _Tp, class>
inline _LIBCPP_INLINE_VISIBILITY
void any::emplace(initializer_list<_Up> __il, _Args&&... __args) {
- using _Hp = __any_imp::_Handler<_Tp>;
reset();
- _Hp::__create(*this, __il, _VSTD::forward<_Args>(__args)...);
+ __any_imp::_Handler<_Tp>::__create(*this, __il, _VSTD::forward<_Args>(__args)...);
}
inline _LIBCPP_INLINE_VISIBILITY
void any::swap(any & __rhs) _NOEXCEPT
{
+ if (this == &__rhs)
+ return;
if (__h && __rhs.__h) {
any __tmp;
__rhs.__call(_Action::_Move, &__tmp);
@@ -582,50 +577,39 @@ template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType any_cast(any const & __v)
{
- static_assert(
- is_reference<_ValueType>::value
- || is_copy_constructible<_ValueType>::value,
- "_ValueType is required to be a reference or a CopyConstructible type.");
- using _Tp = add_const_t<remove_reference_t<_ValueType>>;
- _Tp * __tmp = _VSTD::any_cast<_Tp>(&__v);
+ using _RawValueType = __uncvref_t<_ValueType>;
+ static_assert(is_constructible<_ValueType, _RawValueType const &>::value,
+ "ValueType is required to be a reference or a CopyConstructible type");
+ auto __tmp = _VSTD::any_cast<add_const_t<_RawValueType>>(&__v);
if (__tmp == nullptr)
__throw_bad_any_cast();
- return *__tmp;
+ return static_cast<_ValueType>(*__tmp);
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType any_cast(any & __v)
{
- static_assert(
- is_reference<_ValueType>::value
- || is_copy_constructible<_ValueType>::value,
- "_ValueType is required to be a reference or a CopyConstructible type.");
- typedef typename remove_reference<_ValueType>::type _Tp;
- _Tp * __tmp = _VSTD::any_cast<_Tp>(&__v);
+ using _RawValueType = __uncvref_t<_ValueType>;
+ static_assert(is_constructible<_ValueType, _RawValueType &>::value,
+ "ValueType is required to be a reference or a CopyConstructible type");
+ auto __tmp = _VSTD::any_cast<_RawValueType>(&__v);
if (__tmp == nullptr)
__throw_bad_any_cast();
- return *__tmp;
+ return static_cast<_ValueType>(*__tmp);
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType any_cast(any && __v)
{
- static_assert(
- is_reference<_ValueType>::value
- || is_copy_constructible<_ValueType>::value,
- "_ValueType is required to be a reference or a CopyConstructible type.");
- typedef typename remove_reference<_ValueType>::type _Tp;
- using _ForwardTp = conditional_t<
- is_reference<_ValueType>::value,
- _ValueType,
- conditional_t<is_move_constructible<_Tp>::value, _Tp, _Tp&>
- >;
- _Tp * __tmp = _VSTD::any_cast<_Tp>(&__v);
+ using _RawValueType = __uncvref_t<_ValueType>;
+ static_assert(is_constructible<_ValueType, _RawValueType>::value,
+ "ValueType is required to be an rvalue reference or a CopyConstructible type");
+ auto __tmp = _VSTD::any_cast<_RawValueType>(&__v);
if (__tmp == nullptr)
__throw_bad_any_cast();
- return _VSTD::forward<_ForwardTp>(*__tmp);
+ return static_cast<_ValueType>(_VSTD::move(*__tmp));
}
template <class _ValueType>
OpenPOWER on IntegriCloud