Commit 5c578ae4 by Ville Voutilainen Committed by Ville Voutilainen

Implement LWG 2744 and LWG 2754.

	* include/std/any (any(ValueType&&)): Constrain with __is_in_place_type.
	(any(in_place_type_t<_ValueType>, _Args&&...)): Use _Decay.
	(any(in_place_type_t<_ValueType>, initializer_list<_Up>, _Args&&...)):
	Likewise.
	(emplace(_Args&&...)): Likewise.
	(emplace(initializer_list<_Up>, _Args&&...)): Likewise.
	* include/std/utility: (__is_in_place_type_impl): New.
	(__is_in_place_type): Likewise.
	* testsuite/20_util/any/assign/emplace.cc: Add tests for decaying
	emplace.
	* testsuite/20_util/any/cons/in_place.cc: Add tests for decaying
	in_place constructor.
	* testsuite/20_util/any/misc/any_cast_neg.cc: Adjust.
	* testsuite/20_util/any/requirements.cc: Add a test for
	in_place-constructing a non-default-constructible type.

From-SVN: r239482
parent 7e1dde14
2016-08-15 Ville Voutilainen <ville.voutilainen@gmail.com> 2016-08-15 Ville Voutilainen <ville.voutilainen@gmail.com>
Implement LWG 2744 and LWG 2754.
* include/std/any (any(ValueType&&)): Constrain with __is_in_place_type.
(any(in_place_type_t<_ValueType>, _Args&&...)): Use _Decay.
(any(in_place_type_t<_ValueType>, initializer_list<_Up>, _Args&&...)):
Likewise.
(emplace(_Args&&...)): Likewise.
(emplace(initializer_list<_Up>, _Args&&...)): Likewise.
* include/std/utility: (__is_in_place_type_impl): New.
(__is_in_place_type): Likewise.
* testsuite/20_util/any/assign/emplace.cc: Add tests for decaying
emplace.
* testsuite/20_util/any/cons/in_place.cc: Add tests for decaying
in_place constructor.
* testsuite/20_util/any/misc/any_cast_neg.cc: Adjust.
* testsuite/20_util/any/requirements.cc: Add a test for
in_place-constructing a non-default-constructible type.
2016-08-15 Ville Voutilainen <ville.voutilainen@gmail.com>
Add a feature macro for C++17 make_from_tuple. Add a feature macro for C++17 make_from_tuple.
* include/std/tuple (__cpp_lib_make_from_tuple): New. * include/std/tuple (__cpp_lib_make_from_tuple): New.
(__make_from_tuple_impl(_Tuple&&, index_sequence<_Idx...>)): (__make_from_tuple_impl(_Tuple&&, index_sequence<_Idx...>)):
......
...@@ -153,7 +153,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -153,7 +153,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// Construct with a copy of @p __value as the contained object. /// Construct with a copy of @p __value as the contained object.
template <typename _ValueType, typename _Tp = _Decay<_ValueType>, template <typename _ValueType, typename _Tp = _Decay<_ValueType>,
typename _Mgr = _Manager<_Tp>, typename _Mgr = _Manager<_Tp>,
__any_constructible_t<_Tp, _ValueType&&> = true> __any_constructible_t<_Tp, _ValueType&&> = true,
enable_if_t<!__is_in_place_type<_ValueType>::value, bool> = true>
any(_ValueType&& __value) any(_ValueType&& __value)
: _M_manager(&_Mgr::_S_manage) : _M_manager(&_Mgr::_S_manage)
{ {
...@@ -164,9 +165,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -164,9 +165,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template <typename _ValueType, typename _Tp = _Decay<_ValueType>, template <typename _ValueType, typename _Tp = _Decay<_ValueType>,
typename _Mgr = _Manager<_Tp>, typename _Mgr = _Manager<_Tp>,
enable_if_t<__and_<is_copy_constructible<_Tp>, enable_if_t<__and_<is_copy_constructible<_Tp>,
__not_< __not_<is_constructible<_Tp, _ValueType&&>>,
is_constructible<_Tp, __not_<__is_in_place_type<_ValueType>>>::value,
_ValueType&&>>>::value,
bool> = false> bool> = false>
any(_ValueType&& __value) any(_ValueType&& __value)
: _M_manager(&_Mgr::_S_manage) : _M_manager(&_Mgr::_S_manage)
...@@ -175,10 +175,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -175,10 +175,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
/// Construct with an object created from @p __args as the contained object. /// Construct with an object created from @p __args as the contained object.
template <typename _Tp, typename... _Args, template <typename _ValueType, typename... _Args,
typename _Tp = _Decay<_ValueType>,
typename _Mgr = _Manager<_Tp>, typename _Mgr = _Manager<_Tp>,
__any_constructible_t<_Tp, _Args&&...> = false> __any_constructible_t<_Tp, _Args&&...> = false>
any(in_place_type_t<_Tp>, _Args&&... __args) any(in_place_type_t<_ValueType>, _Args&&... __args)
: _M_manager(&_Mgr::_S_manage) : _M_manager(&_Mgr::_S_manage)
{ {
_Mgr::_S_create(_M_storage, std::forward<_Args>(__args)...); _Mgr::_S_create(_M_storage, std::forward<_Args>(__args)...);
...@@ -186,11 +187,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -186,11 +187,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// Construct with an object created from @p __il and @p __args as /// Construct with an object created from @p __il and @p __args as
/// the contained object. /// the contained object.
template <typename _Tp, typename _Up, typename... _Args, template <typename _ValueType, typename _Up, typename... _Args,
typename _Tp = _Decay<_ValueType>,
typename _Mgr = _Manager<_Tp>, typename _Mgr = _Manager<_Tp>,
__any_constructible_t<_Tp, initializer_list<_Up>, __any_constructible_t<_Tp, initializer_list<_Up>,
_Args&&...> = false> _Args&&...> = false>
any(in_place_type_t<_Tp>, initializer_list<_Up> __il, _Args&&... __args) any(in_place_type_t<_ValueType>,
initializer_list<_Up> __il, _Args&&... __args)
: _M_manager(&_Mgr::_S_manage) : _M_manager(&_Mgr::_S_manage)
{ {
_Mgr::_S_create(_M_storage, __il, std::forward<_Args>(__args)...); _Mgr::_S_create(_M_storage, __il, std::forward<_Args>(__args)...);
...@@ -248,7 +251,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -248,7 +251,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
} }
/// Emplace with an object created from @p __args as the contained object. /// Emplace with an object created from @p __args as the contained object.
template <typename _Tp, typename... _Args, template <typename _ValueType, typename... _Args,
typename _Tp = _Decay<_ValueType>,
typename _Mgr = _Manager<_Tp>, typename _Mgr = _Manager<_Tp>,
__any_constructible_t<_Tp, _Args&&...> = false> __any_constructible_t<_Tp, _Args&&...> = false>
void emplace(_Args&&... __args) void emplace(_Args&&... __args)
...@@ -260,7 +264,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -260,7 +264,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// Emplace with an object created from @p __il and @p __args as /// Emplace with an object created from @p __il and @p __args as
/// the contained object. /// the contained object.
template <typename _Tp, typename _Up, typename... _Args, template <typename _ValueType, typename _Up, typename... _Args,
typename _Tp = _Decay<_ValueType>,
typename _Mgr = _Manager<_Tp>, typename _Mgr = _Manager<_Tp>,
__any_constructible_t<_Tp, initializer_list<_Up>, __any_constructible_t<_Tp, initializer_list<_Up>,
_Args&&...> = false> _Args&&...> = false>
......
...@@ -356,6 +356,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -356,6 +356,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template <size_t _Idx> template <size_t _Idx>
in_place_tag in_place(__in_place_index<_Idx>*) {terminate();} in_place_tag in_place(__in_place_index<_Idx>*) {terminate();}
template<typename>
struct __is_in_place_type_impl : false_type
{ };
template<typename _Tp>
struct __is_in_place_type_impl<in_place_type_t<_Tp>> : true_type
{ };
template<typename _Tp>
struct __is_in_place_type
: public __is_in_place_type_impl<_Tp>
{ };
#define __cpp_lib_as_const 201510 #define __cpp_lib_as_const 201510
template<typename _Tp> template<typename _Tp>
constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; } constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; }
...@@ -363,7 +376,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -363,7 +376,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _Tp> template<typename _Tp>
void as_const(const _Tp&&) = delete; void as_const(const _Tp&&) = delete;
#endif #endif // C++17
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
} // namespace } // namespace
......
...@@ -59,4 +59,17 @@ int main() ...@@ -59,4 +59,17 @@ int main()
combined& c2 = std::any_cast<combined&>(o5); combined& c2 = std::any_cast<combined&>(o5);
VERIFY(c2.v[0] == 1 && c2.v[1] == 2 VERIFY(c2.v[0] == 1 && c2.v[1] == 2
&& std::get<0>(c2.t) == 3 && std::get<1>(c2.t) == 4 ); && std::get<0>(c2.t) == 3 && std::get<1>(c2.t) == 4 );
std::any o6;
o6.emplace<const int&>(i);
VERIFY(o6.type() == o.type());
std::any o7;
o7.emplace<void()>(nullptr);
std::any o8;
o8.emplace<void(*)()>(nullptr);
VERIFY(o7.type() == o8.type());
std::any o9;
o9.emplace<char(&)[42]>(nullptr);
std::any o10;
o10.emplace<char*>(nullptr);
VERIFY(o9.type() == o10.type());
} }
...@@ -54,4 +54,12 @@ int main() ...@@ -54,4 +54,12 @@ int main()
combined& c2 = std::any_cast<combined&>(o5); combined& c2 = std::any_cast<combined&>(o5);
VERIFY(c2.v[0] == 1 && c2.v[1] == 2 VERIFY(c2.v[0] == 1 && c2.v[1] == 2
&& std::get<0>(c2.t) == 3 && std::get<1>(c2.t) == 4 ); && std::get<0>(c2.t) == 3 && std::get<1>(c2.t) == 4 );
std::any o6(std::in_place<int&>, i);
VERIFY(o6.type() == o.type());
std::any o7(std::in_place<void()>, nullptr);
std::any o8(std::in_place<void(*)()>, nullptr);
VERIFY(o7.type() == o8.type());
std::any o9(std::in_place<char(&)[42]>, nullptr);
std::any o10(std::in_place<char*>, nullptr);
VERIFY(o9.type() == o10.type());
} }
...@@ -26,5 +26,5 @@ void test01() ...@@ -26,5 +26,5 @@ void test01()
using std::any_cast; using std::any_cast;
const any y(1); const any y(1);
any_cast<int&>(y); // { dg-error "qualifiers" "" { target { *-*-* } } 435 } any_cast<int&>(y); // { dg-error "qualifiers" "" { target { *-*-* } } 440 }
} }
...@@ -34,3 +34,11 @@ static_assert(!std::is_assignable<any&, const unique_ptr<int>&>::value); ...@@ -34,3 +34,11 @@ static_assert(!std::is_assignable<any&, const unique_ptr<int>&>::value);
static_assert(!std::is_constructible<any&, const unique_ptr<int>&>::value); static_assert(!std::is_constructible<any&, const unique_ptr<int>&>::value);
static_assert(!std::is_assignable<any&, unique_ptr<int>&>::value); static_assert(!std::is_assignable<any&, unique_ptr<int>&>::value);
static_assert(!std::is_constructible<any&, unique_ptr<int>&>::value); static_assert(!std::is_constructible<any&, unique_ptr<int>&>::value);
struct NoDefaultCtor
{
NoDefaultCtor() = delete;
};
static_assert(!std::is_constructible<any,
std::in_place_type_t<NoDefaultCtor>>::value);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment