aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2015-09-11 10:51:29 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2015-09-11 10:51:29 +0100
commit997ed914e2c1ca4083affd78fd22569f5e734d08 (patch)
treeb4f480f65886207a7d569f6ddc85da53a5702d68
parent09fcd8e1491fa20f45b546144e18e201458e925d (diff)
downloadgcc-997ed914e2c1ca4083affd78fd22569f5e734d08.zip
gcc-997ed914e2c1ca4083affd78fd22569f5e734d08.tar.gz
gcc-997ed914e2c1ca4083affd78fd22569f5e734d08.tar.bz2
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
-rw-r--r--libstdc++-v3/ChangeLog13
-rw-r--r--libstdc++-v3/include/bits/stl_queue.h59
-rw-r--r--libstdc++-v3/include/bits/stl_stack.h27
-rw-r--r--libstdc++-v3/testsuite/23_containers/priority_queue/requirements/uses_allocator.cc45
-rw-r--r--libstdc++-v3/testsuite/23_containers/queue/requirements/uses_allocator.cc37
-rw-r--r--libstdc++-v3/testsuite/23_containers/stack/requirements/uses_allocator.cc37
6 files changed, 212 insertions, 6 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 8516782c..c4505fd 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,16 @@
+2015-09-11 Jonathan Wakely <jwakely@redhat.com>
+
+ 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 <jwakely@redhat.com>
* 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 5f8e6fb..f7e5e30 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<typename _Alloc>
+ using _Uses = typename
+ enable_if<uses_allocator<_Sequence, _Alloc>::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<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ explicit
+ queue(const _Alloc& __a)
+ : c(__a) { }
+
+ template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ queue(const _Sequence& __c, const _Alloc& __a)
+ : c(__c, __a) { }
+
+ template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ queue(_Sequence&& __c, const _Alloc& __a)
+ : c(std::move(__c), __a) { }
+
+ template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ queue(const queue& __q, const _Alloc& __a)
+ : c(__q.c, __a) { }
+
+ template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ 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<typename _Alloc>
+ using _Uses = typename
+ enable_if<uses_allocator<_Sequence, _Alloc>::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<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ explicit
+ priority_queue(const _Alloc& __a)
+ : c(__a) { }
+
+ template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ priority_queue(const _Compare& __x, const _Alloc& __a)
+ : c(__x, __a) { }
+
+ template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ priority_queue(const _Compare& __x, const _Sequence& __c,
+ const _Alloc& __a)
+ : c(__x, __c, __a) { }
+
+ template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ priority_queue(const _Compare& __x, _Sequence&& __c, const _Alloc& __a)
+ : c(__x, std::move(__c), __a) { }
+
+ template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ priority_queue(const priority_queue& __q, const _Alloc& __a)
+ : c(__q.c, __a) { }
+
+ template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ 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 09dd611..0b54d1a 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<typename _Alloc>
+ using _Uses = typename
+ enable_if<uses_allocator<_Sequence, _Alloc>::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<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ explicit
+ stack(const _Alloc& __a)
+ : c(__a) { }
+
+ template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ stack(const _Sequence& __c, const _Alloc& __a)
+ : c(__c, __a) { }
+
+ template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ stack(_Sequence&& __c, const _Alloc& __a)
+ : c(std::move(__c), __a) { }
+
+ template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ stack(const stack& __q, const _Alloc& __a)
+ : c(__q.c, __a) { }
+
+ template<typename _Alloc, typename _Requires = _Uses<_Alloc>>
+ 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 75729ff..9419ac8 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 <queue>
+using test_type = std::priority_queue<int>;
+using container = test_type::container_type;
+using comp = std::less<container::value_type>;
+
template<typename A>
- using uses_allocator = std::uses_allocator<std::priority_queue<int>, A>;
+ using uses_allocator = std::uses_allocator<test_type, A>;
+
+template<typename... Args>
+ using is_constructible = std::is_constructible<test_type, Args...>;
+
+// test with invalid allocator
+using alloc_type = container::allocator_type;
-static_assert( uses_allocator<std::allocator<int>>::value, "valid allocator" );
+static_assert( uses_allocator<alloc_type>::value, "valid allocator" );
+static_assert( is_constructible<const alloc_type&>::value,
+ "priority_queue(const Alloc&)" );
+static_assert( is_constructible<const comp&, const alloc_type&>::value,
+ "priority_queue(const Cmp&, const Alloc&)" );
+static_assert( is_constructible<const comp&, const container&,
+ const alloc_type&>::value,
+ "priority_queue(const Cmp&, const Container&, const Alloc&)" );
+static_assert( is_constructible<const comp&, container&&,
+ const alloc_type&>::value,
+ "priority_queue(const Cmp&, const Container&, const Alloc&)" );
+static_assert( is_constructible<const test_type&, const alloc_type&>::value,
+ "priority_queue(const priority_queue&, const Alloc&)" );
+static_assert( is_constructible<test_type&&, const alloc_type&>::value,
+ "priority_queue(const priority_queue&, const Alloc&)" );
+
+// test with invalid allocator
struct X { };
+
static_assert( !uses_allocator<X>::value, "invalid allocator" );
+
+static_assert( !is_constructible<const X&>::value,
+ "priority_queue(const NonAlloc&)" );
+static_assert( !is_constructible<const comp&, const X&>::value,
+ "priority_queue(const Cmp&, const NonAlloc&)" );
+static_assert( !is_constructible<const comp&, const container&,
+ const X&>::value,
+ "priority_queue(const Cmp&, const Cont&, const NonAlloc&)" );
+static_assert( !is_constructible<const comp&, container&&, const X&>::value,
+ "priority_queue(const Cmp&, const Cont&, const NonAlloc&)" );
+static_assert( !is_constructible<const test_type&, const X&>::value,
+ "priority_queue(const priority_queue&, const NonAlloc&)" );
+static_assert( !is_constructible<test_type&&, const X&>::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 714cb9e..6eb107e 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 <queue>
+using test_type = std::queue<int>;
+using container = test_type::container_type;
+
template<typename A>
- using uses_allocator = std::uses_allocator<std::queue<int>, A>;
+ using uses_allocator = std::uses_allocator<test_type, A>;
+
+template<typename... Args>
+ using is_constructible = std::is_constructible<test_type, Args...>;
+
+// test with valid allocator
+using alloc_type = container::allocator_type;
-static_assert( uses_allocator<std::allocator<int>>::value, "valid allocator" );
+static_assert( uses_allocator<alloc_type>::value, "valid allocator" );
+static_assert( is_constructible<const alloc_type&>::value,
+ "queue(const Alloc&)" );
+static_assert( is_constructible<const container&, const alloc_type&>::value,
+ "queue(const container_type&, const Alloc&)" );
+static_assert( is_constructible<container&&, const alloc_type&>::value,
+ "queue(const container_type&, const Alloc&)" );
+static_assert( is_constructible<const test_type&, const alloc_type&>::value,
+ "queue(const queue&, const Alloc&)" );
+static_assert( is_constructible<test_type&&, const alloc_type&>::value,
+ "queue(const queue&, const Alloc&)" );
+
+// test with invalid allocator
struct X { };
+
static_assert( !uses_allocator<X>::value, "invalid allocator" );
+
+static_assert( !is_constructible<const X&>::value,
+ "queue(const NonAlloc&)" );
+static_assert( !is_constructible<const container&, const X&>::value,
+ "queue(const container_type&, const NonAlloc&)" );
+static_assert( !is_constructible<container&&, const X&>::value,
+ "queue(const container_type&, const NonAlloc&)" );
+static_assert( !is_constructible<const test_type&, const X&>::value,
+ "queue(const queue&, const NonAlloc&)" );
+static_assert( !is_constructible<test_type&&, const X&>::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 ab8990f..9141608 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 <stack>
+using test_type = std::stack<int>;
+using container = test_type::container_type;
+
template<typename A>
- using uses_allocator = std::uses_allocator<std::stack<int>, A>;
+ using uses_allocator = std::uses_allocator<test_type, A>;
+
+template<typename... Args>
+ using is_constructible = std::is_constructible<test_type, Args...>;
+
+// test with valid allocator
+using alloc_type = container::allocator_type;
-static_assert( uses_allocator<std::allocator<int>>::value, "valid allocator" );
+static_assert( uses_allocator<alloc_type>::value, "valid allocator" );
+static_assert( is_constructible<const alloc_type&>::value,
+ "stack(const Alloc&)" );
+static_assert( is_constructible<const container&, const alloc_type&>::value,
+ "stack(const container_type&, const Alloc&)" );
+static_assert( is_constructible<container&&, const alloc_type&>::value,
+ "stack(const container_type&, const Alloc&)" );
+static_assert( is_constructible<const test_type&, const alloc_type&>::value,
+ "stack(const stack&, const Alloc&)" );
+static_assert( is_constructible<test_type&&, const alloc_type&>::value,
+ "stack(const stack&, const Alloc&)" );
+
+// test with invalid allocator
struct X { };
+
static_assert( !uses_allocator<X>::value, "invalid allocator" );
+
+static_assert( !is_constructible<const X&>::value,
+ "stack(const NonAlloc&)" );
+static_assert( !is_constructible<const container&, const X&>::value,
+ "stack(const container_type&, const NonAlloc&)" );
+static_assert( !is_constructible<container&&, const X&>::value,
+ "stack(const container_type&, const NonAlloc&)" );
+static_assert( !is_constructible<const test_type&, const X&>::value,
+ "stack(const stack&, const NonAlloc&)" );
+static_assert( !is_constructible<test_type&&, const X&>::value,
+ "stack(const stack&, const NonAlloc&)" );