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 // UNSUPPORTED: c++98, c++03
     11 
     12 // <set>
     13 
     14 // class set
     15 
     16 // template <class... Args>
     17 //   iterator emplace_hint(const_iterator position, Args&&... args);
     18 
     19 #include <set>
     20 #include <cassert>
     21 
     22 #include "../../Emplaceable.h"
     23 #include "DefaultOnly.h"
     24 #include "min_allocator.h"
     25 
     26 int main()
     27 {
     28     {
     29         typedef std::set<DefaultOnly> M;
     30         typedef M::iterator R;
     31         M m;
     32         assert(DefaultOnly::count == 0);
     33         R r = m.emplace_hint(m.cend());
     34         assert(r == m.begin());
     35         assert(m.size() == 1);
     36         assert(*m.begin() == DefaultOnly());
     37         assert(DefaultOnly::count == 1);
     38 
     39         r = m.emplace_hint(m.cbegin());
     40         assert(r == 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 M::iterator R;
     49         M m;
     50         R r = m.emplace_hint(m.cend());
     51         assert(r == m.begin());
     52         assert(m.size() == 1);
     53         assert(*m.begin() == Emplaceable());
     54         r = m.emplace_hint(m.cend(), 2, 3.5);
     55         assert(r == next(m.begin()));
     56         assert(m.size() == 2);
     57         assert(*r == Emplaceable(2, 3.5));
     58         r = m.emplace_hint(m.cbegin(), 2, 3.5);
     59         assert(r == next(m.begin()));
     60         assert(m.size() == 2);
     61         assert(*r == Emplaceable(2, 3.5));
     62     }
     63     {
     64         typedef std::set<int> M;
     65         typedef M::iterator R;
     66         M m;
     67         R r = m.emplace_hint(m.cend(), M::value_type(2));
     68         assert(r == m.begin());
     69         assert(m.size() == 1);
     70         assert(*r == 2);
     71     }
     72     {
     73         typedef std::set<int, std::less<int>, min_allocator<int>> M;
     74         typedef M::iterator R;
     75         M m;
     76         R r = m.emplace_hint(m.cend(), M::value_type(2));
     77         assert(r == m.begin());
     78         assert(m.size() == 1);
     79         assert(*r == 2);
     80     }
     81 }
     82