libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

insert_const_lvalue.pass.cpp (1625B)


      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(const value_type& x);
     17 
     18 #include <unordered_set>
     19 #include <cassert>
     20 
     21 #include "min_allocator.h"
     22 
     23 template<class Container>
     24 void do_insert_const_lvalue_test()
     25 {
     26     typedef Container C;
     27     typedef std::pair<typename C::iterator, bool> R;
     28     typedef typename C::value_type VT;
     29     C c;
     30     const VT v1(3.5);
     31     R r = c.insert(v1);
     32     assert(c.size() == 1);
     33     assert(*r.first == 3.5);
     34     assert(r.second);
     35 
     36     r = c.insert(v1);
     37     assert(c.size() == 1);
     38     assert(*r.first == 3.5);
     39     assert(!r.second);
     40 
     41     const VT v2(4.5);
     42     r = c.insert(v2);
     43     assert(c.size() == 2);
     44     assert(*r.first == 4.5);
     45     assert(r.second);
     46 
     47     const VT v3(5.5);
     48     r = c.insert(v3);
     49     assert(c.size() == 3);
     50     assert(*r.first == 5.5);
     51     assert(r.second);
     52 }
     53 
     54 int main()
     55 {
     56     do_insert_const_lvalue_test<std::unordered_set<double> >();
     57 #if TEST_STD_VER >= 11
     58     {
     59         typedef std::unordered_set<double, std::hash<double>,
     60                                 std::equal_to<double>, min_allocator<double>> C;
     61         do_insert_const_lvalue_test<C>();
     62     }
     63 #endif
     64 }