Home | History | Annotate | Download | only in priqueue.cons.alloc
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <queue>
     11 
     12 // template <class Alloc>
     13 //     priority_queue(const Compare& comp, const container_type& c,
     14 //                    const Alloc& a);
     15 
     16 #include <queue>
     17 #include <cassert>
     18 
     19 #include "test_macros.h"
     20 #include "test_allocator.h"
     21 
     22 template <class C>
     23 C
     24 make(int n)
     25 {
     26     C c;
     27     for (int i = 0; i < n; ++i)
     28         c.push_back(i);
     29     return c;
     30 }
     31 
     32 template <class T>
     33 struct test
     34     : public std::priority_queue<T, std::vector<T, test_allocator<T> > >
     35 {
     36     typedef std::priority_queue<T, std::vector<T, test_allocator<T> > > base;
     37     typedef typename base::container_type container_type;
     38     typedef typename base::value_compare value_compare;
     39 
     40     explicit test(const test_allocator<int>& a) : base(a) {}
     41     test(const value_compare& comp, const test_allocator<int>& a)
     42         : base(comp, a) {}
     43     test(const value_compare& comp, const container_type& c,
     44         const test_allocator<int>& a) : base(comp, c, a) {}
     45 #if TEST_STD_VER >= 11 // testing rvalue constructor
     46     test(const value_compare& comp, container_type&& c,
     47          const test_allocator<int>& a) : base(comp, std::move(c), a) {}
     48     test(test&& q, const test_allocator<int>& a) : base(std::move(q), a) {}
     49 #endif
     50     test_allocator<int> get_allocator() {return c.get_allocator();}
     51 
     52     using base::c;
     53 };
     54 
     55 int main()
     56 {
     57     typedef std::vector<int, test_allocator<int> > C;
     58     C v = make<C>(5);
     59     test<int> q(std::less<int>(), v, test_allocator<int>(3));
     60     assert(q.c.get_allocator() == test_allocator<int>(3));
     61     assert(q.size() == 5);
     62     assert(q.top() == 4);
     63 }
     64