From: Jonathan Wakely Date: Fri, 11 Sep 2015 09:51:29 +0000 (+0100) Subject: Allocator-extended constructors for container adaptors. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=997ed914e2c1ca4083affd78fd22569f5e734d08;p=gcc.git Allocator-extended constructors for container adaptors. PR libstdc++/65092 * include/bits/stl_queue.h (queue, priority_queue): Add allocator-extended constructors. * include/bits/stl_stack.h (stack): Likewise. * testsuite/23_containers/priority_queue/requirements/ uses_allocator.cc: Test allocator-extended constructors. * testsuite/23_containers/queue/requirements/uses_allocator.cc: Likewise. * testsuite/23_containers/stack/requirements/uses_allocator.cc: Likewise. From-SVN: r227680 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 8516782cf58..c4505fd05f0 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2015-09-11 Jonathan Wakely + + PR libstdc++/65092 + * include/bits/stl_queue.h (queue, priority_queue): Add + allocator-extended constructors. + * include/bits/stl_stack.h (stack): Likewise. + * testsuite/23_containers/priority_queue/requirements/ + uses_allocator.cc: Test allocator-extended constructors. + * testsuite/23_containers/queue/requirements/uses_allocator.cc: + Likewise. + * testsuite/23_containers/stack/requirements/uses_allocator.cc: + Likewise. + 2015-09-10 Jonathan Wakely * testsuite/util/testsuite_allocator.h (PointerBase::operator[]): Add. diff --git a/libstdc++-v3/include/bits/stl_queue.h b/libstdc++-v3/include/bits/stl_queue.h index 5f8e6fb9ab1..f7e5e300d7b 100644 --- a/libstdc++-v3/include/bits/stl_queue.h +++ b/libstdc++-v3/include/bits/stl_queue.h @@ -110,6 +110,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION friend bool operator<(const queue<_Tp1, _Seq1>&, const queue<_Tp1, _Seq1>&); +#if __cplusplus >= 201103L + template + using _Uses = typename + enable_if::value>::type; +#endif + public: typedef typename _Sequence::value_type value_type; typedef typename _Sequence::reference reference; @@ -144,6 +150,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION explicit queue(_Sequence&& __c = _Sequence()) : c(std::move(__c)) { } + + template> + explicit + queue(const _Alloc& __a) + : c(__a) { } + + template> + queue(const _Sequence& __c, const _Alloc& __a) + : c(__c, __a) { } + + template> + queue(_Sequence&& __c, const _Alloc& __a) + : c(std::move(__c), __a) { } + + template> + queue(const queue& __q, const _Alloc& __a) + : c(__q.c, __a) { } + + template> + queue(queue&& __q, const _Alloc& __a) + : c(std::move(__q.c), __a) { } #endif /** @@ -378,6 +405,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION __glibcxx_class_requires4(_Compare, bool, _Tp, _Tp, _BinaryFunctionConcept) +#if __cplusplus >= 201103L + template + using _Uses = typename + enable_if::value>::type; +#endif + public: typedef typename _Sequence::value_type value_type; typedef typename _Sequence::reference reference; @@ -412,6 +445,32 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Sequence&& __s = _Sequence()) : c(std::move(__s)), comp(__x) { std::make_heap(c.begin(), c.end(), comp); } + + template> + explicit + priority_queue(const _Alloc& __a) + : c(__a) { } + + template> + priority_queue(const _Compare& __x, const _Alloc& __a) + : c(__x, __a) { } + + template> + priority_queue(const _Compare& __x, const _Sequence& __c, + const _Alloc& __a) + : c(__x, __c, __a) { } + + template> + priority_queue(const _Compare& __x, _Sequence&& __c, const _Alloc& __a) + : c(__x, std::move(__c), __a) { } + + template> + priority_queue(const priority_queue& __q, const _Alloc& __a) + : c(__q.c, __a) { } + + template> + priority_queue(priority_queue&& __q, const _Alloc& __a) + : c(std::move(__q.c), __a) { } #endif /** diff --git a/libstdc++-v3/include/bits/stl_stack.h b/libstdc++-v3/include/bits/stl_stack.h index 09dd6118a7a..0b54d1a6376 100644 --- a/libstdc++-v3/include/bits/stl_stack.h +++ b/libstdc++-v3/include/bits/stl_stack.h @@ -114,6 +114,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION friend bool operator<(const stack<_Tp1, _Seq1>&, const stack<_Tp1, _Seq1>&); +#if __cplusplus >= 201103L + template + using _Uses = typename + enable_if::value>::type; +#endif + public: typedef typename _Sequence::value_type value_type; typedef typename _Sequence::reference reference; @@ -142,6 +148,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION explicit stack(_Sequence&& __c = _Sequence()) : c(std::move(__c)) { } + + template> + explicit + stack(const _Alloc& __a) + : c(__a) { } + + template> + stack(const _Sequence& __c, const _Alloc& __a) + : c(__c, __a) { } + + template> + stack(_Sequence&& __c, const _Alloc& __a) + : c(std::move(__c), __a) { } + + template> + stack(const stack& __q, const _Alloc& __a) + : c(__q.c, __a) { } + + template> + stack(stack&& __q, const _Alloc& __a) + : c(std::move(__q.c), __a) { } #endif /** diff --git a/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/uses_allocator.cc b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/uses_allocator.cc index 75729ffab1a..9419ac8d023 100644 --- a/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/uses_allocator.cc +++ b/libstdc++-v3/testsuite/23_containers/priority_queue/requirements/uses_allocator.cc @@ -20,10 +20,51 @@ #include +using test_type = std::priority_queue; +using container = test_type::container_type; +using comp = std::less; + template - using uses_allocator = std::uses_allocator, A>; + using uses_allocator = std::uses_allocator; + +template + using is_constructible = std::is_constructible; + +// test with invalid allocator +using alloc_type = container::allocator_type; -static_assert( uses_allocator>::value, "valid allocator" ); +static_assert( uses_allocator::value, "valid allocator" ); +static_assert( is_constructible::value, + "priority_queue(const Alloc&)" ); +static_assert( is_constructible::value, + "priority_queue(const Cmp&, const Alloc&)" ); +static_assert( is_constructible::value, + "priority_queue(const Cmp&, const Container&, const Alloc&)" ); +static_assert( is_constructible::value, + "priority_queue(const Cmp&, const Container&, const Alloc&)" ); +static_assert( is_constructible::value, + "priority_queue(const priority_queue&, const Alloc&)" ); +static_assert( is_constructible::value, + "priority_queue(const priority_queue&, const Alloc&)" ); + +// test with invalid allocator struct X { }; + static_assert( !uses_allocator::value, "invalid allocator" ); + +static_assert( !is_constructible::value, + "priority_queue(const NonAlloc&)" ); +static_assert( !is_constructible::value, + "priority_queue(const Cmp&, const NonAlloc&)" ); +static_assert( !is_constructible::value, + "priority_queue(const Cmp&, const Cont&, const NonAlloc&)" ); +static_assert( !is_constructible::value, + "priority_queue(const Cmp&, const Cont&, const NonAlloc&)" ); +static_assert( !is_constructible::value, + "priority_queue(const priority_queue&, const NonAlloc&)" ); +static_assert( !is_constructible::value, + "priority_queue(const priority_queue&, const NonAlloc&)" ); diff --git a/libstdc++-v3/testsuite/23_containers/queue/requirements/uses_allocator.cc b/libstdc++-v3/testsuite/23_containers/queue/requirements/uses_allocator.cc index 714cb9ee090..6eb107e0ce8 100644 --- a/libstdc++-v3/testsuite/23_containers/queue/requirements/uses_allocator.cc +++ b/libstdc++-v3/testsuite/23_containers/queue/requirements/uses_allocator.cc @@ -20,10 +20,43 @@ #include +using test_type = std::queue; +using container = test_type::container_type; + template - using uses_allocator = std::uses_allocator, A>; + using uses_allocator = std::uses_allocator; + +template + using is_constructible = std::is_constructible; + +// test with valid allocator +using alloc_type = container::allocator_type; -static_assert( uses_allocator>::value, "valid allocator" ); +static_assert( uses_allocator::value, "valid allocator" ); +static_assert( is_constructible::value, + "queue(const Alloc&)" ); +static_assert( is_constructible::value, + "queue(const container_type&, const Alloc&)" ); +static_assert( is_constructible::value, + "queue(const container_type&, const Alloc&)" ); +static_assert( is_constructible::value, + "queue(const queue&, const Alloc&)" ); +static_assert( is_constructible::value, + "queue(const queue&, const Alloc&)" ); + +// test with invalid allocator struct X { }; + static_assert( !uses_allocator::value, "invalid allocator" ); + +static_assert( !is_constructible::value, + "queue(const NonAlloc&)" ); +static_assert( !is_constructible::value, + "queue(const container_type&, const NonAlloc&)" ); +static_assert( !is_constructible::value, + "queue(const container_type&, const NonAlloc&)" ); +static_assert( !is_constructible::value, + "queue(const queue&, const NonAlloc&)" ); +static_assert( !is_constructible::value, + "queue(const queue&, const NonAlloc&)" ); diff --git a/libstdc++-v3/testsuite/23_containers/stack/requirements/uses_allocator.cc b/libstdc++-v3/testsuite/23_containers/stack/requirements/uses_allocator.cc index ab8990f088b..91416083fc5 100644 --- a/libstdc++-v3/testsuite/23_containers/stack/requirements/uses_allocator.cc +++ b/libstdc++-v3/testsuite/23_containers/stack/requirements/uses_allocator.cc @@ -20,10 +20,43 @@ #include +using test_type = std::stack; +using container = test_type::container_type; + template - using uses_allocator = std::uses_allocator, A>; + using uses_allocator = std::uses_allocator; + +template + using is_constructible = std::is_constructible; + +// test with valid allocator +using alloc_type = container::allocator_type; -static_assert( uses_allocator>::value, "valid allocator" ); +static_assert( uses_allocator::value, "valid allocator" ); +static_assert( is_constructible::value, + "stack(const Alloc&)" ); +static_assert( is_constructible::value, + "stack(const container_type&, const Alloc&)" ); +static_assert( is_constructible::value, + "stack(const container_type&, const Alloc&)" ); +static_assert( is_constructible::value, + "stack(const stack&, const Alloc&)" ); +static_assert( is_constructible::value, + "stack(const stack&, const Alloc&)" ); + +// test with invalid allocator struct X { }; + static_assert( !uses_allocator::value, "invalid allocator" ); + +static_assert( !is_constructible::value, + "stack(const NonAlloc&)" ); +static_assert( !is_constructible::value, + "stack(const container_type&, const NonAlloc&)" ); +static_assert( !is_constructible::value, + "stack(const container_type&, const NonAlloc&)" ); +static_assert( !is_constructible::value, + "stack(const stack&, const NonAlloc&)" ); +static_assert( !is_constructible::value, + "stack(const stack&, const NonAlloc&)" );