Home | History | Annotate | Download | only in queue.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 // UNSUPPORTED: c++98, c++03
     11 
     12 // <queue>
     13 
     14 // template <class Alloc>
     15 //   queue(queue&& q, const Alloc& a);
     16 
     17 #include <queue>
     18 #include <cassert>
     19 
     20 #include "test_allocator.h"
     21 #include "MoveOnly.h"
     22 
     23 
     24 template <class C>
     25 C
     26 make(int n)
     27 {
     28     C c;
     29     for (int i = 0; i < n; ++i)
     30         c.push_back(MoveOnly(i));
     31     return c;
     32 }
     33 
     34 typedef std::deque<MoveOnly, test_allocator<MoveOnly> > C;
     35 
     36 template <class T>
     37 struct test
     38     : public std::queue<T, C>
     39 {
     40     typedef std::queue<T, C> base;
     41     typedef test_allocator<MoveOnly>      allocator_type;
     42     typedef typename base::container_type container_type;
     43 
     44     explicit test(const allocator_type& a) : base(a) {}
     45     test(const container_type& c, const allocator_type& a) : base(c, a) {}
     46     test(container_type&& c, const allocator_type& a) : base(std::move(c), a) {}
     47     test(test&& q, const allocator_type& a) : base(std::move(q), a) {}
     48     allocator_type get_allocator() {return this->c.get_allocator();}
     49 };
     50 
     51 
     52 int main()
     53 {
     54     test<MoveOnly> q(make<C>(5), test_allocator<MoveOnly>(4));
     55     test<MoveOnly> q2(std::move(q), test_allocator<MoveOnly>(5));
     56     assert(q2.get_allocator() == test_allocator<MoveOnly>(5));
     57     assert(q2.size() == 5);
     58 }
     59