+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.
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;
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
/**
__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;
_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
/**
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;
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
/**
#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&)" );
#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&)" );
#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&)" );