Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. 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 | |
| 23 | int main() |
| 24 | { |
| 25 | { |
| 26 | typedef std::unordered_set<double> C; |
| 27 | typedef std::pair<C::iterator, bool> R; |
| 28 | typedef double P; |
| 29 | C c; |
| 30 | R r = c.insert(P(3.5)); |
| 31 | assert(c.size() == 1); |
| 32 | assert(*r.first == 3.5); |
| 33 | assert(r.second); |
| 34 | |
| 35 | r = c.insert(P(3.5)); |
| 36 | assert(c.size() == 1); |
| 37 | assert(*r.first == 3.5); |
| 38 | assert(!r.second); |
| 39 | |
| 40 | r = c.insert(P(4.5)); |
| 41 | assert(c.size() == 2); |
| 42 | assert(*r.first == 4.5); |
| 43 | assert(r.second); |
| 44 | |
| 45 | r = c.insert(P(5.5)); |
| 46 | assert(c.size() == 3); |
| 47 | assert(*r.first == 5.5); |
| 48 | assert(r.second); |
| 49 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 50 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | { |
| 52 | typedef std::unordered_set<MoveOnly> C; |
| 53 | typedef std::pair<C::iterator, bool> R; |
| 54 | typedef MoveOnly P; |
| 55 | C c; |
| 56 | R r = c.insert(P(3)); |
| 57 | assert(c.size() == 1); |
| 58 | assert(*r.first == 3); |
| 59 | assert(r.second); |
| 60 | |
| 61 | r = c.insert(P(3)); |
| 62 | assert(c.size() == 1); |
| 63 | assert(*r.first == 3); |
| 64 | assert(!r.second); |
| 65 | |
| 66 | r = c.insert(P(4)); |
| 67 | assert(c.size() == 2); |
| 68 | assert(*r.first == 4); |
| 69 | assert(r.second); |
| 70 | |
| 71 | r = c.insert(P(5)); |
| 72 | assert(c.size() == 3); |
| 73 | assert(*r.first == 5); |
| 74 | assert(r.second); |
| 75 | } |
Howard Hinnant | 73d21a4 | 2010-09-04 23:28:19 +0000 | [diff] [blame^] | 76 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 77 | } |