This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] libstdc++/65092 Allocator-extended constructors for container adaptors.


These should have been added as part of finishing C++11 support but I
missed them.

Now we have even more constructors to slow down compilation, yay
allocators.

Tested powerpc64le-linux, commtted to trunk.



commit 0a8e02d699f4fe30e44678eb7cbd08bb6c6aed97
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Sep 11 10:19:43 2015 +0100

    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.

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>;
 
-static_assert( uses_allocator<std::allocator<int>>::value, "valid allocator" );
+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<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>;
 
-static_assert( uses_allocator<std::allocator<int>>::value, "valid allocator" );
+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<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>;
 
-static_assert( uses_allocator<std::allocator<int>>::value, "valid allocator" );
+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<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&)" );

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]