Commit 197c757c by Tim Shen Committed by Tim Shen

Implement <variant>

	* include/Makefile.am: Add new file std/variant.
	* include/Makefile.in: Generated from Makefile.am.
	* include/bits/enable_special_members.h: Add a tag type to allow
	the construction in non-default constructor.
	* include/bits/uses_allocator.h: Add convenience traits to
	detect constructibility.
	* include/std/variant: Implement <variant>.
	* testsuite/20_util/variant/compile.cc: Compile-time tests.
	* testsuite/20_util/variant/run.cc: Runtime tests.

From-SVN: r239590
parent cc015f3a
2016-08-18 Tim Shen <timshen@google.com>
Implement <variant>
* include/Makefile.am: Add new file std/variant.
* include/Makefile.in: Generated from Makefile.am.
* include/bits/enable_special_members.h: Add a tag type to allow
the construction in non-default constructor.
* include/bits/uses_allocator.h: Add convenience traits to
detect constructibility.
* include/std/variant: Implement <variant>.
* testsuite/20_util/variant/compile.cc: Compile-time tests.
* testsuite/20_util/variant/run.cc: Runtime tests.
2016-08-18 Jonathan Wakely <jwakely@redhat.com> 2016-08-18 Jonathan Wakely <jwakely@redhat.com>
* doc/xml/manual/test.xml (test.run.permutations): Expand section. * doc/xml/manual/test.xml (test.run.permutations): Expand section.
......
...@@ -77,6 +77,7 @@ std_headers = \ ...@@ -77,6 +77,7 @@ std_headers = \
${std_srcdir}/unordered_set \ ${std_srcdir}/unordered_set \
${std_srcdir}/utility \ ${std_srcdir}/utility \
${std_srcdir}/valarray \ ${std_srcdir}/valarray \
${std_srcdir}/variant \
${std_srcdir}/vector ${std_srcdir}/vector
bits_srcdir = ${glibcxx_srcdir}/include/bits bits_srcdir = ${glibcxx_srcdir}/include/bits
......
...@@ -367,6 +367,7 @@ std_headers = \ ...@@ -367,6 +367,7 @@ std_headers = \
${std_srcdir}/unordered_set \ ${std_srcdir}/unordered_set \
${std_srcdir}/utility \ ${std_srcdir}/utility \
${std_srcdir}/valarray \ ${std_srcdir}/valarray \
${std_srcdir}/variant \
${std_srcdir}/vector ${std_srcdir}/vector
bits_srcdir = ${glibcxx_srcdir}/include/bits bits_srcdir = ${glibcxx_srcdir}/include/bits
......
...@@ -36,13 +36,33 @@ namespace std _GLIBCXX_VISIBILITY(default) ...@@ -36,13 +36,33 @@ namespace std _GLIBCXX_VISIBILITY(default)
{ {
_GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_BEGIN_NAMESPACE_VERSION
struct _Enable_default_constructor_tag
{
explicit _Enable_default_constructor_tag() = default;
};
/** /**
* @brief A mixin helper to conditionally enable or disable the default * @brief A mixin helper to conditionally enable or disable the default
* constructor. * constructor.
* @sa _Enable_special_members * @sa _Enable_special_members
*/ */
template<bool _Switch, typename _Tag = void> template<bool _Switch, typename _Tag = void>
struct _Enable_default_constructor { }; struct _Enable_default_constructor
{
constexpr _Enable_default_constructor() noexcept = default;
constexpr _Enable_default_constructor(_Enable_default_constructor const&)
noexcept = default;
constexpr _Enable_default_constructor(_Enable_default_constructor&&)
noexcept = default;
_Enable_default_constructor&
operator=(_Enable_default_constructor const&) noexcept = default;
_Enable_default_constructor&
operator=(_Enable_default_constructor&&) noexcept = default;
// Can be used in other ctors.
constexpr explicit
_Enable_default_constructor(_Enable_default_constructor_tag) { }
};
/** /**
...@@ -86,7 +106,20 @@ template<bool _Default, bool _Destructor, ...@@ -86,7 +106,20 @@ template<bool _Default, bool _Destructor,
template<typename _Tag> template<typename _Tag>
struct _Enable_default_constructor<false, _Tag> struct _Enable_default_constructor<false, _Tag>
{ constexpr _Enable_default_constructor() noexcept = delete; }; {
constexpr _Enable_default_constructor() noexcept = delete;
constexpr _Enable_default_constructor(_Enable_default_constructor const&)
noexcept = default;
constexpr _Enable_default_constructor(_Enable_default_constructor&&)
noexcept = default;
_Enable_default_constructor&
operator=(_Enable_default_constructor const&) noexcept = default;
_Enable_default_constructor&
operator=(_Enable_default_constructor&&) noexcept = default;
// Can be used in other ctors.
explicit _Enable_default_constructor(_Enable_default_constructor_tag) { }
};
template<typename _Tag> template<typename _Tag>
struct _Enable_destructor<false, _Tag> struct _Enable_destructor<false, _Tag>
......
...@@ -113,6 +113,57 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION ...@@ -113,6 +113,57 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr bool uses_allocator_v = uses_allocator<_Tp, _Alloc>::value; constexpr bool uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
#endif // C++17 #endif // C++17
template<template<typename...> class _Predicate,
typename _Tp, typename _Alloc, typename... _Args>
struct __is_uses_allocator_predicate
: conditional<uses_allocator<_Tp, _Alloc>::value,
__or_<_Predicate<_Tp, allocator_arg_t, _Alloc, _Args...>,
_Predicate<_Tp, _Args..., _Alloc>>,
_Predicate<_Tp, _Args...>>::type { };
template<typename _Tp, typename _Alloc, typename... _Args>
struct __is_uses_allocator_constructible
: __is_uses_allocator_predicate<is_constructible, _Tp, _Alloc, _Args...>
{ };
template<typename _Tp, typename _Alloc, typename... _Args>
constexpr bool __is_uses_allocator_constructible_v =
__is_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
template<typename _Tp, typename _Alloc, typename... _Args>
struct __is_nothrow_uses_allocator_constructible
: __is_uses_allocator_predicate<is_nothrow_constructible,
_Tp, _Alloc, _Args...>
{ };
template<typename _Tp, typename _Alloc, typename... _Args>
constexpr bool __is_nothrow_uses_allocator_constructible_v =
__is_nothrow_uses_allocator_constructible<_Tp, _Alloc, _Args...>::value;
template<typename _Tp, typename... _Args>
void __uses_allocator_construct_impl(__uses_alloc0 __a, _Tp* __ptr,
_Args&&... __args)
{ new (__ptr) _Tp(forward<_Args>(__args)...); }
template<typename _Tp, typename _Alloc, typename... _Args>
void __uses_allocator_construct_impl(__uses_alloc1<_Alloc> __a, _Tp* __ptr,
_Args&&... __args)
{ new (__ptr) _Tp(allocator_arg, *__a._M_a, forward<_Args>(__args)...); }
template<typename _Tp, typename _Alloc, typename... _Args>
void __uses_allocator_construct_impl(__uses_alloc2<_Alloc> __a, _Tp* __ptr,
_Args&&... __args)
{ new (__ptr) _Tp(forward<_Args>(__args)..., *__a._M_a); }
template<typename _Tp, typename _Alloc, typename... _Args>
void __uses_allocator_construct(const _Alloc& __a, _Tp* __ptr,
_Args&&... __args)
{
__uses_allocator_construct_impl(__use_alloc<_Tp, _Alloc, _Args...>(__a),
__ptr, forward<_Args>(__args)...);
}
_GLIBCXX_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
} // namespace std } // namespace std
......
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