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 // pair<iterator, bool> insert(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 std::pair<C::iterator, bool> R;
     29         typedef double P;
     30         C c;
     31         R r = c.insert(P(3.5));
     32         assert(c.size() == 1);
     33         assert(*r.first == 3.5);
     34         assert(r.second);
     35 
     36         r = c.insert(P(3.5));
     37         assert(c.size() == 1);
     38         assert(*r.first == 3.5);
     39         assert(!r.second);
     40 
     41         r = c.insert(P(4.5));
     42         assert(c.size() == 2);
     43         assert(*r.first == 4.5);
     44         assert(r.second);
     45 
     46         r = c.insert(P(5.5));
     47         assert(c.size() == 3);
     48         assert(*r.first == 5.5);
     49         assert(r.second);
     50     }
     51 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
     52     {
     53         typedef std::unordered_set<MoveOnly> C;
     54         typedef std::pair<C::iterator, bool> R;
     55         typedef MoveOnly P;
     56         C c;
     57         R r = c.insert(P(3));
     58         assert(c.size() == 1);
     59         assert(*r.first == 3);
     60         assert(r.second);
     61 
     62         r = c.insert(P(3));
     63         assert(c.size() == 1);
     64         assert(*r.first == 3);
     65         assert(!r.second);
     66 
     67         r = c.insert(P(4));
     68         assert(c.size() == 2);
     69         assert(*r.first == 4);
     70         assert(r.second);
     71 
     72         r = c.insert(P(5));
     73         assert(c.size() == 3);
     74         assert(*r.first == 5);
     75         assert(r.second);
     76     }
     77 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
     78 #if TEST_STD_VER >= 11
     79     {
     80         typedef std::unordered_set<double, std::hash<double>,
     81                                 std::equal_to<double>, min_allocator<double>> C;
     82         typedef std::pair<C::iterator, bool> R;
     83         typedef double P;
     84         C c;
     85         R r = c.insert(P(3.5));
     86         assert(c.size() == 1);
     87         assert(*r.first == 3.5);
     88         assert(r.second);
     89 
     90         r = c.insert(P(3.5));
     91         assert(c.size() == 1);
     92         assert(*r.first == 3.5);
     93         assert(!r.second);
     94 
     95         r = c.insert(P(4.5));
     96         assert(c.size() == 2);
     97         assert(*r.first == 4.5);
     98         assert(r.second);
     99 
    100         r = c.insert(P(5.5));
    101         assert(c.size() == 3);
    102         assert(*r.first == 5.5);
    103         assert(r.second);
    104     }
    105 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
    106     {
    107         typedef std::unordered_set<MoveOnly, std::hash<MoveOnly>,
    108                             std::equal_to<MoveOnly>, min_allocator<MoveOnly>> C;
    109         typedef std::pair<C::iterator, bool> R;
    110         typedef MoveOnly P;
    111         C c;
    112         R r = c.insert(P(3));
    113         assert(c.size() == 1);
    114         assert(*r.first == 3);
    115         assert(r.second);
    116 
    117         r = c.insert(P(3));
    118         assert(c.size() == 1);
    119         assert(*r.first == 3);
    120         assert(!r.second);
    121 
    122         r = c.insert(P(4));
    123         assert(c.size() == 2);
    124         assert(*r.first == 4);
    125         assert(r.second);
    126 
    127         r = c.insert(P(5));
    128         assert(c.size() == 3);
    129         assert(*r.first == 5);
    130         assert(r.second);
    131     }
    132 #endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
    133 #endif
    134 }
    135