Home | History | Annotate | Download | only in unord.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 // <unordered_set>
     11 
     12 // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
     13 //           class Alloc = allocator<Value>>
     14 // class unordered_set
     15 
     16 // iterator insert(const_iterator p, value_type&& x);
     17 
     18 #include <unordered_set>
     19 #include <cassert>
     20 
     21 #include "../../MoveOnly.h"
     22 #include "../../min_allocator.h"
     23 
     24 int main()
     25 {
     26     {
     27         typedef std::unordered_set<double> C;
     28         typedef C::iterator R;
     29         typedef double P;
     30         C c;
     31         C::const_iterator e = c.end();
     32         R r = c.insert(e, P(3.5));
     33         assert(c.size() == 1);
     34         assert(*r == 3.5);
     35 
     36         r = c.insert(r, P(3.5));
     37         assert(c.size() == 1);
     38         assert(*r == 3.5);
     39 
     40         r = c.insert(e, P(4.5));
     41         assert(c.size() == 2);
     42         assert(*r == 4.5);
     43 
     44         r = c.insert(e, P(5.5));
     45         assert(c.size() == 3);
     46         assert(*r == 5.5);
     47     }
     48 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     49     {
     50         typedef std::unordered_set<MoveOnly> C;
     51         typedef C::iterator R;
     52         typedef MoveOnly P;
     53         C c;
     54         C::const_iterator e = c.end();
     55         R r = c.insert(e, P(3));
     56         assert(c.size() == 1);
     57         assert(*r == 3);
     58 
     59         r = c.insert(r, P(3));
     60         assert(c.size() == 1);
     61         assert(*r == 3);
     62 
     63         r = c.insert(e, P(4));
     64         assert(c.size() == 2);
     65         assert(*r == 4);
     66 
     67         r = c.insert(e, P(5));
     68         assert(c.size() == 3);
     69         assert(*r == 5);
     70     }
     71 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     72 #if __cplusplus >= 201103L
     73     {
     74         typedef std::unordered_set<double, std::hash<double>,
     75                                 std::equal_to<double>, min_allocator<double>> C;
     76         typedef C::iterator R;
     77         typedef double P;
     78         C c;
     79         C::const_iterator e = c.end();
     80         R r = c.insert(e, P(3.5));
     81         assert(c.size() == 1);
     82         assert(*r == 3.5);
     83 
     84         r = c.insert(r, P(3.5));
     85         assert(c.size() == 1);
     86         assert(*r == 3.5);
     87 
     88         r = c.insert(e, P(4.5));
     89         assert(c.size() == 2);
     90         assert(*r == 4.5);
     91 
     92         r = c.insert(e, P(5.5));
     93         assert(c.size() == 3);
     94         assert(*r == 5.5);
     95     }
     96 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     97     {
     98         typedef std::unordered_set<MoveOnly, std::hash<MoveOnly>,
     99                             std::equal_to<MoveOnly>, min_allocator<MoveOnly>> C;
    100         typedef C::iterator R;
    101         typedef MoveOnly P;
    102         C c;
    103         C::const_iterator e = c.end();
    104         R r = c.insert(e, P(3));
    105         assert(c.size() == 1);
    106         assert(*r == 3);
    107 
    108         r = c.insert(r, P(3));
    109         assert(c.size() == 1);
    110         assert(*r == 3);
    111 
    112         r = c.insert(e, P(4));
    113         assert(c.size() == 2);
    114         assert(*r == 4);
    115 
    116         r = c.insert(e, P(5));
    117         assert(c.size() == 3);
    118         assert(*r == 5);
    119     }
    120 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    121 #endif
    122 }
    123