Home | History | Annotate | Download | only in list.modifiers
      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 // <list>
     11 
     12 // template <class... Args> void emplace_front(Args&&... args);
     13 
     14 #include <list>
     15 #include <cassert>
     16 
     17 #include "min_allocator.h"
     18 
     19 class A
     20 {
     21     int i_;
     22     double d_;
     23 
     24     A(const A&);
     25     A& operator=(const A&);
     26 public:
     27     A(int i, double d)
     28         : i_(i), d_(d) {}
     29 
     30     int geti() const {return i_;}
     31     double getd() const {return d_;}
     32 };
     33 
     34 int main()
     35 {
     36 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     37     {
     38     std::list<A> c;
     39     c.emplace_front(2, 3.5);
     40     assert(c.size() == 1);
     41     assert(c.front().geti() == 2);
     42     assert(c.front().getd() == 3.5);
     43     c.emplace_front(3, 4.5);
     44     assert(c.size() == 2);
     45     assert(c.front().geti() == 3);
     46     assert(c.front().getd() == 4.5);
     47     assert(c.back().geti() == 2);
     48     assert(c.back().getd() == 3.5);
     49     }
     50 #if __cplusplus >= 201103L
     51     {
     52     std::list<A, min_allocator<A>> c;
     53     c.emplace_front(2, 3.5);
     54     assert(c.size() == 1);
     55     assert(c.front().geti() == 2);
     56     assert(c.front().getd() == 3.5);
     57     c.emplace_front(3, 4.5);
     58     assert(c.size() == 2);
     59     assert(c.front().geti() == 3);
     60     assert(c.front().getd() == 4.5);
     61     assert(c.back().geti() == 2);
     62     assert(c.back().getd() == 3.5);
     63     }
     64 #endif
     65 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     66 }
     67