Home | History | Annotate | Download | only in set
      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 // <set>
     11 
     12 // class set
     13 
     14 // template <class... Args>
     15 //   pair<iterator, bool> emplace(Args&&... args);
     16 
     17 #include <set>
     18 #include <cassert>
     19 
     20 #include "../../Emplaceable.h"
     21 #include "../../DefaultOnly.h"
     22 
     23 int main()
     24 {
     25 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     26     {
     27         typedef std::set<DefaultOnly> M;
     28         typedef std::pair<M::iterator, bool> R;
     29         M m;
     30         assert(DefaultOnly::count == 0);
     31         R r = m.emplace();
     32         assert(r.second);
     33         assert(r.first == m.begin());
     34         assert(m.size() == 1);
     35         assert(*m.begin() == DefaultOnly());
     36         assert(DefaultOnly::count == 1);
     37 
     38         r = m.emplace();
     39         assert(!r.second);
     40         assert(r.first == m.begin());
     41         assert(m.size() == 1);
     42         assert(*m.begin() == DefaultOnly());
     43         assert(DefaultOnly::count == 1);
     44     }
     45     assert(DefaultOnly::count == 0);
     46     {
     47         typedef std::set<Emplaceable> M;
     48         typedef std::pair<M::iterator, bool> R;
     49         M m;
     50         R r = m.emplace();
     51         assert(r.second);
     52         assert(r.first == m.begin());
     53         assert(m.size() == 1);
     54         assert(*m.begin() == Emplaceable());
     55         r = m.emplace(2, 3.5);
     56         assert(r.second);
     57         assert(r.first == next(m.begin()));
     58         assert(m.size() == 2);
     59         assert(*r.first == Emplaceable(2, 3.5));
     60         r = m.emplace(2, 3.5);
     61         assert(!r.second);
     62         assert(r.first == next(m.begin()));
     63         assert(m.size() == 2);
     64         assert(*r.first == Emplaceable(2, 3.5));
     65     }
     66     {
     67         typedef std::set<int> M;
     68         typedef std::pair<M::iterator, bool> R;
     69         M m;
     70         R r = m.emplace(M::value_type(2));
     71         assert(r.second);
     72         assert(r.first == m.begin());
     73         assert(m.size() == 1);
     74         assert(*r.first == 2);
     75     }
     76 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     77 }
     78