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