brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · 434f205 Raw
74 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++0310 11// <unordered_set>12 13// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,14//           class Alloc = allocator<Value>>15// class unordered_multiset16 17// template <class... Args>18//     iterator emplace(Args&&... args);19 20#include <cassert>21#include <unordered_set>22 23#include "../../Emplaceable.h"24#include "MoveOnly.h"25#include "min_allocator.h"26 27int main(int, char**) {28  {29    typedef std::unordered_multiset<Emplaceable> C;30    typedef C::iterator R;31    C c;32    R r = c.emplace();33    assert(c.size() == 1);34    assert(*r == Emplaceable());35 36    r = c.emplace(Emplaceable(5, 6));37    assert(c.size() == 2);38    assert(*r == Emplaceable(5, 6));39 40    r = c.emplace(5, 6);41    assert(c.size() == 3);42    assert(*r == Emplaceable(5, 6));43  }44  {45    typedef std::46        unordered_multiset<Emplaceable, std::hash<Emplaceable>, std::equal_to<Emplaceable>, min_allocator<Emplaceable>>47            C;48    typedef C::iterator R;49    C c;50    R r = c.emplace();51    assert(c.size() == 1);52    assert(*r == Emplaceable());53 54    r = c.emplace(Emplaceable(5, 6));55    assert(c.size() == 2);56    assert(*r == Emplaceable(5, 6));57 58    r = c.emplace(5, 6);59    assert(c.size() == 3);60    assert(*r == Emplaceable(5, 6));61  }62  { // We're unwrapping pairs for `unordered_{,multi}map`. Make sure we're not trying to do that for unordered_multiset.63    struct PairHasher {64      size_t operator()(const std::pair<MoveOnly, MoveOnly>& val) const { return std::hash<MoveOnly>()(val.first); }65    };66    using Set = std::unordered_multiset<std::pair<MoveOnly, MoveOnly>, PairHasher>;67    Set set;68    auto iter = set.emplace(std::pair<MoveOnly, MoveOnly>(2, 4));69    assert(set.begin() == iter);70  }71 72  return 0;73}74