Allocator-extended constructors for container adaptors.
authorJonathan Wakely <jwakely@redhat.com>
Fri, 11 Sep 2015 09:51:29 +0000 (10:51 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Fri, 11 Sep 2015 09:51:29 +0000 (10:51 +0100)
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

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/stl_queue.h
libstdc++-v3/include/bits/stl_stack.h
libstdc++-v3/testsuite/23_containers/priority_queue/requirements/uses_allocator.cc
libstdc++-v3/testsuite/23_containers/queue/requirements/uses_allocator.cc
libstdc++-v3/testsuite/23_containers/stack/requirements/uses_allocator.cc

index 8516782..c4505fd 100644 (file)
@@ -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.
index 5f8e6fb..f7e5e30 100644 (file)
@@ -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
 
       /**
index 09dd611..0b54d1a 100644 (file)
@@ -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
 
       /**
index 75729ff..9419ac8 100644 (file)
 
 #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&)" );
index 714cb9e..6eb107e 100644 (file)
 
 #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&)" );
index ab8990f..9141608 100644 (file)
 
 #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&)" );