diff options
author | Ville Voutilainen <ville.voutilainen@gmail.com> | 2016-11-14 22:47:44 +0200 |
---|---|---|
committer | Ville Voutilainen <ville@gcc.gnu.org> | 2016-11-14 22:47:44 +0200 |
commit | 627a2f592382c96daaa3bce4a22245f0614892d0 (patch) | |
tree | ff762da0e37a6eb4da26f6b67b3cb98d698dd274 /libstdc++-v3/include/std | |
parent | bcb9a772e9287057d8c20fc04c91e716ecff36fe (diff) | |
download | gcc-627a2f592382c96daaa3bce4a22245f0614892d0.zip gcc-627a2f592382c96daaa3bce4a22245f0614892d0.tar.gz gcc-627a2f592382c96daaa3bce4a22245f0614892d0.tar.bz2 |
Implement P0504R0 (Revisiting in-place tag types for any/optional/variant).
Implement P0504R0 (Revisiting in-place tag types for
any/optional/variant).
* include/std/any (any(_ValueType&& __value)): Constrain
the __is_in_place_type with the decayed type.
(make_any): Adjust to use the new tag type.
* include/std/utility (in_place_tag): Remove.
(in_place_t): Turn into a non-reference tag type.
(__in_place, __in_place_type, __in_place_index): Remove.
(in_place): Turn into an inline variable of non-reference
tag type.
(in_place<_Tp>): Remove.
(in_place_index<_Idx>): Remove.
(in_place_type_t): New.
(in_place_type): Turn into a variable template of non-reference
type.
(in_place_index_t): New.
(in_place_index): Turn into a variable template of non-reference
type.
* include/std/variant
(_Variant_storage(in_place_index_t<_Np>, _Args&&...)): Adjust to
use the new tag type.
(_Union(in_place_index_t<0>, _Args&&...)): Likewise.
(_Union(in_place_index_t<_Np>, _Args&&...)): Likewise.
(_Variant_base()): Likewise.
(variant(_Tp&&)): Likewise.
(variant(in_place_type_t<_Tp>, _Args&&...)): Likewise.
(variant(in_place_type_t<_Tp>, initializer_list<_Up>,
_Args&&...)): Likewise.
(variant(in_place_index_t<_Np>, _Args&&...)): Likewise.
(variant(in_place_index_t<_Np>, initializer_list<_Up>,
_Args&&...)): Likewise
(variant(allocator_arg_t, const _Alloc&)): Likewise.
(variant(allocator_arg_t, const _Alloc&, _Tp&&)): Likewise.
(variant(allocator_arg_t, const _Alloc&, in_place_type_t<_Tp>,
_Args&&...)): Likewise.
(variant(allocator_arg_t, const _Alloc&, in_place_type_t<_Tp>,
initializer_list<_Up>, _Args&&...)): Likewise.
(variant(allocator_arg_t, const _Alloc&, in_place_index_t<_Np>,
_Args&&...)): Likewise.
(variant(allocator_arg_t, const _Alloc&, in_place_index_t<_Np>,
initializer_list<_Up>, _Args&&...)): Likewise.
(emplace(_Args&&...)): Likewise.
(emplace(initializer_list<_Up>, _Args&&...)): Likewise.
* testsuite/20_util/any/cons/explicit.cc: Likewise.
* testsuite/20_util/any/cons/in_place.cc: Likewise.
* testsuite/20_util/any/requirements.cc: Add tests to
check that any is not constructible from the new in_place_type_t
of any value category.
* testsuite/20_util/in_place/requirements.cc: Adjust to
use the new tag type.
* testsuite/20_util/variant/compile.cc: Likewise.
* testsuite/20_util/variant/run.cc: Likewise.
From-SVN: r242401
Diffstat (limited to 'libstdc++-v3/include/std')
-rw-r--r-- | libstdc++-v3/include/std/any | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/std/utility | 36 | ||||
-rw-r--r-- | libstdc++-v3/include/std/variant | 34 |
3 files changed, 40 insertions, 38 deletions
diff --git a/libstdc++-v3/include/std/any b/libstdc++-v3/include/std/any index 719e683..ded2bb2 100644 --- a/libstdc++-v3/include/std/any +++ b/libstdc++-v3/include/std/any @@ -179,7 +179,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template <typename _ValueType, typename _Tp = _Decay<_ValueType>, typename _Mgr = _Manager<_Tp>, __any_constructible_t<_Tp, _ValueType&&> = true, - enable_if_t<!__is_in_place_type<_ValueType>::value, bool> = true> + enable_if_t<!__is_in_place_type<_Tp>::value, bool> = true> any(_ValueType&& __value) : _M_manager(&_Mgr::_S_manage) { @@ -191,7 +191,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typename _Mgr = _Manager<_Tp>, enable_if_t<__and_<is_copy_constructible<_Tp>, __not_<is_constructible<_Tp, _ValueType&&>>, - __not_<__is_in_place_type<_ValueType>>>::value, + __not_<__is_in_place_type<_Tp>>>::value, bool> = false> any(_ValueType&& __value) : _M_manager(&_Mgr::_S_manage) @@ -423,14 +423,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template <typename _Tp, typename... _Args> any make_any(_Args&&... __args) { - return any(in_place<_Tp>, std::forward<_Args>(__args)...); + return any(in_place_type<_Tp>, std::forward<_Args>(__args)...); } /// Create an any holding a @c _Tp constructed from @c __il and @c __args. template <typename _Tp, typename _Up, typename... _Args> any make_any(initializer_list<_Up> __il, _Args&&... __args) { - return any(in_place<_Tp>, __il, std::forward<_Args>(__args)...); + return any(in_place_type<_Tp>, __il, std::forward<_Args>(__args)...); } /** diff --git a/libstdc++-v3/include/std/utility b/libstdc++-v3/include/std/utility index 6a6659b..2ca52fe 100644 --- a/libstdc++-v3/include/std/utility +++ b/libstdc++-v3/include/std/utility @@ -336,25 +336,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 201402L - struct in_place_tag { - in_place_tag() = delete; + struct in_place_t { + explicit in_place_t() = default; }; - struct __in_place; - template<typename _Tp> struct __in_place_type; - template<size_t _Idx> struct __in_place_index; - - using in_place_t = in_place_tag(&)(__in_place*); - template <class _Tp> - using in_place_type_t = in_place_tag(&)(__in_place_type<_Tp>*); - template <int _Idx> - using in_place_index_t = in_place_tag(&)(__in_place_index<_Idx>*); - - inline in_place_tag in_place(__in_place*) {terminate();} - template <class _Tp> - in_place_tag in_place(__in_place_type<_Tp>*) {terminate();} - template <size_t _Idx> - in_place_tag in_place(__in_place_index<_Idx>*) {terminate();} + inline constexpr in_place_t in_place{}; + + template<typename _Tp> struct in_place_type_t + { + explicit in_place_type_t() = default; + }; + + template<typename _Tp> + inline constexpr in_place_type_t<_Tp> in_place_type{}; + + template<size_t _Idx> struct in_place_index_t + { + explicit in_place_index_t() = default; + }; + + template<size_t _Idx> + inline constexpr in_place_index_t<_Idx> in_place_index{}; template<typename> struct __is_in_place_type_impl : false_type diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 314f5f2..0d5fa56 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -302,7 +302,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<size_t _Np, typename... _Args> constexpr _Variant_storage(in_place_index_t<_Np>, _Args&&... __args) - : _M_union(in_place<_Np>, std::forward<_Args>(__args)...) + : _M_union(in_place_index<_Np>, std::forward<_Args>(__args)...) { } ~_Variant_storage() = default; @@ -320,13 +320,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename... _Args> constexpr _Union(in_place_index_t<0>, _Args&&... __args) - : _M_first(in_place<0>, std::forward<_Args>(__args)...) + : _M_first(in_place_index<0>, std::forward<_Args>(__args)...) { } template<size_t _Np, typename... _Args, typename = enable_if_t<0 < _Np && _Np < sizeof...(_Rest) + 1>> constexpr _Union(in_place_index_t<_Np>, _Args&&... __args) - : _M_rest(in_place<_Np - 1>, std::forward<_Args>(__args)...) + : _M_rest(in_place_index<_Np - 1>, std::forward<_Args>(__args)...) { } _Uninitialized<__storage<_First>> _M_first; @@ -361,7 +361,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Variant_base() noexcept(is_nothrow_default_constructible_v< variant_alternative_t<0, variant<_Types...>>>) - : _Variant_base(in_place<0>) { } + : _Variant_base(in_place_index<0>) { } _Variant_base(const _Variant_base& __rhs) : _Storage(), _M_index(__rhs._M_index) @@ -1018,7 +1018,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr variant(_Tp&& __t) noexcept(is_nothrow_constructible_v<__accepted_type<_Tp&&>, _Tp&&>) - : variant(in_place<__accepted_index<_Tp&&>>, std::forward<_Tp>(__t)) + : variant(in_place_index<__accepted_index<_Tp&&>>, std::forward<_Tp>(__t)) { __glibcxx_assert(holds_alternative<__accepted_type<_Tp&&>>(*this)); } template<typename _Tp, typename... _Args, @@ -1026,7 +1026,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION && is_constructible_v<_Tp, _Args&&...>>> constexpr explicit variant(in_place_type_t<_Tp>, _Args&&... __args) - : variant(in_place<__index_of<_Tp>>, std::forward<_Args>(__args)...) + : variant(in_place_index<__index_of<_Tp>>, std::forward<_Args>(__args)...) { __glibcxx_assert(holds_alternative<_Tp>(*this)); } template<typename _Tp, typename _Up, typename... _Args, @@ -1036,7 +1036,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr explicit variant(in_place_type_t<_Tp>, initializer_list<_Up> __il, _Args&&... __args) - : variant(in_place<__index_of<_Tp>>, __il, + : variant(in_place_index<__index_of<_Tp>>, __il, std::forward<_Args>(__args)...) { __glibcxx_assert(holds_alternative<_Tp>(*this)); } @@ -1045,7 +1045,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION is_constructible_v<__to_type<_Np>, _Args&&...>>> constexpr explicit variant(in_place_index_t<_Np>, _Args&&... __args) - : _Base(in_place<_Np>, std::forward<_Args>(__args)...), + : _Base(in_place_index<_Np>, std::forward<_Args>(__args)...), _Default_ctor_enabler(_Enable_default_constructor_tag{}) { __glibcxx_assert(index() == _Np); } @@ -1055,7 +1055,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION constexpr explicit variant(in_place_index_t<_Np>, initializer_list<_Up> __il, _Args&&... __args) - : _Base(in_place<_Np>, __il, std::forward<_Args>(__args)...), + : _Base(in_place_index<_Np>, __il, std::forward<_Args>(__args)...), _Default_ctor_enabler(_Enable_default_constructor_tag{}) { __glibcxx_assert(index() == _Np); } @@ -1063,7 +1063,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typename = enable_if_t< __is_uses_allocator_constructible_v<__to_type<0>, _Alloc>>> variant(allocator_arg_t, const _Alloc& __a) - : variant(allocator_arg, __a, in_place<0>) + : variant(allocator_arg, __a, in_place_index<0>) { } template<typename _Alloc, @@ -1091,7 +1091,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __accepted_type<_Tp&&>, _Alloc, _Tp&&> && !is_same_v<decay_t<_Tp>, variant>, variant&>> variant(allocator_arg_t, const _Alloc& __a, _Tp&& __t) - : variant(allocator_arg, __a, in_place<__accepted_index<_Tp&&>>, + : variant(allocator_arg, __a, in_place_index<__accepted_index<_Tp&&>>, std::forward<_Tp>(__t)) { __glibcxx_assert(holds_alternative<__accepted_type<_Tp&&>>(*this)); } @@ -1102,7 +1102,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Tp, _Alloc, _Args&&...>>> variant(allocator_arg_t, const _Alloc& __a, in_place_type_t<_Tp>, _Args&&... __args) - : variant(allocator_arg, __a, in_place<__index_of<_Tp>>, + : variant(allocator_arg, __a, in_place_index<__index_of<_Tp>>, std::forward<_Args>(__args)...) { __glibcxx_assert(holds_alternative<_Tp>(*this)); } @@ -1113,7 +1113,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Tp, _Alloc, initializer_list<_Up>&, _Args&&...>>> variant(allocator_arg_t, const _Alloc& __a, in_place_type_t<_Tp>, initializer_list<_Up> __il, _Args&&... __args) - : variant(allocator_arg, __a, in_place<__index_of<_Tp>>, __il, + : variant(allocator_arg, __a, in_place_index<__index_of<_Tp>>, __il, std::forward<_Args>(__args)...) { __glibcxx_assert(holds_alternative<_Tp>(*this)); } @@ -1123,7 +1123,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __to_type<_Np>, _Alloc, _Args&&...>>> variant(allocator_arg_t, const _Alloc& __a, in_place_index_t<_Np>, _Args&&... __args) - : _Base(__a, in_place<_Np>, std::forward<_Args>(__args)...), + : _Base(__a, in_place_index<_Np>, std::forward<_Args>(__args)...), _Default_ctor_enabler(_Enable_default_constructor_tag{}) { __glibcxx_assert(index() == _Np); } @@ -1133,7 +1133,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __to_type<_Np>, _Alloc, initializer_list<_Up>&, _Args&&...>>> variant(allocator_arg_t, const _Alloc& __a, in_place_index_t<_Np>, initializer_list<_Up> __il, _Args&&... __args) - : _Base(__a, in_place<_Np>, __il, std::forward<_Args>(__args)...), + : _Base(__a, in_place_index<_Np>, __il, std::forward<_Args>(__args)...), _Default_ctor_enabler(_Enable_default_constructor_tag{}) { __glibcxx_assert(index() == _Np); } @@ -1188,7 +1188,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION this->~variant(); __try { - ::new (this) variant(in_place<_Np>, + ::new (this) variant(in_place_index<_Np>, std::forward<_Args>(__args)...); } __catch (...) @@ -1207,7 +1207,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION this->~variant(); __try { - ::new (this) variant(in_place<_Np>, __il, + ::new (this) variant(in_place_index<_Np>, __il, std::forward<_Args>(__args)...); } __catch (...) |