| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <unordered_set> |
| 10 | |
| 11 | // template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>, |
| 12 | // class Alloc = allocator<Value>> |
| 13 | // class unordered_set |
| 14 | |
| 15 | // pair<iterator, bool> insert(const value_type& x); |
| 16 | |
| 17 | #include <unordered_set> |
| 18 | #include <cassert> |
| 19 | |
| 20 | #include "test_macros.h" |
| 21 | #include "min_allocator.h" |
| 22 | |
| 23 | template <class Container> |
| 24 | void do_insert_const_lvalue_test() { |
| 25 | typedef Container C; |
| 26 | typedef std::pair<typename C::iterator, bool> R; |
| 27 | typedef typename C::value_type VT; |
| 28 | C c; |
| 29 | const VT v1(3.5); |
| 30 | R r = c.insert(v1); |
| 31 | assert(c.size() == 1); |
| 32 | assert(*r.first == 3.5); |
| 33 | assert(r.second); |
| 34 | |
| 35 | r = c.insert(v1); |
| 36 | assert(c.size() == 1); |
| 37 | assert(*r.first == 3.5); |
| 38 | assert(!r.second); |
| 39 | |
| 40 | const VT v2(4.5); |
| 41 | r = c.insert(v2); |
| 42 | assert(c.size() == 2); |
| 43 | assert(*r.first == 4.5); |
| 44 | assert(r.second); |
| 45 | |
| 46 | const VT v3(5.5); |
| 47 | r = c.insert(v3); |
| 48 | assert(c.size() == 3); |
| 49 | assert(*r.first == 5.5); |
| 50 | assert(r.second); |
| 51 | } |
| 52 | |
| 53 | int main(int, char**) { |
| 54 | do_insert_const_lvalue_test<std::unordered_set<double> >(); |
| 55 | #if TEST_STD_VER >= 11 |
| 56 | { |
| 57 | typedef std::unordered_set<double, std::hash<double>, std::equal_to<double>, min_allocator<double>> C; |
| 58 | do_insert_const_lvalue_test<C>(); |
| 59 | } |
| 60 | #endif |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |