brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · 97cae1c Raw
89 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// <set>12 13// class multiset14 15// template <class... Args>16//   iterator emplace(Args&&... args);17 18#include <cassert>19#include <set>20 21#include "../../Emplaceable.h"22#include "DefaultOnly.h"23#include "MoveOnly.h"24#include "min_allocator.h"25 26int main(int, char**) {27  {28    typedef std::multiset<DefaultOnly> M;29    typedef M::iterator R;30    M m;31    assert(DefaultOnly::count == 0);32    R r = m.emplace();33    assert(r == m.begin());34    assert(m.size() == 1);35    assert(*m.begin() == DefaultOnly());36    assert(DefaultOnly::count == 1);37 38    r = m.emplace();39    assert(r == std::next(m.begin()));40    assert(m.size() == 2);41    assert(*m.begin() == DefaultOnly());42    assert(DefaultOnly::count == 2);43  }44  assert(DefaultOnly::count == 0);45  {46    typedef std::multiset<Emplaceable> M;47    typedef M::iterator R;48    M m;49    R r = m.emplace();50    assert(r == m.begin());51    assert(m.size() == 1);52    assert(*m.begin() == Emplaceable());53    r = m.emplace(2, 3.5);54    assert(r == std::next(m.begin()));55    assert(m.size() == 2);56    assert(*r == Emplaceable(2, 3.5));57    r = m.emplace(2, 3.5);58    assert(r == std::next(m.begin(), 2));59    assert(m.size() == 3);60    assert(*r == Emplaceable(2, 3.5));61  }62  {63    typedef std::multiset<int> M;64    typedef M::iterator R;65    M m;66    R r = m.emplace(M::value_type(2));67    assert(r == m.begin());68    assert(m.size() == 1);69    assert(*r == 2);70  }71  {72    typedef std::multiset<int, std::less<int>, min_allocator<int>> M;73    typedef M::iterator R;74    M m;75    R r = m.emplace(M::value_type(2));76    assert(r == m.begin());77    assert(m.size() == 1);78    assert(*r == 2);79  }80  { // We're unwrapping pairs for `{,multi}map`. Make sure we're not trying to do that for multiset.81    using Set = std::multiset<std::pair<MoveOnly, MoveOnly>>;82    Set set;83    auto iter = set.emplace(std::pair<MoveOnly, MoveOnly>(2, 4));84    assert(set.begin() == iter);85  }86 87  return 0;88}89