brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.5 KiB · 36501a5 Raw
191 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++03, c++11, c++14, c++17, c++2010 11// <flat_set>12 13// template<container-compatible-range<value_type> R>14//     flat_multiset(from_range_t, R&&)15// template<container-compatible-range<value_type> R>16//     flat_multiset(from_range_t, R&&, const key_compare&)17// template<container-compatible-range<value_type> R, class Alloc>18//      flat_multiset(from_range_t, R&&, const Alloc&);19// template<container-compatible-range<value_type> R, class Alloc>20//      flat_multiset(from_range_t, R&&, const key_compare&, const Alloc&);21 22#include <algorithm>23#include <deque>24#include <flat_set>25#include <functional>26#include <string>27#include <vector>28 29#include "min_allocator.h"30#include "test_allocator.h"31#include "test_iterators.h"32#include "test_macros.h"33#include "../../../test_compare.h"34 35// test constraint container-compatible-range36 37template <class V>38using RangeOf = std::ranges::subrange<V*>;39using Set     = std::flat_multiset<int>;40 41static_assert(std::is_constructible_v<Set, std::from_range_t, RangeOf<int>>);42static_assert(std::is_constructible_v<Set, std::from_range_t, RangeOf<short>>);43static_assert(!std::is_constructible_v<Set, std::from_range_t, RangeOf<std::pair<int, int>>>);44 45static_assert(std::is_constructible_v<Set, std::from_range_t, RangeOf<int>, std::less<int>>);46static_assert(std::is_constructible_v<Set, std::from_range_t, RangeOf<short>, std::less<int>>);47static_assert(!std::is_constructible_v<Set, std::from_range_t, RangeOf<std::pair<int, int>>, std::less<int>>);48 49static_assert(std::is_constructible_v<Set, std::from_range_t, RangeOf<int>, std::allocator<int>>);50static_assert(std::is_constructible_v<Set, std::from_range_t, RangeOf<short>, std::allocator<int>>);51static_assert(!std::is_constructible_v<Set, std::from_range_t, RangeOf<std::pair<int, int>>, std::allocator<int>>);52 53static_assert(std::is_constructible_v<Set, std::from_range_t, RangeOf<int>, std::less<int>, std::allocator<int>>);54static_assert(std::is_constructible_v<Set, std::from_range_t, RangeOf<int>, std::less<int>, std::allocator<int>>);55static_assert(56    !std::57        is_constructible_v<Set, std::from_range_t, RangeOf<std::pair<int, int>>, std::less<int>, std::allocator<int>>);58 59template <template <class...> class KeyContainer>60constexpr void test() {61  {62    // The constructors in this subclause shall not participate in overload63    // resolution unless uses_allocator_v<container_type, Alloc> is true.64 65    using C  = test_less<int>;66    using A1 = test_allocator<int>;67    using A2 = other_allocator<int>;68    using V1 = KeyContainer<int, A1>;69    using V2 = KeyContainer<int, A2>;70    using M1 = std::flat_multiset<int, C, V1>;71    using M2 = std::flat_multiset<int, C, V2>;72    static_assert(std::is_constructible_v<M1, std::from_range_t, M1, const A1&>);73    static_assert(std::is_constructible_v<M2, std::from_range_t, M2, const A2&>);74    static_assert(!std::is_constructible_v<M1, std::from_range_t, M1, const A2&>);75    static_assert(!std::is_constructible_v<M2, std::from_range_t, M2, const A1&>);76 77    static_assert(std::is_constructible_v<M1, std::from_range_t, M1, const C&, const A1&>);78    static_assert(std::is_constructible_v<M2, std::from_range_t, M2, const C&, const A2&>);79    static_assert(!std::is_constructible_v<M1, std::from_range_t, M1, const C&, const A2&>);80    static_assert(!std::is_constructible_v<M2, std::from_range_t, M2, const C&, const A1&>);81  }82 83  int ar[]       = {1, 1, 1, 2, 2, 3, 2, 3, 3};84  int expected[] = {1, 1, 1, 2, 2, 2, 3, 3, 3};85  {86    // flat_multiset(from_range_t, R&&)87    // input_range && !common88    using M    = std::flat_multiset<int, std::less<int>, KeyContainer<int>>;89    using Iter = cpp20_input_iterator<const int*>;90    using Sent = sentinel_wrapper<Iter>;91    using R    = std::ranges::subrange<Iter, Sent>;92    auto m     = M(std::from_range, R(Iter(ar), Sent(Iter(ar + 9))));93    assert(std::ranges::equal(m, expected));94 95    // explicit(false)96    M m2 = {std::from_range, R(Iter(ar), Sent(Iter(ar + 9)))};97    assert(m2 == m);98  }99  {100    // flat_multiset(from_range_t, R&&)101    // greater102    using M    = std::flat_multiset<int, std::greater<int>, KeyContainer<int, min_allocator<int>>>;103    using Iter = cpp20_input_iterator<const int*>;104    using Sent = sentinel_wrapper<Iter>;105    using R    = std::ranges::subrange<Iter, Sent>;106    auto m     = M(std::from_range, R(Iter(ar), Sent(Iter(ar + 9))));107    assert(std::ranges::equal(m, KeyContainer<int, min_allocator<int>>{3, 3, 3, 2, 2, 2, 1, 1, 1}));108  }109  {110    // flat_multiset(from_range_t, R&&)111    // contiguous range112    using M = std::flat_multiset<int, std::less<int>, KeyContainer<int>>;113    using R = std::ranges::subrange<const int*>;114    auto m  = M(std::from_range, R(ar, ar + 9));115    assert(std::ranges::equal(m, expected));116  }117  {118    // flat_multiset(from_range_t, R&&, const key_compare&)119    using C = test_less<int>;120    using M = std::flat_multiset<int, C, KeyContainer<int>>;121    using R = std::ranges::subrange<const int*>;122    auto m  = M(std::from_range, R(ar, ar + 9), C(3));123    assert(std::ranges::equal(m, expected));124    assert(m.key_comp() == C(3));125 126    // explicit(false)127    M m2 = {std::from_range, R(ar, ar + 9), C(3)};128    assert(m2 == m);129    assert(m2.key_comp() == C(3));130  }131  {132    // flat_multiset(from_range_t, R&&, const Allocator&)133    using A1 = test_allocator<int>;134    using M  = std::flat_multiset<int, std::less<int>, KeyContainer<int, A1>>;135    using R  = std::ranges::subrange<const int*>;136    auto m   = M(std::from_range, R(ar, ar + 9), A1(5));137    assert(std::ranges::equal(m, expected));138    assert(std::move(m).extract().get_allocator() == A1(5));139  }140  {141    // flat_multiset(from_range_t, R&&, const Allocator&)142    // explicit(false)143    using A1 = test_allocator<int>;144    using M  = std::flat_multiset<int, std::less<int>, KeyContainer<int, A1>>;145    using R  = std::ranges::subrange<const int*>;146    M m      = {std::from_range, R(ar, ar + 9), A1(5)}; // implicit ctor147    assert(std::ranges::equal(m, expected));148    assert(std::move(m).extract().get_allocator() == A1(5));149  }150  {151    // flat_multiset(from_range_t, R&&, const key_compare&, const Allocator&)152    using C  = test_less<int>;153    using A1 = test_allocator<int>;154    using M  = std::flat_multiset<int, C, KeyContainer<int, A1>>;155    using R  = std::ranges::subrange<const int*>;156    auto m   = M(std::from_range, R(ar, ar + 9), C(3), A1(5));157    assert(std::ranges::equal(m, expected));158    assert(m.key_comp() == C(3));159    assert(std::move(m).extract().get_allocator() == A1(5));160  }161  {162    // flat_multiset(from_range_t, R&&, const key_compare&, const Allocator&)163    // explicit(false)164    using A1 = test_allocator<int>;165    using M  = std::flat_multiset<int, std::less<int>, KeyContainer<int, A1>>;166    using R  = std::ranges::subrange<const int*>;167    M m      = {std::from_range, R(ar, ar + 9), {}, A1(5)}; // implicit ctor168    assert(std::ranges::equal(m, expected));169    assert(std::move(m).extract().get_allocator() == A1(5));170  }171}172 173constexpr bool test() {174  test<std::vector>();175#ifndef __cpp_lib_constexpr_deque176  if (!TEST_IS_CONSTANT_EVALUATED)177#endif178    test<std::deque>();179 180  return true;181}182 183int main(int, char**) {184  test();185#if TEST_STD_VER >= 26186  static_assert(test());187#endif188 189  return 0;190}191