Merge branch 'main' into p2996

This commit is contained in:
Dan Katz
2025-06-23 13:50:52 -04:00
4661 changed files with 216710 additions and 75495 deletions

View File

@@ -12,6 +12,7 @@
#include <cstddef>
#include <deque>
#include <list>
#include <ranges>
#include <string>
#include <vector>
@@ -23,6 +24,7 @@ int main(int argc, char** argv) {
// {std,ranges}::for_each
{
auto bm = []<class Container>(std::string name, auto for_each) {
using ElemType = typename Container::value_type;
benchmark::RegisterBenchmark(
name,
[for_each](auto& st) {
@@ -33,15 +35,14 @@ int main(int argc, char** argv) {
for ([[maybe_unused]] auto _ : st) {
benchmark::DoNotOptimize(c);
auto result = for_each(first, last, [](int& x) { x = std::clamp(x, 10, 100); });
auto result = for_each(first, last, [](ElemType& x) { x = std::clamp<ElemType>(x, 10, 100); });
benchmark::DoNotOptimize(result);
}
})
->Arg(8)
->Arg(32)
->Arg(50) // non power-of-two
->Arg(8192)
->Arg(1 << 20);
->Arg(8192);
};
bm.operator()<std::vector<int>>("std::for_each(vector<int>)", std_for_each);
bm.operator()<std::deque<int>>("std::for_each(deque<int>)", std_for_each);
@@ -51,6 +52,42 @@ int main(int argc, char** argv) {
bm.operator()<std::list<int>>("rng::for_each(list<int>)", std::ranges::for_each);
}
// {std,ranges}::for_each for join_view
{
auto bm = []<class Container>(std::string name, auto for_each) {
using C1 = typename Container::value_type;
using ElemType = typename C1::value_type;
benchmark::RegisterBenchmark(
name,
[for_each](auto& st) {
std::size_t const size = st.range(0);
std::size_t const seg_size = 256;
std::size_t const segments = (size + seg_size - 1) / seg_size;
Container c(segments);
for (std::size_t i = 0, n = size; i < segments; ++i, n -= seg_size) {
c[i].resize(std::min(seg_size, n), ElemType(1));
}
auto view = c | std::views::join;
auto first = view.begin();
auto last = view.end();
for ([[maybe_unused]] auto _ : st) {
benchmark::DoNotOptimize(c);
auto result = for_each(first, last, [](ElemType& x) { x = std::clamp<ElemType>(x, 10, 100); });
benchmark::DoNotOptimize(result);
}
})
->Arg(8)
->Arg(32)
->Arg(50) // non power-of-two
->Arg(8192);
};
bm.operator()<std::vector<std::vector<int>>>("std::for_each(join_view(vector<vector<int>>))", std_for_each);
bm.operator()<std::vector<std::vector<int>>>("rng::for_each(join_view(vector<vector<int>>)", std::ranges::for_each);
}
benchmark::Initialize(&argc, argv);
benchmark::RunSpecifiedBenchmarks();
benchmark::Shutdown();

View File

@@ -21,7 +21,7 @@
int main(int argc, char** argv) {
auto std_for_each_n = [](auto first, auto n, auto f) { return std::for_each_n(first, n, f); };
// std::for_each_n
// {std,ranges}::for_each_n
{
auto bm = []<class Container>(std::string name, auto for_each_n) {
using ElemType = typename Container::value_type;
@@ -41,19 +41,17 @@ int main(int argc, char** argv) {
->Arg(8)
->Arg(32)
->Arg(50) // non power-of-two
->Arg(1024)
->Arg(4096)
->Arg(8192)
->Arg(1 << 14)
->Arg(1 << 16)
->Arg(1 << 18);
->Arg(8192);
};
bm.operator()<std::vector<int>>("std::for_each_n(vector<int>)", std_for_each_n);
bm.operator()<std::deque<int>>("std::for_each_n(deque<int>)", std_for_each_n);
bm.operator()<std::list<int>>("std::for_each_n(list<int>)", std_for_each_n);
bm.operator()<std::vector<int>>("rng::for_each_n(vector<int>)", std::ranges::for_each_n);
bm.operator()<std::deque<int>>("rng::for_each_n(deque<int>)", std::ranges::for_each_n);
bm.operator()<std::list<int>>("rng::for_each_n(list<int>)", std::ranges::for_each_n);
}
// std::for_each_n for join_view
// {std,ranges}::for_each_n for join_view
{
auto bm = []<class Container>(std::string name, auto for_each_n) {
using C1 = typename Container::value_type;
@@ -81,14 +79,11 @@ int main(int argc, char** argv) {
->Arg(8)
->Arg(32)
->Arg(50) // non power-of-two
->Arg(1024)
->Arg(4096)
->Arg(8192)
->Arg(1 << 14)
->Arg(1 << 16)
->Arg(1 << 18);
->Arg(8192);
};
bm.operator()<std::vector<std::vector<int>>>("std::for_each_n(join_view(vector<vector<int>>))", std_for_each_n);
bm.operator()<std::vector<std::vector<int>>>(
"rng::for_each_n(join_view(vector<vector<int>>)", std::ranges::for_each_n);
}
benchmark::Initialize(&argc, argv);

View File

@@ -1,5 +1,5 @@
# This testing configuration handles running the test suite against LLVM's
# libc++ using adb and a libc++_shared.so library on Android.
# libc++ using adb on Android.
lit_config.load_config(config, '@CMAKE_CURRENT_BINARY_DIR@/cmake-bridge.cfg')
@@ -27,11 +27,11 @@ if re.match(r'i686-linux-android(21|22|23)$', config.target_triple):
compile_flags += ' -mstackrealign'
config.substitutions.append(('%{compile_flags}', compile_flags))
# The NDK library is called "libc++_shared.so". Use LD_LIBRARY_PATH to find
# libc++_shared.so because older Bionic dynamic loaders don't support rpath
# lookup.
# The platform library is called "libc++.so" and the NDK library is called "libc++_shared.so".
# Use LD_LIBRARY_PATH to find the libcxx shared object because older Bionic dynamic loaders
# don't support rpath lookup.
config.substitutions.append(('%{link_flags}',
'-nostdlib++ -L %{lib-dir} -lc++_shared'
'-nostdlib++ -L %{lib-dir} -l@LIBCXX_SHARED_OUTPUT_NAME@'
))
config.substitutions.append(('%{exec}',
'%{executor}' +

View File

@@ -1,56 +0,0 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
#include <__tree>
#include <map>
#include <set>
#include <type_traits>
#include "test_macros.h"
#include "min_allocator.h"
void testKeyValueTrait() {
{
typedef int Tp;
typedef std::__tree_key_value_types<Tp> Traits;
static_assert((std::is_same<Traits::key_type, int>::value), "");
static_assert((std::is_same<Traits::__container_value_type, Tp>::value), "");
static_assert(Traits::__is_map == false, "");
}
{
typedef std::pair<int, int> Tp;
typedef std::__tree_key_value_types<Tp> Traits;
static_assert((std::is_same<Traits::key_type, Tp>::value), "");
static_assert((std::is_same<Traits::__container_value_type, Tp>::value), "");
static_assert(Traits::__is_map == false, "");
}
{
typedef std::pair<const int, int> Tp;
typedef std::__tree_key_value_types<Tp> Traits;
static_assert((std::is_same<Traits::key_type, Tp>::value), "");
static_assert((std::is_same<Traits::__container_value_type, Tp>::value), "");
static_assert(Traits::__is_map == false, "");
}
{
typedef std::__value_type<int, int> Tp;
typedef std::__tree_key_value_types<Tp> Traits;
static_assert((std::is_same<Traits::key_type, int>::value), "");
static_assert((std::is_same<Traits::mapped_type, int>::value), "");
static_assert((std::is_same<Traits::__container_value_type, std::pair<const int, int> >::value), "");
static_assert((std::is_same<Traits::__map_value_type, std::pair<const int, int> >::value), "");
static_assert(Traits::__is_map == true, "");
}
}
int main(int, char**) {
testKeyValueTrait();
return 0;
}

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// <flat_set>
// class flat_set
// class flat_multiset
// Extension: SCARY/N2913 iterator compatibility between flat_set and flat_multiset
// Test for the absence of this feature
#include <flat_set>
#include <type_traits>
#include "test_macros.h"
void test() {
typedef std::flat_set<int, int> M1;
typedef std::flat_multiset<int, int> M2;
static_assert(!std::is_convertible_v<M1::iterator, M2::iterator>);
static_assert(!std::is_convertible_v<M2::iterator, M1::iterator>);
static_assert(!std::is_convertible_v<M1::const_iterator, M2::const_iterator>);
static_assert(!std::is_convertible_v<M2::const_iterator, M1::const_iterator>);
}

View File

@@ -8,6 +8,11 @@
// UNSUPPORTED: c++03, c++11, c++14
// When built with modules, this test gives diagnostics like declaration of
// 'unexpected' must be imported from module 'std.expected.unexpected' before
// it is required. Therefore disable it in this configuration.
// UNSUPPORTED: clang-modules-build
// test unexpected
#include <exception>

View File

@@ -0,0 +1,74 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// We're using `string::starts_with` in this test
// UNSUPPORTED: c++03, c++11, c++14, c++17
// Make sure that the mangling of our public types stays the same
// UNSUPPORTED: no-rtti, msvc
#include <cassert>
#include <charconv>
#include <iostream>
#include <map>
#include <typeinfo>
#include <string>
#include <string_view>
template <class>
struct mangling {};
struct test_struct {};
_LIBCPP_BEGIN_NAMESPACE_STD
struct ns_mangling {};
_LIBCPP_END_NAMESPACE_STD
namespace std::__name {
struct ns_mangling {};
} // namespace std::__name
namespace std::__long_name_to_make_sure_multiple_digits_work {
struct ns_mangling {};
} // namespace std::__long_name_to_make_sure_multiple_digits_work
std::string get_std_inline_namespace_mangling(const std::type_info& info) {
std::string name = info.name();
assert(name.starts_with("NSt"));
unsigned name_len;
auto res = std::from_chars(name.data() + 3, name.data() + name.size(), name_len);
assert(res.ec == std::errc{});
return std::move(name).substr(0, (res.ptr + name_len) - name.data());
}
void expect_mangling(const std::type_info& info, std::string expected_name) {
if (expected_name != info.name())
std::__libcpp_verbose_abort("Expected: '%s'\n Got: '%s'\n", expected_name.c_str(), info.name());
}
// Mangling names are really long, but splitting it up into multiple lines doesn't make it any more readable
// clang-format off
int main(int, char**) {
// self-test inline namespace recovery
assert(get_std_inline_namespace_mangling(typeid(std::__name::ns_mangling)) == "NSt6__name");
assert(get_std_inline_namespace_mangling(typeid(std::__long_name_to_make_sure_multiple_digits_work::ns_mangling)) == "NSt45__long_name_to_make_sure_multiple_digits_work");
// selftest
expect_mangling(typeid(test_struct), "11test_struct");
std::string ns_std = get_std_inline_namespace_mangling(typeid(std::ns_mangling));
std::string ptrdiff = typeid(std::ptrdiff_t).name();
// std::map
expect_mangling(typeid(std::map<int, int>), ns_std + "3mapIiiNS_4lessIiEENS_9allocatorINS_4pairIKiiEEEEEE");
expect_mangling(typeid(std::map<int, int>::iterator), ns_std + "14__map_iteratorINS_15__tree_iteratorINS_12__value_typeIiiEEPNS_11__tree_nodeIS3_PvEE" + ptrdiff +"EEEE");
expect_mangling(typeid(std::map<int, int>::const_iterator), ns_std + "20__map_const_iteratorINS_21__tree_const_iteratorINS_12__value_typeIiiEEPNS_11__tree_nodeIS3_PvEE" + ptrdiff + "EEEE");
return 0;
}

View File

@@ -6,9 +6,11 @@
//
//===----------------------------------------------------------------------===//
// TODO: Investigate
// ABI tags have no effect in MSVC mode.
// XFAIL: msvc
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
// Test that we encode whether exceptions are supported in an ABI tag to avoid
// ODR violations when linking TUs that have different values for it.
@@ -18,17 +20,19 @@
// RUN: %{cxx} %t.tu1.o %t.tu2.o %t.main.o %{flags} %{link_flags} -o %t.exe
// RUN: %{exec} %t.exe
#include "test_macros.h"
// -fno-exceptions
#ifdef TU1
# include <__config>
_LIBCPP_HIDE_FROM_ABI inline int f() { return 1; }
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 1; }
int tu1() { return f(); }
#endif // TU1
// -fexceptions
#ifdef TU2
# include <__config>
_LIBCPP_HIDE_FROM_ABI inline int f() { return 2; }
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 2; }
int tu2() { return f(); }
#endif // TU2

View File

@@ -6,9 +6,11 @@
//
//===----------------------------------------------------------------------===//
// TODO: Investigate
// ABI tags have no effect in MSVC mode.
// XFAIL: msvc
// XFAIL: FROZEN-CXX03-HEADERS-FIXME
// Test that we encode the hardening mode in an ABI tag to avoid ODR violations
// when linking TUs that have different values for it.
@@ -21,31 +23,33 @@
// RUN: %{cxx} %t.tu1.o %t.tu2.o %t.tu3.o %t.tu4.o %t.main.o %{flags} %{link_flags} -o %t.exe
// RUN: %{exec} %t.exe
#include "test_macros.h"
// fast hardening mode
#ifdef TU1
# include <__config>
_LIBCPP_HIDE_FROM_ABI inline int f() { return 1; }
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 1; }
int tu1() { return f(); }
#endif // TU1
// extensive hardening mode
#ifdef TU2
# include <__config>
_LIBCPP_HIDE_FROM_ABI inline int f() { return 2; }
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 2; }
int tu2() { return f(); }
#endif // TU2
// debug hardening mode
#ifdef TU3
# include <__config>
_LIBCPP_HIDE_FROM_ABI inline int f() { return 3; }
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 3; }
int tu3() { return f(); }
#endif // TU3
// No hardening
#ifdef TU4
# include <__config>
_LIBCPP_HIDE_FROM_ABI inline int f() { return 4; }
_LIBCPP_HIDE_FROM_ABI TEST_NOINLINE inline int f() { return 4; }
int tu4() { return f(); }
#endif // TU4

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// REQUIRES: std-at-least-c++23
// <ranges>
// Test the libc++ extension that std::ranges::join_with_view::iterator<Const>::operator* is marked as [[nodiscard]].
#include <ranges>
#include <utility>
void test() {
char range[3][2] = {{'x', 'x'}, {'y', 'y'}, {'z', 'z'}};
char pattern[2] = {',', ' '};
std::ranges::join_with_view view(range, pattern);
// clang-format off
*view.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
*std::as_const(view).begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// clang-format on
}

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// REQUIRES: std-at-least-c++23
// <ranges>
// Test the libc++ extension that std::ranges::join_with_view::iterator<Const>::operator== is marked as [[nodiscard]].
#include <ranges>
#include <utility>
void test() {
char16_t range[3][1] = {{u'x'}, {u'y'}, {u'z'}};
char16_t pattern[1] = {u'-'};
std::ranges::join_with_view view(range, pattern);
// clang-format off
(view.begin() == view.end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
(std::as_const(view).begin() == view.end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
(view.begin() == std::as_const(view).end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
(std::as_const(view).begin() == std::as_const(view).end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// clang-format on
}

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// REQUIRES: std-at-least-c++23
// <ranges>
// Test the libc++ extension that std::ranges::join_with_view::iterator<Const>::iter_move is marked as [[nodiscard]].
#include <ranges>
#include <utility>
void test() {
long range[2][1] = {{0L}, {2L}};
long pattern[1] = {1L};
std::ranges::join_with_view view(range, pattern);
// clang-format off
iter_move(view.begin()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
iter_move(std::as_const(view).begin()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// clang-format on
}

View File

@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// REQUIRES: std-at-least-c++23
// <ranges>
// This test ensures that we use `[[no_unique_address]]` in `join_with_view::iterator`.
#include <cstddef>
#include <ranges>
#include <variant>
struct IntRange : std::ranges::view_base {
int* begin();
int* end();
};
class Iter {
public:
using value_type = IntRange;
using difference_type = ptrdiff_t;
Iter& operator++();
void operator++(int);
value_type& operator*() const;
bool operator==(std::default_sentinel_t) const;
private:
int* ptr_;
};
static_assert(std::input_iterator<Iter>);
static_assert(!std::forward_iterator<Iter>);
struct View : std::ranges::view_base {
Iter begin();
std::default_sentinel_t end();
};
static_assert(std::ranges::input_range<View>);
static_assert(!std::ranges::forward_range<View>);
using JWV = std::ranges::join_with_view<View, IntRange>;
// Expected JWV::iterator layout:
// _Parent* __parent_; // offset: 0
// [[no_unique_address]] __empty __outer_it; // 0
// variant<_PatternIter, _InnerIter> __pattern_; // sizeof(pointer)
static_assert(sizeof(std::ranges::iterator_t<JWV>) ==
sizeof(void*) + sizeof(std::variant<int*, int*>)); // sizeof(__parent_) + sizeof(__inner_it_)

View File

@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// REQUIRES: std-at-least-c++23
// <ranges>
// Test the libc++ extension that std::views::join_with is marked as [[nodiscard]].
#include <ranges>
void test() {
int range[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int pattern_base[2] = {-1, -1};
auto pattern = std::views::all(pattern_base);
// clang-format off
std::views::join_with(pattern); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::join_with(range, pattern); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
range | std::views::join_with(pattern); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::reverse | std::views::join_with(pattern); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::join_with(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::join_with(range, 0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
range | std::views::join_with(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::views::reverse | std::views::join_with(0); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// clang-format on
}

View File

@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// REQUIRES: std-at-least-c++23
// <ranges>
// Test the libc++ extension that std::ranges::join_with_view::sentinel<Const>::operator== is marked as [[nodiscard]].
#include <array>
#include <ranges>
#include <utility>
#include "test_iterators.h"
#include "test_range.h"
void test() {
std::array<test_range<cpp20_input_iterator>, 0> range;
std::array<int, 0> pattern;
std::ranges::join_with_view view(range, pattern);
static_assert(!std::ranges::common_range<decltype(view)>);
// clang-format off
(view.begin() == view.end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
(std::as_const(view).begin() == view.end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
(view.begin() == std::as_const(view).end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
(std::as_const(view).begin() == std::as_const(view).end()); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// clang-format on
}

View File

@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// REQUIRES: std-at-least-c++23
// XFAIL: msvc
// <ranges>
// This test ensures that we use `[[no_unique_address]]` in `join_with_view::sentinel`.
#include <cstddef>
#include <ranges>
#include <string_view>
template <bool Const>
struct Iter {
using value_type = std::string_view;
using difference_type = std::ptrdiff_t;
Iter& operator++();
Iter operator++(int);
value_type& operator*() const;
bool operator==(const Iter&) const;
bool operator==(std::default_sentinel_t) const;
};
struct View : std::ranges::view_base {
Iter<false> begin();
Iter<true> begin() const;
std::default_sentinel_t end() const;
};
using JWV = std::ranges::join_with_view<View, std::string_view>;
template <class View>
struct Test {
[[no_unique_address]] std::ranges::sentinel_t<View> se;
unsigned char pad;
};
static_assert(sizeof(Test<JWV>) == 1);
static_assert(sizeof(Test<const JWV>) == 1);

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// REQUIRES: std-at-least-c++23
// <ranges>
// Test the libc++ extension that std::ranges::join_with_view::base is marked as [[nodiscard]].
#include <ranges>
#include <utility>
void test() {
int range[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
int pattern[2] = {-1, -1};
std::ranges::join_with_view view(range, pattern);
// clang-format off
view.base(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::as_const(view).base(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(std::as_const(view)).base(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::move(view).base(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// clang-format on
}

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// REQUIRES: std-at-least-c++23
// <ranges>
// Test the libc++ extension that std::ranges::join_with_view::begin is marked as [[nodiscard]].
#include <ranges>
#include <utility>
void test() {
int range[3][2] = {{1, 3}, {4, 6}, {7, 9}};
int pattern[1] = {-2};
std::ranges::join_with_view view(range, pattern);
// clang-format off
view.begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::as_const(view).begin(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// clang-format on
}

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// REQUIRES: std-at-least-c++23
// <ranges>
// Test the libc++ extension that std::ranges::join_with_view::end is marked as [[nodiscard]].
#include <ranges>
#include <utility>
void test() {
int range[3][2] = {{1, 2}, {4, 5}, {7, 8}};
int pattern[1] = {-3};
std::ranges::join_with_view view(range, pattern);
// clang-format off
view.end(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
std::as_const(view).end(); // expected-warning {{ignoring return value of function declared with 'nodiscard' attribute}}
// clang-format on
}

View File

@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// REQUIRES: std-at-least-c++23
// XFAIL: msvc
// <ranges>
// This test ensures that we use `[[no_unique_address]]` in `join_with_view`.
#include <ranges>
#include <string>
struct ForwardView : std::ranges::view_base {
std::string* begin() const;
std::string* end() const;
};
static_assert(std::ranges::forward_range<ForwardView>);
static_assert(std::is_reference_v<std::ranges::range_reference_t<ForwardView>>);
struct Pattern : std::ranges::view_base {
char* begin() const;
char* end() const;
};
template <class View>
struct Test {
[[no_unique_address]] View view;
unsigned char pad;
};
using JWV = std::ranges::join_with_view<ForwardView, Pattern>;
// Expected JWV layout:
// [[no_unique_address]] _View __base_ // offset: 0
// [[no_unique_address]] __empty_cache __outer_it; // 0
// [[no_unique_address]] __empty_cache __inner_; // 1
// [[no_unique_address]] _Patter __pattern_ // 0
static_assert(sizeof(JWV) == 2);
static_assert(sizeof(Test<JWV>) == 2);

View File

@@ -195,7 +195,7 @@ constexpr bool test() {
std::string a[] = {str1, str1, str, str1, str1};
auto whole =
std::ranges::subrange(forward_iterator(std::move_iterator(a)), forward_iterator(std::move_iterator(a + 5)));
bool ret = std::ranges::contains(whole.begin(), whole.end(), "hello world", [&](const std::string i) {
bool ret = std::ranges::contains(whole.begin(), whole.end(), +"hello world", [&](const std::string i) {
++projection_count;
return i;
});
@@ -207,7 +207,7 @@ constexpr bool test() {
std::string a[] = {str1, str1, str, str1, str1};
auto whole =
std::ranges::subrange(forward_iterator(std::move_iterator(a)), forward_iterator(std::move_iterator(a + 5)));
bool ret = std::ranges::contains(whole, "hello world", [&](const std::string i) {
bool ret = std::ranges::contains(whole, +"hello world", [&](const std::string i) {
++projection_count;
return i;
});

View File

@@ -20,7 +20,10 @@
#include <algorithm>
#include <array>
#include <cassert>
#include <deque>
#include <ranges>
#include <vector>
#include "almost_satisfies_types.h"
#include "test_iterators.h"
@@ -30,7 +33,7 @@ struct Callable {
};
template <class Iter, class Sent = Iter>
concept HasForEachIt = requires (Iter iter, Sent sent) { std::ranges::for_each(iter, sent, Callable{}); };
concept HasForEachIt = requires(Iter iter, Sent sent) { std::ranges::for_each(iter, sent, Callable{}); };
static_assert(HasForEachIt<int*>);
static_assert(!HasForEachIt<InputIteratorNotDerivedFrom>);
@@ -47,7 +50,7 @@ static_assert(!HasForEachItFunc<IndirectUnaryPredicateNotPredicate>);
static_assert(!HasForEachItFunc<IndirectUnaryPredicateNotCopyConstructible>);
template <class Range>
concept HasForEachR = requires (Range range) { std::ranges::for_each(range, Callable{}); };
concept HasForEachR = requires(Range range) { std::ranges::for_each(range, Callable{}); };
static_assert(HasForEachR<UncheckedRange<int*>>);
static_assert(!HasForEachR<InputRangeNotDerivedFrom>);
@@ -68,7 +71,7 @@ constexpr void test_iterator() {
{ // simple test
{
auto func = [i = 0](int& a) mutable { a += i++; };
int a[] = {1, 6, 3, 4};
int a[] = {1, 6, 3, 4};
std::same_as<std::ranges::for_each_result<Iter, decltype(func)>> decltype(auto) ret =
std::ranges::for_each(Iter(a), Sent(Iter(a + 4)), func);
assert(a[0] == 1);
@@ -81,8 +84,8 @@ constexpr void test_iterator() {
assert(i == 4);
}
{
auto func = [i = 0](int& a) mutable { a += i++; };
int a[] = {1, 6, 3, 4};
auto func = [i = 0](int& a) mutable { a += i++; };
int a[] = {1, 6, 3, 4};
auto range = std::ranges::subrange(Iter(a), Sent(Iter(a + 4)));
std::same_as<std::ranges::for_each_result<Iter, decltype(func)>> decltype(auto) ret =
std::ranges::for_each(range, func);
@@ -110,6 +113,30 @@ constexpr void test_iterator() {
}
}
struct deque_test {
std::deque<int>* d_;
int* i_;
deque_test(std::deque<int>& d, int& i) : d_(&d), i_(&i) {}
void operator()(int& v) {
assert(&(*d_)[*i_] == &v);
++*i_;
}
};
/*TEST_CONSTEXPR_CXX26*/
void test_segmented_deque_iterator() { // TODO: Mark as TEST_CONSTEXPR_CXX26 once std::deque is constexpr
// check that segmented deque iterators work properly
int sizes[] = {0, 1, 2, 1023, 1024, 1025, 2047, 2048, 2049};
for (const int size : sizes) {
std::deque<int> d(size);
int index = 0;
std::ranges::for_each(d, deque_test(d, index));
}
}
constexpr bool test() {
test_iterator<cpp17_input_iterator<int*>, sentinel_wrapper<cpp17_input_iterator<int*>>>();
test_iterator<cpp20_input_iterator<int*>, sentinel_wrapper<cpp20_input_iterator<int*>>>();
@@ -146,6 +173,15 @@ constexpr bool test() {
}
}
if (!TEST_IS_CONSTANT_EVALUATED) // TODO: Use TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED when std::deque is made constexpr
test_segmented_deque_iterator();
{
std::vector<std::vector<int>> vec = {{0}, {1, 2}, {3, 4, 5}, {6, 7, 8, 9}, {10}, {11, 12, 13}};
auto v = vec | std::views::join;
std::ranges::for_each(v, [i = 0](int x) mutable { assert(x == 2 * i++); }, [](int x) { return 2 * x; });
}
return true;
}

View File

@@ -17,7 +17,12 @@
#include <algorithm>
#include <array>
#include <cassert>
#include <deque>
#include <iterator>
#include <ranges>
#include <ranges>
#include <vector>
#include "almost_satisfies_types.h"
#include "test_iterators.h"
@@ -27,7 +32,7 @@ struct Callable {
};
template <class Iter>
concept HasForEachN = requires (Iter iter) { std::ranges::for_each_n(iter, 0, Callable{}); };
concept HasForEachN = requires(Iter iter) { std::ranges::for_each_n(iter, 0, Callable{}); };
static_assert(HasForEachN<int*>);
static_assert(!HasForEachN<InputIteratorNotDerivedFrom>);
@@ -45,7 +50,7 @@ template <class Iter>
constexpr void test_iterator() {
{ // simple test
auto func = [i = 0](int& a) mutable { a += i++; };
int a[] = {1, 6, 3, 4};
int a[] = {1, 6, 3, 4};
std::same_as<std::ranges::for_each_result<Iter, decltype(func)>> auto ret =
std::ranges::for_each_n(Iter(a), 4, func);
assert(a[0] == 1);
@@ -64,6 +69,30 @@ constexpr void test_iterator() {
}
}
struct deque_test {
std::deque<int>* d_;
int* i_;
deque_test(std::deque<int>& d, int& i) : d_(&d), i_(&i) {}
void operator()(int& v) {
assert(&(*d_)[*i_] == &v);
++*i_;
}
};
/*TEST_CONSTEXPR_CXX26*/
void test_segmented_deque_iterator() { // TODO: Mark as TEST_CONSTEXPR_CXX26 once std::deque is constexpr
// check that segmented deque iterators work properly
int sizes[] = {0, 1, 2, 1023, 1024, 1025, 2047, 2048, 2049};
for (const int size : sizes) {
std::deque<int> d(size);
int index = 0;
std::ranges::for_each_n(d.begin(), d.size(), deque_test(d, index));
}
}
constexpr bool test() {
test_iterator<cpp17_input_iterator<int*>>();
test_iterator<cpp20_input_iterator<int*>>();
@@ -89,6 +118,19 @@ constexpr bool test() {
assert(a[2].other == 6);
}
if (!TEST_IS_CONSTANT_EVALUATED) // TODO: Use TEST_STD_AT_LEAST_26_OR_RUNTIME_EVALUATED when std::deque is made constexpr
test_segmented_deque_iterator();
{
std::vector<std::vector<int>> vec = {{0}, {1, 2}, {3, 4, 5}, {6, 7, 8, 9}, {10}, {11, 12, 13}};
auto v = vec | std::views::join;
std::ranges::for_each_n(
v.begin(),
std::ranges::distance(v),
[i = 0](int x) mutable { assert(x == 2 * i++); },
[](int x) { return 2 * x; });
}
return true;
}

View File

@@ -26,6 +26,7 @@
#include <vector>
#include "compare_types.h"
#include "test_macros.h"
namespace fundamentals {
static_assert(std::equality_comparable<int>);
@@ -43,7 +44,12 @@ static_assert(std::equality_comparable<unsigned char&&>);
static_assert(std::equality_comparable<unsigned short const&&>);
static_assert(std::equality_comparable<unsigned int volatile&&>);
static_assert(std::equality_comparable<unsigned long const volatile&&>);
// Array comparisons are ill-formed in C++26, but Clang doesn't implement this yet.
#if TEST_STD_VER <= 23 || defined(TEST_COMPILER_CLANG)
static_assert(std::equality_comparable<int[5]>);
#else
static_assert(!std::equality_comparable<int[5]>);
#endif
static_assert(std::equality_comparable<int (*)(int)>);
static_assert(std::equality_comparable<int (&)(int)>);
static_assert(std::equality_comparable<int (*)(int) noexcept>);

View File

@@ -107,7 +107,12 @@ static_assert(!check_equality_comparable_with < int,
int (S::*)() const volatile&& noexcept > ());
static_assert(check_equality_comparable_with<int*, int*>());
// Array comparisons are ill-formed in C++26, but Clang doesn't implement this yet.
#if TEST_STD_VER <= 23 || defined(TEST_COMPILER_CLANG)
static_assert(check_equality_comparable_with<int*, int[5]>());
#else
static_assert(!check_equality_comparable_with<int*, int[5]>());
#endif
static_assert(!check_equality_comparable_with<int*, int (*)()>());
static_assert(!check_equality_comparable_with<int*, int (&)()>());
static_assert(!check_equality_comparable_with<int*, int (S::*)()>());
@@ -148,7 +153,12 @@ static_assert(
static_assert(!check_equality_comparable_with < int*,
int (S::*)() const volatile&& noexcept > ());
// Array comparisons are ill-formed in C++26, but Clang doesn't implement this yet.
#if TEST_STD_VER <= 23 || defined(TEST_COMPILER_CLANG)
static_assert(check_equality_comparable_with<int[5], int[5]>());
#else
static_assert(!check_equality_comparable_with<int[5], int[5]>());
#endif
static_assert(!check_equality_comparable_with<int[5], int (*)()>());
static_assert(!check_equality_comparable_with<int[5], int (&)()>());
static_assert(!check_equality_comparable_with<int[5], int (S::*)()>());
@@ -942,7 +952,12 @@ static_assert(
static_assert(!check_equality_comparable_with<std::nullptr_t, int>());
static_assert(check_equality_comparable_with<std::nullptr_t, int*>());
// Array comparisons are ill-formed in C++26, but Clang doesn't implement this yet.
#if TEST_STD_VER <= 23 || defined(TEST_COMPILER_CLANG)
static_assert(check_equality_comparable_with<std::nullptr_t, int[5]>());
#else
static_assert(!check_equality_comparable_with<std::nullptr_t, int[5]>());
#endif
static_assert(check_equality_comparable_with<std::nullptr_t, int (*)()>());
static_assert(check_equality_comparable_with<std::nullptr_t, int (&)()>());
static_assert(check_equality_comparable_with<std::nullptr_t, int (S::*)()>());

View File

@@ -55,7 +55,10 @@ static_assert(models_totally_ordered<unsigned char&&>());
static_assert(models_totally_ordered<unsigned short const&&>());
static_assert(models_totally_ordered<unsigned int volatile&&>());
static_assert(models_totally_ordered<unsigned long const volatile&&>());
// Array comparisons are ill-formed in C++26
#if TEST_STD_VER <= 23
static_assert(models_totally_ordered<int[5]>());
#endif
static_assert(models_totally_ordered<int (*)(int)>());
static_assert(models_totally_ordered<int (&)(int)>());
static_assert(models_totally_ordered<int (*)(int) noexcept>());

View File

@@ -89,7 +89,12 @@ static_assert(!check_totally_ordered_with<int, int (S::*)() const volatile&&>())
static_assert(!check_totally_ordered_with < int, int (S::*)() const volatile&& noexcept > ());
static_assert(check_totally_ordered_with<int*, int*>());
// Array comparisons are ill-formed in C++26, but Clang doesn't implement this yet.
#if TEST_STD_VER <= 23 || defined(TEST_COMPILER_CLANG)
static_assert(check_totally_ordered_with<int*, int[5]>());
#else
static_assert(!check_totally_ordered_with<int*, int[5]>());
#endif
static_assert(!check_totally_ordered_with<int*, int (*)()>());
static_assert(!check_totally_ordered_with<int*, int (&)()>());
static_assert(!check_totally_ordered_with<int*, int (S::*)()>());
@@ -117,7 +122,12 @@ static_assert(!check_totally_ordered_with < int*, int (S::*)() volatile&& noexce
static_assert(!check_totally_ordered_with<int*, int (S::*)() const volatile&&>());
static_assert(!check_totally_ordered_with < int*, int (S::*)() const volatile&& noexcept > ());
// Array comparisons are ill-formed in C++26, but Clang doesn't implement this yet.
#if TEST_STD_VER <= 23 || defined(TEST_COMPILER_CLANG)
static_assert(check_totally_ordered_with<int[5], int[5]>());
#else
static_assert(!check_totally_ordered_with<int[5], int[5]>());
#endif
static_assert(!check_totally_ordered_with<int[5], int (*)()>());
static_assert(!check_totally_ordered_with<int[5], int (&)()>());
static_assert(!check_totally_ordered_with<int[5], int (S::*)()>());

View File

@@ -22,13 +22,13 @@ class Emplaceable {
double double_;
public:
TEST_CONSTEXPR Emplaceable() : int_(0), double_(0) {}
TEST_CONSTEXPR Emplaceable(int i, double d) : int_(i), double_(d) {}
TEST_CONSTEXPR_CXX14 Emplaceable(Emplaceable&& x) : int_(x.int_), double_(x.double_) {
TEST_CONSTEXPR_CXX20 Emplaceable() : int_(0), double_(0) {}
TEST_CONSTEXPR_CXX20 Emplaceable(int i, double d) : int_(i), double_(d) {}
TEST_CONSTEXPR_CXX20 Emplaceable(Emplaceable&& x) : int_(x.int_), double_(x.double_) {
x.int_ = 0;
x.double_ = 0;
}
TEST_CONSTEXPR_CXX14 Emplaceable& operator=(Emplaceable&& x) {
TEST_CONSTEXPR_CXX20 Emplaceable& operator=(Emplaceable&& x) {
int_ = x.int_;
x.int_ = 0;
double_ = x.double_;
@@ -36,12 +36,12 @@ public:
return *this;
}
TEST_CONSTEXPR bool operator==(const Emplaceable& x) const { return int_ == x.int_ && double_ == x.double_; }
TEST_CONSTEXPR bool operator<(const Emplaceable& x) const {
TEST_CONSTEXPR_CXX20 bool operator==(const Emplaceable& x) const { return int_ == x.int_ && double_ == x.double_; }
TEST_CONSTEXPR_CXX20 bool operator<(const Emplaceable& x) const {
return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);
}
TEST_CONSTEXPR int get() const { return int_; }
TEST_CONSTEXPR_CXX20 int get() const { return int_; }
};
template <>
@@ -49,7 +49,7 @@ struct std::hash<Emplaceable> {
typedef Emplaceable argument_type;
typedef std::size_t result_type;
TEST_CONSTEXPR std::size_t operator()(const Emplaceable& x) const { return static_cast<std::size_t>(x.get()); }
TEST_CONSTEXPR_CXX20 std::size_t operator()(const Emplaceable& x) const { return static_cast<std::size_t>(x.get()); }
};
#endif // TEST_STD_VER >= 11

View File

@@ -18,6 +18,7 @@
#include <flat_map>
#include <functional>
#include <stdexcept>
#include <type_traits>
#include <vector>
#include "MinSequenceContainer.h"
@@ -25,7 +26,7 @@
#include "test_macros.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using P = std::pair<int, double>;
P ar[] = {
P(1, 1.5),
@@ -49,10 +50,12 @@ void test() {
assert(m.at(4) == 4.5);
assert(m.at(5) == 5.5);
#ifndef TEST_HAS_NO_EXCEPTIONS
try {
TEST_IGNORE_NODISCARD m.at(6);
assert(false);
} catch (std::out_of_range&) {
if (!TEST_IS_CONSTANT_EVALUATED) {
try {
TEST_IGNORE_NODISCARD m.at(6);
assert(false);
} catch (std::out_of_range&) {
}
}
#endif
assert(m.at(7) == 7.5);
@@ -70,10 +73,12 @@ void test() {
assert(m.at(4) == 4.5);
assert(m.at(5) == 5.5);
#ifndef TEST_HAS_NO_EXCEPTIONS
try {
TEST_IGNORE_NODISCARD m.at(6);
assert(false);
} catch (std::out_of_range&) {
if (!TEST_IS_CONSTANT_EVALUATED) {
try {
TEST_IGNORE_NODISCARD m.at(6);
assert(false);
} catch (std::out_of_range&) {
}
}
#endif
assert(m.at(7) == 7.5);
@@ -82,11 +87,25 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -35,7 +35,7 @@ static_assert(!CanAt<NonTransparentMap>);
static_assert(!CanAt<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using P = std::pair<int, double>;
P ar[] = {
P(1, 1.5),
@@ -60,10 +60,12 @@ void test() {
assert(m.at(Transparent<int>{4}) == 4.5);
assert(m.at(Transparent<int>{5}) == 5.5);
#ifndef TEST_HAS_NO_EXCEPTIONS
try {
TEST_IGNORE_NODISCARD m.at(Transparent<int>{6});
assert(false);
} catch (std::out_of_range&) {
if (!TEST_IS_CONSTANT_EVALUATED) {
try {
TEST_IGNORE_NODISCARD m.at(Transparent<int>{6});
assert(false);
} catch (std::out_of_range&) {
}
}
#endif
assert(m.at(Transparent<int>{7}) == 7.5);
@@ -81,10 +83,12 @@ void test() {
assert(m.at(Transparent<int>{4}) == 4.5);
assert(m.at(Transparent<int>{5}) == 5.5);
#ifndef TEST_HAS_NO_EXCEPTIONS
try {
TEST_IGNORE_NODISCARD m.at(Transparent<int>{6});
assert(false);
} catch (std::out_of_range&) {
if (!TEST_IS_CONSTANT_EVALUATED) {
try {
TEST_IGNORE_NODISCARD m.at(Transparent<int>{6});
assert(false);
} catch (std::out_of_range&) {
}
}
#endif
assert(m.at(Transparent<int>{7}) == 7.5);
@@ -93,9 +97,14 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
{
@@ -114,5 +123,14 @@ int main(int, char**) {
assert(x == 1);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -16,6 +16,7 @@
#include <deque>
#include <flat_map>
#include <functional>
#include <type_traits>
#include <vector>
#include "MinSequenceContainer.h"
@@ -31,7 +32,7 @@ static_assert(CanIndex<std::flat_map<int, double>, const int&>);
static_assert(!CanIndex<std::flat_map<int, NoDefaultCtr>, const int&>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using P = std::pair<int, double>;
P ar[] = {
P(1, 1.5),
@@ -58,13 +59,18 @@ void test() {
assert(m.size() == 8);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto index_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
const typename FlatMap::key_type key = key_arg;
@@ -73,5 +79,15 @@ int main(int, char**) {
};
test_emplace_exception_guarantee(index_func);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -16,6 +16,7 @@
#include <deque>
#include <functional>
#include <cassert>
#include <type_traits>
#include "MinSequenceContainer.h"
#include "../helpers.h"
@@ -31,7 +32,7 @@ static_assert(CanIndex<std::flat_map<int, double>, int&&>);
static_assert(!CanIndex<std::flat_map<int, NoDefaultCtr>, int&&>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
{
std::flat_map<MoveOnly, double, std::less<MoveOnly>, KeyContainer, ValueContainer> m;
ASSERT_SAME_TYPE(decltype(m[MoveOnly{}]), double&);
@@ -49,13 +50,18 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<MoveOnly>, std::vector<double>>();
test<std::deque<MoveOnly>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<MoveOnly>, std::vector<double>>();
}
test<MinSequenceContainer<MoveOnly>, MinSequenceContainer<double>>();
test<std::vector<MoveOnly, min_allocator<MoveOnly>>, std::vector<double, min_allocator<double>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto index_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
typename FlatMap::key_type key = key_arg;
@@ -64,5 +70,14 @@ int main(int, char**) {
};
test_emplace_exception_guarantee(index_func);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -50,7 +50,7 @@ static_assert(!CanIndex<TransparentMap, TransparentMap::iterator>);
static_assert(!CanIndex<TransparentMap, TransparentMap::const_iterator>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using P = std::pair<int, double>;
P ar[] = {
P(1, 1.5),
@@ -81,11 +81,17 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
{
bool transparent_used = false;
TransparentComparator c(transparent_used);
@@ -101,7 +107,8 @@ int main(int, char**) {
int& x = m["alpha"];
assert(x == 1);
}
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto index_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using Key = typename FlatMap::key_type;
@@ -110,5 +117,15 @@ int main(int, char**) {
};
test_emplace_exception_guarantee(index_func);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -24,10 +24,10 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_multimap<Key, Value, std::less<int>, KeyContainer, ValueContainer>;
using M = std::flat_map<Key, Value, std::less<int>, KeyContainer, ValueContainer>;
M m;
ASSERT_SAME_TYPE(decltype(m.empty()), bool);
ASSERT_NOEXCEPT(m.empty());
@@ -39,11 +39,25 @@ void test() {
assert(m.empty());
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -24,7 +24,7 @@
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
constexpr bool test() {
{
using A1 = limited_allocator<int, 10>;
using A2 = limited_allocator<int, 20>;
@@ -72,5 +72,15 @@ int main(int, char**) {
assert(c.max_size() <= max_dist);
assert(c.max_size() <= alloc_max_size(std::allocator<char>()));
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -16,6 +16,7 @@
#include <deque>
#include <flat_map>
#include <functional>
#include <type_traits>
#include <vector>
#include "MinSequenceContainer.h"
@@ -23,7 +24,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using M = std::flat_map<int, char, std::less<int>, KeyContainer, ValueContainer>;
{
const M m = {{1, 'a'}, {1, 'b'}, {4, 'd'}, {5, 'e'}, {5, 'h'}};
@@ -45,7 +46,7 @@ void test() {
}
{
M m;
std::size_t s = 1000000;
std::size_t s = TEST_IS_CONSTANT_EVALUATED ? 100 : 1000000;
for (auto i = 0u; i < s; ++i) {
m.emplace(i, 'a');
}
@@ -55,11 +56,25 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
test<std::deque<int>, std::vector<char>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<char>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -14,6 +14,7 @@
// explicit flat_map(const Allocator& a);
#include <cassert>
#include <deque>
#include <flat_map>
#include <functional>
#include <vector>
@@ -22,7 +23,23 @@
#include "test_allocator.h"
#include "../../../test_compare.h"
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
using A = test_allocator<short>;
using M =
std::flat_map<int,
long,
std::less<int>,
KeyContainer<int, test_allocator<int>>,
ValueContainer<long, test_allocator<long>>>;
M m(A(0, 5));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.keys().get_allocator().get_id() == 5);
assert(m.values().get_allocator().get_id() == 5);
}
constexpr bool test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -53,20 +70,23 @@ int main(int, char**) {
static_assert(std::is_constructible_v<M, test_allocator<int>>);
static_assert(!std::is_convertible_v<test_allocator<int>, M>);
}
test<std::vector, std::vector>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
using A = test_allocator<short>;
using M =
std::flat_map<int,
long,
std::less<int>,
std::vector<int, test_allocator<int>>,
std::vector<long, test_allocator<long>>>;
M m(A(0, 5));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.keys().get_allocator().get_id() == 5);
assert(m.values().get_allocator().get_id() == 5);
test<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -26,7 +26,7 @@
#include "test_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -36,7 +36,6 @@ void test() {
m = {{3, 0}, {1, 0}, {2, 0}, {2, 1}, {3, 1}, {4, 0}, {3, 2}, {5, 0}, {6, 0}, {5, 1}};
std::pair<int, int> expected[] = {{1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0}, {6, 0}};
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
}
{
M m = {{10, 1}, {8, 1}};
@@ -47,13 +46,28 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<int>>();
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -20,11 +20,73 @@
#include <type_traits>
#include <vector>
#include "MinSequenceContainer.h"
#include "min_allocator.h"
#include "test_macros.h"
#include "../../../test_compare.h"
#include "test_allocator.h"
int main(int, char**) {
// explicit flat_map(const key_compare& comp);
template <class KeyContainer, class ValueContainer>
constexpr void test_compare() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
{
// The one-argument ctor is explicit.
using C = test_less<Key>;
static_assert(std::is_constructible_v<std::flat_map<Key, Value, C>, C>);
static_assert(!std::is_convertible_v<C, std::flat_map<Key, Value, C>>);
static_assert(std::is_constructible_v<std::flat_map<Key, Value>, std::less<Key>>);
static_assert(!std::is_convertible_v<std::less<Key>, std::flat_map<Key, Value>>);
}
{
using C = test_less<Key>;
auto m = std::flat_map<Key, Value, C>(C(3));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(3));
}
}
// template <class Alloc>
// flat_map(const key_compare& comp, const Alloc& a);
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test_compare_alloc() {
{
// If an allocator is given, it must be usable by both containers.
using A = test_allocator<int>;
using M = std::flat_map<int, int, std::less<>, KeyContainer<int>, ValueContainer<int, A>>;
static_assert(std::is_constructible_v<M, std::less<>>);
static_assert(!std::is_constructible_v<M, std::less<>, std::allocator<int>>);
static_assert(!std::is_constructible_v<M, std::less<>, A>);
}
{
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
auto m = std::flat_map<int, short, C, KeyContainer<int, A1>, ValueContainer<short, A2>>(C(4), A1(5));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(4));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// explicit(false)
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
std::flat_map<int, short, C, KeyContainer<int, A1>, ValueContainer<short, A2>> m = {C(4), A1(5)};
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(4));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
}
constexpr bool test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -41,53 +103,31 @@ int main(int, char**) {
static_assert(!std::is_constructible_v<M2, const C&, const A2&>);
static_assert(!std::is_constructible_v<M3, const C&, const A2&>);
}
{
using C = test_less<int>;
auto m = std::flat_map<int, char*, C>(C(3));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(3));
}
{
// The one-argument ctor is explicit.
using C = test_less<int>;
static_assert(std::is_constructible_v<std::flat_map<int, char*, C>, C>);
static_assert(!std::is_convertible_v<C, std::flat_map<int, char*, C>>);
static_assert(std::is_constructible_v<std::flat_map<int, char*>, std::less<int>>);
static_assert(!std::is_convertible_v<std::less<int>, std::flat_map<int, char*>>);
}
test_compare<std::vector<int>, std::vector<int>>();
test_compare<std::vector<int>, std::vector<double>>();
test_compare<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test_compare<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test_compare<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
test_compare_alloc<std::vector, std::vector>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
auto m = std::flat_map<int, short, C, std::vector<int, A1>, std::vector<short, A2>>(C(4), A1(5));
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(4));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// explicit(false)
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
std::flat_map<int, short, C, std::deque<int, A1>, std::deque<short, A2>> m = {C(4), A1(5)};
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp() == C(4));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// If an allocator is given, it must be usable by both containers.
using A = test_allocator<int>;
using M = std::flat_map<int, int, std::less<>, std::vector<int>, std::vector<int, A>>;
static_assert(std::is_constructible_v<M, std::less<>>);
static_assert(!std::is_constructible_v<M, std::less<>, std::allocator<int>>);
static_assert(!std::is_constructible_v<M, std::less<>, A>);
test_compare<std::deque<int>, std::vector<double>>();
test_compare_alloc<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -30,18 +30,162 @@
#include "test_allocator.h"
#include "test_iterators.h"
#include "test_macros.h"
#include "../helpers.h"
#include "../../../test_compare.h"
struct P {
int first;
int second;
template <class T, class U>
bool operator==(const std::pair<T, U>& rhs) const {
constexpr bool operator==(const std::pair<T, U>& rhs) const {
return MoveOnly(first) == rhs.first && MoveOnly(second) == rhs.second;
}
};
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
{
// flat_map(key_container_type , mapped_container_type)
using M = std::flat_map<int, short, std::less<int>, KeyContainer<int>, ValueContainer<short>>;
KeyContainer<int> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
ValueContainer<short> vs = {1, 2, 3, 4, 5, 6, 7, 8, 9};
auto m = M(ks, vs);
assert((m.keys() == KeyContainer<int>{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<short>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
// explicit(false)
M m2 = {ks, vs};
assert(m2 == m);
m = M(std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m.keys() == KeyContainer<int>{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<short>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
}
{
// flat_map(key_container_type , mapped_container_type)
// move-only
P expected[] = {{3, 2}, {2, 1}, {1, 3}};
using Ks = KeyContainer<int, min_allocator<int>>;
using Vs = ValueContainer<MoveOnly, min_allocator<MoveOnly>>;
using M = std::flat_map<int, MoveOnly, std::greater<int>, Ks, Vs>;
Ks ks = {1, 3, 2};
Vs vs;
vs.push_back(3);
vs.push_back(2);
vs.push_back(1);
auto m = M(std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert(std::ranges::equal(m, expected, std::equal_to<>()));
}
{
// flat_map(key_container_type , mapped_container_type)
// container's allocators are used
using A = test_allocator<int>;
using M = std::flat_map<int, int, std::less<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
auto ks = KeyContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
auto vs = ValueContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(6));
auto m = M(std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 1}, {2, 2}, {3, 3}}));
assert(m.keys().get_allocator() == A(5));
assert(m.values().get_allocator() == A(6));
}
{
// flat_map(key_container_type , mapped_container_type, key_compare)
using C = test_less<int>;
using M = std::flat_map<int, char, C, KeyContainer<int>, ValueContainer<char>>;
KeyContainer<int> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
ValueContainer<char> vs = {1, 2, 3, 4, 5, 6, 7, 8, 9};
auto m = M(ks, vs, C(4));
assert((m.keys() == KeyContainer<int>{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<char>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
assert(m.key_comp() == C(4));
// explicit(false)
M m2 = {ks, vs, C(4)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
}
{
// flat_map(key_container_type , mapped_container_type, const Allocator&)
using A = test_allocator<int>;
using M = std::flat_map<int, int, std::less<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
auto ks = KeyContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
auto vs = ValueContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(6));
auto m = M(ks, vs, A(4)); // replaces the allocators
assert(!ks.empty()); // it was an lvalue above
assert(!vs.empty()); // it was an lvalue above
assert((m == M{{1, 1}, {2, 2}, {3, 3}}));
assert(m.keys().get_allocator() == A(4));
assert(m.values().get_allocator() == A(4));
}
{
// flat_map(key_container_type , mapped_container_type, const Allocator&)
// explicit(false)
using A = test_allocator<int>;
using M = std::flat_map<int, int, std::less<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
auto ks = KeyContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
auto vs = ValueContainer<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(6));
M m = {ks, vs, A(4)}; // implicit ctor
assert(!ks.empty()); // it was an lvalue above
assert(!vs.empty()); // it was an lvalue above
assert((m == M{{1, 1}, {2, 2}, {3, 3}}));
assert(m.keys().get_allocator() == A(4));
assert(m.values().get_allocator() == A(4));
}
{
// flat_map(key_container_type , mapped_container_type, key_compare, const Allocator&)
using C = test_less<int>;
using A = test_allocator<int>;
using M = std::flat_map<int, int, C, std::vector<int, A>, std::vector<int, A>>;
std::vector<int, A> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
std::vector<int, A> vs = {1, 2, 3, 4, 5, 6, 7, 8, 9};
auto m = M(ks, vs, C(4), A(5));
assert((m.keys() == std::vector<int, A>{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<int>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
assert(m.key_comp() == C(4));
assert(m.keys().get_allocator() == A(5));
assert(m.values().get_allocator() == A(5));
// explicit(false)
M m2 = {ks, vs, C(4), A(5)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
assert(m2.keys().get_allocator() == A(5));
assert(m2.values().get_allocator() == A(5));
}
}
bool constexpr test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -65,120 +209,25 @@ int main(int, char**) {
static_assert(!std::is_constructible_v<M2, const V1&, const V2&, const C&, const A2&>);
static_assert(!std::is_constructible_v<M3, const V2&, const V1&, const C&, const A2&>);
}
{
// flat_map(key_container_type , mapped_container_type)
using M = std::flat_map<int, char>;
std::vector<int> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
std::vector<char> vs = {1, 2, 3, 4, 5, 6, 7, 8, 9};
auto m = M(ks, vs);
assert((m.keys() == std::vector<int>{1, 2, 3}));
LIBCPP_ASSERT((m.values() == std::vector<char>{1, 4, 6}));
// explicit(false)
M m2 = {ks, vs};
assert(m2 == m);
test<std::vector, std::vector>();
m = M(std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m.keys() == std::vector<int>{1, 2, 3}));
LIBCPP_ASSERT((m.values() == std::vector<char>{1, 4, 6}));
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// flat_map(key_container_type , mapped_container_type)
// move-only
P expected[] = {{3, 2}, {2, 1}, {1, 3}};
using Ks = std::deque<int, min_allocator<int>>;
using Vs = std::vector<MoveOnly, min_allocator<MoveOnly>>;
using M = std::flat_map<int, MoveOnly, std::greater<int>, Ks, Vs>;
Ks ks = {1, 3, 2};
Vs vs;
vs.push_back(3);
vs.push_back(2);
vs.push_back(1);
auto m = M(std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert(std::ranges::equal(m, expected, std::equal_to<>()));
test<std::deque, std::vector>();
test<std::deque, std::deque>();
}
{
// flat_map(key_container_type , mapped_container_type)
// container's allocators are used
using A = test_allocator<int>;
using M = std::flat_map<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
auto ks = std::vector<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
auto vs = std::deque<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(6));
auto m = M(std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 1}, {2, 2}, {3, 3}}));
assert(m.keys().get_allocator() == A(5));
assert(m.values().get_allocator() == A(6));
}
{
// flat_map(key_container_type , mapped_container_type, key_compare)
using C = test_less<int>;
using M = std::flat_map<int, char, C>;
std::vector<int> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
std::vector<char> vs = {1, 2, 3, 4, 5, 6, 7, 8, 9};
auto m = M(ks, vs, C(4));
assert((m.keys() == std::vector<int>{1, 2, 3}));
LIBCPP_ASSERT((m.values() == std::vector<char>{1, 4, 6}));
assert(m.key_comp() == C(4));
// explicit(false)
M m2 = {ks, vs, C(4)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
}
{
// flat_map(key_container_type , mapped_container_type, const Allocator&)
using A = test_allocator<int>;
using M = std::flat_map<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
auto ks = std::vector<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
auto vs = std::deque<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(6));
auto m = M(ks, vs, A(4)); // replaces the allocators
assert(!ks.empty()); // it was an lvalue above
assert(!vs.empty()); // it was an lvalue above
assert((m == M{{1, 1}, {2, 2}, {3, 3}}));
assert(m.keys().get_allocator() == A(4));
assert(m.values().get_allocator() == A(4));
}
{
// flat_map(key_container_type , mapped_container_type, const Allocator&)
// explicit(false)
using A = test_allocator<int>;
using M = std::flat_map<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
auto ks = std::vector<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(5));
auto vs = std::deque<int, A>({1, 1, 1, 2, 2, 3, 2, 3, 3}, A(6));
M m = {ks, vs, A(4)}; // implicit ctor
assert(!ks.empty()); // it was an lvalue above
assert(!vs.empty()); // it was an lvalue above
assert((m == M{{1, 1}, {2, 2}, {3, 3}}));
assert(m.keys().get_allocator() == A(4));
assert(m.values().get_allocator() == A(4));
}
{
// flat_map(key_container_type , mapped_container_type, key_compare, const Allocator&)
using C = test_less<int>;
using A = test_allocator<int>;
using M = std::flat_map<int, int, C, std::vector<int, A>, std::vector<int, A>>;
std::vector<int, A> ks = {1, 1, 1, 2, 2, 3, 2, 3, 3};
std::vector<int, A> vs = {1, 2, 3, 4, 5, 6, 7, 8, 9};
auto m = M(ks, vs, C(4), A(5));
assert((m.keys() == std::vector<int, A>{1, 2, 3}));
LIBCPP_ASSERT((m.values() == std::vector<int, A>{1, 4, 6}));
assert(m.key_comp() == C(4));
assert(m.keys().get_allocator() == A(5));
assert(m.values().get_allocator() == A(5));
return true;
}
// explicit(false)
M m2 = {ks, vs, C(4), A(5)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
assert(m2.keys().get_allocator() == A(5));
assert(m2.values().get_allocator() == A(5));
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -13,6 +13,7 @@
// flat_map(const flat_map& m);
#include <cassert>
#include <deque>
#include <flat_map>
#include <vector>
@@ -20,11 +21,12 @@
#include "../../../test_compare.h"
#include "test_allocator.h"
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
{
using C = test_less<int>;
std::vector<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
std::vector<char, test_allocator<char>> vs({2, 2, 1}, test_allocator<char>(7));
KeyContainer<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
ValueContainer<char, test_allocator<char>> vs({2, 2, 1}, test_allocator<char>(7));
using M = std::flat_map<int, char, C, decltype(ks), decltype(vs)>;
auto mo = M(ks, vs, C(5));
auto m = mo;
@@ -44,8 +46,8 @@ int main(int, char**) {
}
{
using C = test_less<int>;
using Ks = std::vector<int, other_allocator<int>>;
using Vs = std::vector<char, other_allocator<char>>;
using Ks = KeyContainer<int, other_allocator<int>>;
using Vs = ValueContainer<char, other_allocator<char>>;
auto ks = Ks({1, 3, 5}, other_allocator<int>(6));
auto vs = Vs({2, 2, 1}, other_allocator<char>(7));
using M = std::flat_map<int, char, C, Ks, Vs>;
@@ -65,6 +67,26 @@ int main(int, char**) {
assert(mo.keys().get_allocator() == other_allocator<int>(6));
assert(mo.values().get_allocator() == other_allocator<char>(7));
}
}
constexpr bool test() {
test<std::vector, std::vector>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -22,7 +22,30 @@
#include "../../../test_compare.h"
#include "test_allocator.h"
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
using C = test_less<int>;
KeyContainer<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
ValueContainer<char, test_allocator<char>> vs({2, 2, 1}, test_allocator<char>(7));
using M = std::flat_map<int, char, C, decltype(ks), decltype(vs)>;
auto mo = M(ks, vs, C(5));
auto m = M(mo, test_allocator<int>(3));
assert(m.key_comp() == C(5));
assert(m.keys() == ks);
assert(m.values() == vs);
assert(m.keys().get_allocator() == test_allocator<int>(3));
assert(m.values().get_allocator() == test_allocator<char>(3));
// mo is unchanged
assert(mo.key_comp() == C(5));
assert(mo.keys() == ks);
assert(mo.values() == vs);
assert(mo.keys().get_allocator() == test_allocator<int>(6));
assert(mo.values().get_allocator() == test_allocator<char>(7));
}
constexpr bool test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -41,27 +64,24 @@ int main(int, char**) {
static_assert(!std::is_constructible_v<M2, const M2&, const A2&>);
static_assert(!std::is_constructible_v<M3, const M3&, const A2&>);
}
test<std::vector, std::vector>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
using C = test_less<int>;
std::vector<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
std::vector<char, test_allocator<char>> vs({2, 2, 1}, test_allocator<char>(7));
using M = std::flat_map<int, char, C, decltype(ks), decltype(vs)>;
auto mo = M(ks, vs, C(5));
auto m = M(mo, test_allocator<int>(3));
assert(m.key_comp() == C(5));
assert(m.keys() == ks);
assert(m.values() == vs);
assert(m.keys().get_allocator() == test_allocator<int>(3));
assert(m.values().get_allocator() == test_allocator<char>(3));
// mo is unchanged
assert(mo.key_comp() == C(5));
assert(mo.keys() == ks);
assert(mo.values() == vs);
assert(mo.keys().get_allocator() == test_allocator<int>(6));
assert(mo.values().get_allocator() == test_allocator<char>(7));
test<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -15,18 +15,20 @@
#include <deque>
#include <flat_map>
#include <functional>
#include <type_traits>
#include <vector>
#include "test_macros.h"
#include "../../../test_compare.h"
#include "test_allocator.h"
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
{
// test_allocator is not propagated
using C = test_less<int>;
std::vector<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
std::vector<char, test_allocator<char>> vs({2, 2, 1}, test_allocator<char>(7));
KeyContainer<int, test_allocator<int>> ks({1, 3, 5}, test_allocator<int>(6));
ValueContainer<char, test_allocator<char>> vs({2, 2, 1}, test_allocator<char>(7));
using M = std::flat_map<int, char, C, decltype(ks), decltype(vs)>;
auto mo = M(ks, vs, C(5));
auto m = M({{3, 3}, {4, 4}, {5, 5}}, C(3), test_allocator<int>(2));
@@ -48,8 +50,8 @@ int main(int, char**) {
{
// other_allocator is propagated
using C = test_less<int>;
using Ks = std::vector<int, other_allocator<int>>;
using Vs = std::vector<char, other_allocator<char>>;
using Ks = KeyContainer<int, other_allocator<int>>;
using Vs = ValueContainer<char, other_allocator<char>>;
auto ks = Ks({1, 3, 5}, other_allocator<int>(6));
auto vs = Vs({2, 2, 1}, other_allocator<char>(7));
using M = std::flat_map<int, char, C, Ks, Vs>;
@@ -70,7 +72,7 @@ int main(int, char**) {
assert(mo.keys().get_allocator() == other_allocator<int>(6));
assert(mo.values().get_allocator() == other_allocator<char>(7));
}
{
if (!TEST_IS_CONSTANT_EVALUATED) {
// comparator is copied and invariant is preserved
using M = std::flat_map<int, int, std::function<bool(int, int)>>;
M mo = M({{1, 2}, {3, 4}}, std::less<int>());
@@ -88,5 +90,26 @@ int main(int, char**) {
m = static_cast<const M&>(m);
assert((m == M{{1, 2}, {3, 4}}));
}
}
constexpr bool test() {
test<std::vector, std::vector>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -24,23 +24,24 @@
#include "test_allocator.h"
struct DefaultCtableComp {
explicit DefaultCtableComp() { default_constructed_ = true; }
bool operator()(int, int) const { return false; }
constexpr explicit DefaultCtableComp() { default_constructed_ = true; }
constexpr bool operator()(int, int) const { return false; }
bool default_constructed_ = false;
};
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
{
std::flat_map<int, char*> m;
std::flat_map<int, char*, std::less<int>, KeyContainer<int>, ValueContainer<char*>> m;
assert(m.empty());
}
{
// explicit(false)
std::flat_map<int, char*> m = {};
std::flat_map<int, char*, std::less<int>, KeyContainer<int>, ValueContainer<char*>> m = {};
assert(m.empty());
}
{
std::flat_map<int, char*, DefaultCtableComp, std::deque<int, min_allocator<int>>> m;
std::flat_map<int, char*, DefaultCtableComp, KeyContainer<int, min_allocator<int>>> m;
assert(m.empty());
assert(m.begin() == m.end());
assert(m.key_comp().default_constructed_);
@@ -49,13 +50,13 @@ int main(int, char**) {
using A1 = explicit_allocator<int>;
using A2 = explicit_allocator<char*>;
{
std::flat_map<int, char*, DefaultCtableComp, std::vector<int, A1>, std::vector<char*, A2>> m;
std::flat_map<int, char*, DefaultCtableComp, KeyContainer<int, A1>, ValueContainer<char*, A2>> m;
assert(m.empty());
assert(m.key_comp().default_constructed_);
}
{
A1 a1;
std::flat_map<int, int, DefaultCtableComp, std::vector<int, A1>, std::vector<int, A1>> m(a1);
std::flat_map<int, int, DefaultCtableComp, KeyContainer<int, A1>, ValueContainer<int, A1>> m(a1);
assert(m.empty());
assert(m.key_comp().default_constructed_);
}
@@ -63,10 +64,31 @@ int main(int, char**) {
{
// If an allocator is given, it must be usable by both containers.
using A = test_allocator<int>;
using M = std::flat_map<int, int, std::less<>, std::vector<int>, std::vector<int, A>>;
using M = std::flat_map<int, int, std::less<>, KeyContainer<int>, ValueContainer<int, A>>;
static_assert(std::is_constructible_v<M>);
static_assert(!std::is_constructible_v<M, std::allocator<int>>);
static_assert(!std::is_constructible_v<M, A>);
}
}
constexpr bool test() {
test<std::vector, std::vector>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -28,11 +28,11 @@
#include "test_allocator.h"
struct ThrowingCtorComp {
ThrowingCtorComp() noexcept(false) {}
bool operator()(const auto&, const auto&) const { return false; }
constexpr ThrowingCtorComp() noexcept(false) {}
constexpr bool operator()(const auto&, const auto&) const { return false; }
};
int main(int, char**) {
constexpr bool test() {
#if defined(_LIBCPP_VERSION)
{
using C = std::flat_map<MoveOnly, MoveOnly>;
@@ -55,5 +55,15 @@ int main(int, char**) {
static_assert(!std::is_nothrow_default_constructible_v<C>);
C c;
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -23,35 +23,58 @@
#include "test_allocator.h"
struct ThrowingDtorComp {
bool operator()(const auto&, const auto&) const;
~ThrowingDtorComp() noexcept(false) {}
constexpr bool operator()(const auto&, const auto&) const;
constexpr ~ThrowingDtorComp() noexcept(false) {}
};
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
{
using C = std::flat_map<MoveOnly, MoveOnly>;
using C = std::flat_map<MoveOnly, MoveOnly, std::less<MoveOnly>, KeyContainer<MoveOnly>, ValueContainer<MoveOnly>>;
static_assert(std::is_nothrow_destructible_v<C>);
C c;
}
{
using V = std::vector<MoveOnly, test_allocator<MoveOnly>>;
using C = std::flat_map<MoveOnly, MoveOnly, std::less<MoveOnly>, V, V>;
using V = KeyContainer<MoveOnly, test_allocator<MoveOnly>>;
using V2 = ValueContainer<MoveOnly, test_allocator<MoveOnly>>;
using C = std::flat_map<MoveOnly, MoveOnly, std::less<MoveOnly>, V, V2>;
static_assert(std::is_nothrow_destructible_v<C>);
C c;
}
{
using V = std::deque<MoveOnly, other_allocator<MoveOnly>>;
using C = std::flat_map<MoveOnly, MoveOnly, std::greater<MoveOnly>, V, V>;
using V = KeyContainer<MoveOnly, test_allocator<MoveOnly>>;
using V2 = ValueContainer<MoveOnly, test_allocator<MoveOnly>>;
using C = std::flat_map<MoveOnly, MoveOnly, std::greater<MoveOnly>, V, V2>;
static_assert(std::is_nothrow_destructible_v<C>);
C c;
}
#if defined(_LIBCPP_VERSION)
{
using C = std::flat_map<MoveOnly, MoveOnly, ThrowingDtorComp>;
using C = std::flat_map<MoveOnly, MoveOnly, ThrowingDtorComp, KeyContainer<MoveOnly>, ValueContainer<MoveOnly>>;
static_assert(!std::is_nothrow_destructible_v<C>);
C c;
}
#endif // _LIBCPP_VERSION
}
constexpr bool test() {
test<std::vector, std::vector>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -30,12 +30,84 @@
#include "../../../test_compare.h"
struct DefaultCtableComp {
explicit DefaultCtableComp() { default_constructed_ = true; }
bool operator()(int, int) const { return false; }
constexpr explicit DefaultCtableComp() { default_constructed_ = true; }
constexpr bool operator()(int, int) const { return false; }
bool default_constructed_ = false;
};
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
std::pair<int, short> expected[] = {{1, 1}, {2, 2}, {3, 3}, {5, 2}};
{
// flat_map(initializer_list<value_type>);
using M = std::flat_map<int, short>;
std::initializer_list<std::pair<int, short>> il = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
M m(il);
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
}
{
// flat_map(initializer_list<value_type>);
// explicit(false)
using M = std::flat_map<int, short>;
M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
}
{
// flat_map(initializer_list<value_type>);
using M = std::flat_map<int, short, std::greater<int>, KeyContainer<int, min_allocator<int>>>;
M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
}
{
// flat_map(initializer_list<value_type>);
// different comparator
using A = explicit_allocator<int>;
using M = std::flat_map<int, int, DefaultCtableComp, KeyContainer<int, A>, ValueContainer<int, A>>;
M m = {{1, 1}, {2, 2}, {3, 3}};
assert(m.size() == 1);
assert(m.begin()->first == m.begin()->second);
assert(m.key_comp().default_constructed_);
}
{
// flat_map(initializer_list<value_type>, const Allocator&);
using A = explicit_allocator<int>;
using M = std::flat_map<int, int, std::greater<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
A a;
M m({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, a);
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
}
{
// flat_map(initializer_list<value_type>, const key_compare&);
using C = test_less<int>;
using M = std::flat_map<int, short, C>;
auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10));
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
assert(m.key_comp() == C(10));
// explicit(false)
M m2 = {{{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10)};
assert(m2 == m);
assert(m2.key_comp() == C(10));
}
if (!TEST_IS_CONSTANT_EVALUATED) {
// flat_map(initializer_list<value_type>, const key_compare&);
// Sorting uses the comparator that was passed in
using M = std::flat_map<int, short, std::function<bool(int, int)>, KeyContainer<int, min_allocator<int>>>;
auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, std::greater<int>());
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
assert(m.key_comp()(2, 1) == true);
}
{
// flat_map(initializer_list<value_type> il, const key_compare& comp, const Alloc& a);
using A = explicit_allocator<int>;
using M = std::flat_map<int, int, std::greater<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
A a;
M m({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, {}, a);
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
}
}
constexpr bool test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -82,76 +154,23 @@ int main(int, char**) {
!std::is_constructible_v<M, std::initializer_list<std::pair<const int, const short>>, std::allocator<int>>);
}
std::pair<int, short> expected[] = {{1, 1}, {2, 2}, {3, 3}, {5, 2}};
{
// flat_map(initializer_list<value_type>);
using M = std::flat_map<int, short>;
std::initializer_list<std::pair<int, short>> il = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
M m(il);
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
}
{
// flat_map(initializer_list<value_type>);
// explicit(false)
using M = std::flat_map<int, short>;
M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
}
{
// flat_map(initializer_list<value_type>);
using M = std::flat_map<int, short, std::greater<int>, std::deque<int, min_allocator<int>>>;
M m = {{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}};
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
}
{
using A = explicit_allocator<int>;
{
// flat_map(initializer_list<value_type>);
// different comparator
using M = std::flat_map<int, int, DefaultCtableComp, std::vector<int, A>, std::deque<int, A>>;
M m = {{1, 1}, {2, 2}, {3, 3}};
assert(m.size() == 1);
assert(m.begin()->first == m.begin()->second);
LIBCPP_ASSERT(*m.begin() == std::make_pair(1, 1));
assert(m.key_comp().default_constructed_);
}
{
// flat_map(initializer_list<value_type>, const Allocator&);
using M = std::flat_map<int, int, std::greater<int>, std::deque<int, A>, std::vector<int, A>>;
A a;
M m({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, a);
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
}
}
{
// flat_map(initializer_list<value_type>, const key_compare&);
using C = test_less<int>;
using M = std::flat_map<int, short, C>;
auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10));
assert(std::equal(m.begin(), m.end(), expected, expected + 4));
assert(m.key_comp() == C(10));
test<std::vector, std::vector>();
// explicit(false)
M m2 = {{{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, C(10)};
assert(m2 == m);
assert(m2.key_comp() == C(10));
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// flat_map(initializer_list<value_type>, const key_compare&);
// Sorting uses the comparator that was passed in
using M = std::flat_map<int, short, std::function<bool(int, int)>, std::deque<int, min_allocator<int>>>;
auto m = M({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, std::greater<int>());
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
assert(m.key_comp()(2, 1) == true);
}
{
// flat_map(initializer_list<value_type> il, const key_compare& comp, const Alloc& a);
using A = explicit_allocator<int>;
using M = std::flat_map<int, int, std::greater<int>, std::deque<int, A>, std::vector<int, A>>;
A a;
M m({{5, 2}, {2, 2}, {2, 2}, {3, 3}, {1, 1}, {3, 3}}, {}, a);
assert(std::equal(m.rbegin(), m.rend(), expected, expected + 4));
test<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -22,14 +22,163 @@
#include <flat_map>
#include <functional>
#include <vector>
#include <ranges>
#include "MinSequenceContainer.h"
#include "min_allocator.h"
#include "test_allocator.h"
#include "test_iterators.h"
#include "test_macros.h"
#include "../helpers.h"
#include "../../../test_compare.h"
int main(int, char**) {
template <class KeyContainer, class ValueContainer>
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using P = std::pair<Key, Value>;
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
{
// flat_map(InputIterator , InputIterator)
// cpp17_input_iterator
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
auto m = M(cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 9));
assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<Value>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
// explicit(false)
M m2 = {cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 9)};
assert(m2 == m);
}
{
// flat_map(InputIterator , InputIterator)
// greater
using M = std::flat_map<Key, Value, std::greater<Key>, KeyContainer, ValueContainer>;
auto m = M(cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 9));
assert(std::ranges::equal(m.keys(), KeyContainer{3, 2, 1}));
check_possible_values(
m.values(),
std::vector<std::vector<Value>>{
{6, 8, 9},
{4, 5, 7},
{1, 2, 3},
});
}
{
// flat_map(InputIterator , InputIterator)
// Test when the operands are of array type (also contiguous iterator type)
using M = std::flat_map<Key, Value, std::greater<Key>, KeyContainer, ValueContainer>;
auto m = M(ar, ar);
assert(m.empty());
}
{
// flat_map(InputIterator , InputIterator, const key_compare&)
using C = test_less<Key>;
using M = std::flat_map<Key, Value, C, KeyContainer, ValueContainer>;
auto m = M(ar, ar + 9, C(3));
assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<Value>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
assert(m.key_comp() == C(3));
// explicit(false)
M m2 = {ar, ar + 9, C(3)};
assert(m2 == m);
assert(m2.key_comp() == C(3));
}
}
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test_alloc() {
using P = std::pair<int, short>;
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
{
// flat_map(InputIterator , InputIterator, const Allocator&)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
auto m = M(ar, ar + 9, A1(5));
assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<short>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(InputIterator , InputIterator, const Allocator&)
// explicit(false)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
M m = {ar, ar + 9, A1(5)}; // implicit ctor
assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<short>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(InputIterator , InputIterator, const key_compare&, const Allocator&)
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, C, KeyContainer<int, A1>, ValueContainer<short, A2>>;
auto m = M(ar, ar + 9, C(3), A1(5));
assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<short>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
assert(m.key_comp() == C(3));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(InputIterator , InputIterator, const key_compare&, const Allocator&)
// explicit(false)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
M m = {ar, ar + 9, {}, A2(5)}; // implicit ctor
assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<short>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
}
constexpr bool test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -57,98 +206,30 @@ int main(int, char**) {
static_assert(!std::is_constructible_v<M3, Iter3, Iter3, const C&, const A2&>);
}
using P = std::pair<int, short>;
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
P expected[] = {{1, 1}, {2, 4}, {3, 6}};
{
// flat_map(InputIterator , InputIterator)
// cpp17_input_iterator
using M = std::flat_map<int, short>;
auto m = M(cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 9));
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
test<std::vector<int>, std::vector<int>>();
test<std::vector<int>, std::vector<double>>();
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
// explicit(false)
M m2 = {cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 9)};
assert(m2 == m);
}
{
// flat_map(InputIterator , InputIterator)
// greater
using M = std::flat_map<int, short, std::greater<int>, std::deque<int, min_allocator<int>>, std::deque<short>>;
auto m = M(cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 9));
assert((m.keys() == std::deque<int, min_allocator<int>>{3, 2, 1}));
LIBCPP_ASSERT((m.values() == std::deque<short>{6, 4, 1}));
}
{
// flat_map(InputIterator , InputIterator)
// Test when the operands are of array type (also contiguous iterator type)
using M = std::flat_map<int, short, std::greater<int>, std::vector<int, min_allocator<int>>>;
auto m = M(ar, ar);
assert(m.empty());
}
{
// flat_map(InputIterator , InputIterator, const key_compare&)
using C = test_less<int>;
using M = std::flat_map<int, short, C, std::vector<int>, std::deque<short>>;
auto m = M(ar, ar + 9, C(3));
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
assert(m.key_comp() == C(3));
test_alloc<std::vector, std::vector>();
// explicit(false)
M m2 = {ar, ar + 9, C(3)};
assert(m2 == m);
assert(m2.key_comp() == C(3));
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// flat_map(InputIterator , InputIterator, const Allocator&)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
auto m = M(ar, ar + 9, A1(5));
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(InputIterator , InputIterator, const Allocator&)
// explicit(false)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
M m = {ar, ar + 9, A1(5)}; // implicit ctor
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(InputIterator , InputIterator, const key_compare&, const Allocator&)
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, C, std::vector<int, A1>, std::deque<short, A2>>;
auto m = M(ar, ar + 9, C(3), A1(5));
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
assert(m.key_comp() == C(3));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(InputIterator , InputIterator, const key_compare&, const Allocator&)
// explicit(false)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, std::deque<int, A1>, std::vector<short, A2>>;
M m = {ar, ar + 9, {}, A2(5)}; // implicit ctor
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
test<std::deque<int>, std::vector<double>>();
test_alloc<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -16,6 +16,7 @@
#include <deque>
#include <flat_map>
#include <functional>
#include <type_traits>
#include <utility>
#include <vector>
@@ -25,11 +26,12 @@
#include "test_allocator.h"
#include "min_allocator.h"
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
{
using C = test_less<int>;
using A = test_allocator<int>;
using M = std::flat_map<int, int, C, std::vector<int, A>, std::deque<int, A>>;
using M = std::flat_map<int, int, C, KeyContainer<int, A>, ValueContainer<int, A>>;
M mo = M({{1, 1}, {2, 2}, {3, 1}}, C(5), A(7));
M m = std::move(mo);
assert((m == M{{1, 1}, {2, 2}, {3, 1}}));
@@ -45,7 +47,7 @@ int main(int, char**) {
{
using C = test_less<int>;
using A = min_allocator<int>;
using M = std::flat_map<int, int, C, std::vector<int, A>, std::deque<int, A>>;
using M = std::flat_map<int, int, C, KeyContainer<int, A>, ValueContainer<int, A>>;
M mo = M({{1, 1}, {2, 2}, {3, 1}}, C(5), A());
M m = std::move(mo);
assert((m == M{{1, 1}, {2, 2}, {3, 1}}));
@@ -58,9 +60,9 @@ int main(int, char**) {
assert(m.keys().get_allocator() == A());
assert(m.values().get_allocator() == A());
}
{
if (!TEST_IS_CONSTANT_EVALUATED) {
// A moved-from flat_map maintains its class invariant in the presence of moved-from comparators.
using M = std::flat_map<int, int, std::function<bool(int, int)>>;
using M = std::flat_map<int, int, std::function<bool(int, int)>, KeyContainer<int>, ValueContainer<int>>;
M mo = M({{1, 1}, {2, 2}, {3, 1}}, std::less<int>());
M m = std::move(mo);
assert(m.size() == 3);
@@ -75,7 +77,7 @@ int main(int, char**) {
}
{
// moved-from object maintains invariant if one of underlying container does not clear after move
using M = std::flat_map<int, int, std::less<>, std::vector<int>, CopyOnlyVector<int>>;
using M = std::flat_map<int, int, std::less<>, KeyContainer<int>, CopyOnlyVector<int>>;
M m1 = M({1, 2, 3}, {1, 2, 3});
M m2 = std::move(m1);
assert(m2.size() == 3);
@@ -84,5 +86,26 @@ int main(int, char**) {
LIBCPP_ASSERT(m1.keys().size() == 0);
LIBCPP_ASSERT(m1.values().size() == 0);
}
}
constexpr bool test() {
test<std::vector, std::vector>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -24,30 +24,13 @@
#include "../../../test_compare.h"
#include "test_allocator.h"
int main(int, char**) {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
// and uses_allocator_v<mapped_container_type, Alloc> is true.
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = other_allocator<int>;
using V1 = std::vector<int, A1>;
using V2 = std::vector<int, A2>;
using M1 = std::flat_map<int, int, C, V1, V1>;
using M2 = std::flat_map<int, int, C, V1, V2>;
using M3 = std::flat_map<int, int, C, V2, V1>;
static_assert(std::is_constructible_v<M1, M1&&, const A1&>);
static_assert(!std::is_constructible_v<M1, M1&&, const A2&>);
static_assert(!std::is_constructible_v<M2, M2&&, const A2&>);
static_assert(!std::is_constructible_v<M3, M3&&, const A2&>);
}
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
{
std::pair<int, int> expected[] = {{1, 1}, {2, 2}, {3, 1}};
using C = test_less<int>;
using A = test_allocator<int>;
using M = std::flat_map<int, int, C, std::vector<int, A>, std::deque<int, A>>;
using M = std::flat_map<int, int, C, KeyContainer<int, A>, ValueContainer<int, A>>;
auto mo = M(expected, expected + 3, C(5), A(7));
auto m = M(std::move(mo), A(3));
@@ -68,7 +51,7 @@ int main(int, char**) {
}
{
// moved-from object maintains invariant if one of underlying container does not clear after move
using M = std::flat_map<int, int, std::less<>, std::vector<int>, CopyOnlyVector<int>>;
using M = std::flat_map<int, int, std::less<>, KeyContainer<int>, CopyOnlyVector<int>>;
M m1 = M({1, 2, 3}, {1, 2, 3});
M m2(std::move(m1), std::allocator<int>{});
assert(m2.size() == 3);
@@ -77,6 +60,45 @@ int main(int, char**) {
LIBCPP_ASSERT(m1.keys().size() == 0);
LIBCPP_ASSERT(m1.values().size() == 0);
}
}
constexpr bool test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
// and uses_allocator_v<mapped_container_type, Alloc> is true.
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = other_allocator<int>;
using V1 = std::vector<int, A1>;
using V2 = std::vector<int, A2>;
using M1 = std::flat_map<int, int, C, V1, V1>;
using M2 = std::flat_map<int, int, C, V1, V2>;
using M3 = std::flat_map<int, int, C, V2, V1>;
static_assert(std::is_constructible_v<M1, M1&&, const A1&>);
static_assert(!std::is_constructible_v<M1, M1&&, const A2&>);
static_assert(!std::is_constructible_v<M2, M2&&, const A2&>);
static_assert(!std::is_constructible_v<M3, M3&&, const A2&>);
}
test<std::vector, std::vector>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -26,12 +26,13 @@
#include "test_allocator.h"
#include "min_allocator.h"
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
{
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<char>;
using M = std::flat_map<int, char, C, std::vector<int, A1>, std::vector<char, A2>>;
using M = std::flat_map<int, char, C, KeyContainer<int, A1>, ValueContainer<char, A2>>;
M mo = M({{1, 1}, {2, 3}, {3, 2}}, C(5), A1(7));
M m = M({}, C(3), A1(7));
m = std::move(mo);
@@ -46,7 +47,7 @@ int main(int, char**) {
using C = test_less<int>;
using A1 = other_allocator<int>;
using A2 = other_allocator<char>;
using M = std::flat_map<int, char, C, std::deque<int, A1>, std::deque<char, A2>>;
using M = std::flat_map<int, char, C, KeyContainer<int, A1>, ValueContainer<char, A2>>;
M mo = M({{4, 5}, {5, 4}}, C(5), A1(7));
M m = M({{1, 1}, {2, 2}, {3, 3}, {4, 4}}, C(3), A1(7));
m = std::move(mo);
@@ -59,7 +60,7 @@ int main(int, char**) {
}
{
using A = min_allocator<int>;
using M = std::flat_map<int, int, std::greater<int>, std::vector<int, A>, std::vector<int, A>>;
using M = std::flat_map<int, int, std::greater<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
M mo = M({{5, 1}, {4, 2}, {3, 3}}, A());
M m = M({{4, 4}, {3, 3}, {2, 2}, {1, 1}}, A());
m = std::move(mo);
@@ -69,6 +70,26 @@ int main(int, char**) {
assert(vs.get_allocator() == A());
assert(mo.empty());
}
}
constexpr bool test() {
test<std::vector, std::vector>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}
}

View File

@@ -16,6 +16,7 @@
#include <algorithm>
#include <cassert>
#include <compare>
#include <deque>
#include <flat_map>
#include <functional>
#include <utility>
@@ -27,9 +28,9 @@
struct MoveNegates {
int value_ = 0;
MoveNegates() = default;
MoveNegates(int v) : value_(v) {}
MoveNegates(MoveNegates&& rhs) : value_(rhs.value_) { rhs.value_ = -rhs.value_; }
MoveNegates& operator=(MoveNegates&& rhs) {
constexpr MoveNegates(int v) : value_(v) {}
constexpr MoveNegates(MoveNegates&& rhs) : value_(rhs.value_) { rhs.value_ = -rhs.value_; }
constexpr MoveNegates& operator=(MoveNegates&& rhs) {
value_ = rhs.value_;
rhs.value_ = -rhs.value_;
return *this;
@@ -41,9 +42,9 @@ struct MoveNegates {
struct MoveClears {
int value_ = 0;
MoveClears() = default;
MoveClears(int v) : value_(v) {}
MoveClears(MoveClears&& rhs) : value_(rhs.value_) { rhs.value_ = 0; }
MoveClears& operator=(MoveClears&& rhs) {
constexpr MoveClears(int v) : value_(v) {}
constexpr MoveClears(MoveClears&& rhs) : value_(rhs.value_) { rhs.value_ = 0; }
constexpr MoveClears& operator=(MoveClears&& rhs) {
value_ = rhs.value_;
rhs.value_ = 0;
return *this;
@@ -52,11 +53,12 @@ struct MoveClears {
auto operator<=>(const MoveClears&) const = default;
};
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
auto value_eq = [](auto&& p, auto&& q) { return p.first == q.first; };
{
const std::pair<int, int> expected[] = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}};
using M = std::flat_map<MoveNegates, int, std::less<MoveNegates>, std::vector<MoveNegates>>;
using M = std::flat_map<MoveNegates, int, std::less<MoveNegates>, KeyContainer<MoveNegates>, ValueContainer<int>>;
M m = M(expected, expected + 8);
M m2 = M(expected, expected + 3);
@@ -73,7 +75,7 @@ int main(int, char**) {
}
{
const std::pair<int, int> expected[] = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {7, 7}, {8, 8}};
using M = std::flat_map<MoveClears, int, std::less<MoveClears>, std::vector<MoveClears>>;
using M = std::flat_map<MoveClears, int, std::less<MoveClears>, KeyContainer<MoveClears>, ValueContainer<int>>;
M m = M(expected, expected + 8);
M m2 = M(expected, expected + 3);
@@ -90,7 +92,7 @@ int main(int, char**) {
}
{
// moved-from object maintains invariant if one of underlying container does not clear after move
using M = std::flat_map<int, int, std::less<>, std::vector<int>, CopyOnlyVector<int>>;
using M = std::flat_map<int, int, std::less<>, KeyContainer<int>, CopyOnlyVector<int>>;
M m1 = M({1, 2, 3}, {1, 2, 3});
M m2 = M({1, 2}, {1, 2});
m2 = std::move(m1);
@@ -100,5 +102,26 @@ int main(int, char**) {
LIBCPP_ASSERT(m1.keys().size() == 0);
LIBCPP_ASSERT(m1.values().size() == 0);
}
}
constexpr bool test() {
test<std::vector, std::vector>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -49,7 +49,7 @@ struct MoveThrowsComp {
bool operator()(const auto&, const auto&) const;
};
int main(int, char**) {
void test() {
{
using C = std::flat_map<int, int>;
LIBCPP_STATIC_ASSERT(std::is_nothrow_move_assignable_v<C>);
@@ -105,6 +105,4 @@ int main(int, char**) {
using C = std::flat_map<int, int, std::less<int>, std::vector<int>, std::pmr::vector<int>>;
static_assert(!std::is_nothrow_move_assignable_v<C>);
}
return 0;
}

View File

@@ -27,9 +27,11 @@
#include <vector>
#include "min_allocator.h"
#include "MinSequenceContainer.h"
#include "test_allocator.h"
#include "test_iterators.h"
#include "test_macros.h"
#include "../helpers.h"
#include "../../../test_compare.h"
// test constraint container-compatible-range
@@ -66,7 +68,171 @@ static_assert(std::is_constructible_v<Map,
static_assert(!std::is_constructible_v<Map, std::from_range_t, RangeOf<int>, std::less<int>, std::allocator<int>>);
static_assert(!std::is_constructible_v<Map, std::from_range_t, RangeOf<double>, std::less<int>, std::allocator<int>>);
int main(int, char**) {
template <class KeyContainer, class ValueContainer>
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using P = std::pair<Key, Value>;
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
{
// flat_map(from_range_t, R&&)
// input_range && !common
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
using Iter = cpp20_input_iterator<const P*>;
using Sent = sentinel_wrapper<Iter>;
using R = std::ranges::subrange<Iter, Sent>;
auto m = M(std::from_range, R(Iter(ar), Sent(Iter(ar + 9))));
assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<Value>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
// explicit(false)
M m2 = {std::from_range, R(Iter(ar), Sent(Iter(ar + 9)))};
assert(m2 == m);
}
{
// flat_map(from_range_t, R&&)
// greater
using M = std::flat_map<Key, Value, std::greater<int>, KeyContainer, ValueContainer>;
using Iter = cpp20_input_iterator<const P*>;
using Sent = sentinel_wrapper<Iter>;
using R = std::ranges::subrange<Iter, Sent>;
auto m = M(std::from_range, R(Iter(ar), Sent(Iter(ar + 9))));
assert(std::ranges::equal(m.keys(), KeyContainer{3, 2, 1}));
check_possible_values(
m.values(),
std::vector<std::vector<Value>>{
{6, 8, 9},
{4, 5, 7},
{1, 2, 3},
});
}
{
// flat_map(from_range_t, R&&)
// contiguous range
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
using R = std::ranges::subrange<const P*>;
auto m = M(std::from_range, R(ar, ar + 9));
assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<Value>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
}
{
// flat_map(from_range_t, R&&, const key_compare&)
using C = test_less<int>;
using M = std::flat_map<Key, Value, C, KeyContainer, ValueContainer>;
using R = std::ranges::subrange<const P*>;
auto m = M(std::from_range, R(ar, ar + 9), C(3));
assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<Value>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
assert(m.key_comp() == C(3));
// explicit(false)
M m2 = {std::from_range, R(ar, ar + 9), C(3)};
assert(m2 == m);
assert(m2.key_comp() == C(3));
}
}
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test_alloc() {
using P = std::pair<int, short>;
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
{
// flat_map(from_range_t, R&&, const Allocator&)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
using R = std::ranges::subrange<const P*>;
auto m = M(std::from_range, R(ar, ar + 9), A1(5));
assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<short>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(from_range_t, R&&, const Allocator&)
// explicit(false)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
using R = std::ranges::subrange<const P*>;
M m = {std::from_range, R(ar, ar + 9), A1(5)}; // implicit ctor
assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<short>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(from_range_t, R&&, const key_compare&, const Allocator&)
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, C, KeyContainer<int, A1>, ValueContainer<short, A2>>;
using R = std::ranges::subrange<const P*>;
auto m = M(std::from_range, R(ar, ar + 9), C(3), A1(5));
assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<short>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
assert(m.key_comp() == C(3));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(from_range_t, R&&, const key_compare&, const Allocator&)
// explicit(false)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
using R = std::ranges::subrange<const P*>;
M m = {std::from_range, R(ar, ar + 9), {}, A2(5)}; // implicit ctor
assert(std::ranges::equal(m.keys(), KeyContainer<int, A1>{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<short>>{
{1, 2, 3},
{4, 5, 7},
{6, 8, 9},
});
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
}
constexpr bool test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -117,111 +283,28 @@ int main(int, char**) {
static_assert(!std::is_constructible_v<M, std::from_range_t, std::vector<NonPairLike>&, const C&, const A1&>);
}
using P = std::pair<int, short>;
P ar[] = {{1, 1}, {1, 2}, {1, 3}, {2, 4}, {2, 5}, {3, 6}, {2, 7}, {3, 8}, {3, 9}};
P expected[] = {{1, 1}, {2, 4}, {3, 6}};
{
// flat_map(from_range_t, R&&)
// input_range && !common
using M = std::flat_map<int, short>;
using Iter = cpp20_input_iterator<const P*>;
using Sent = sentinel_wrapper<Iter>;
using R = std::ranges::subrange<Iter, Sent>;
auto m = M(std::from_range, R(Iter(ar), Sent(Iter(ar + 9))));
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
test<std::vector<int>, std::vector<int>>();
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
// explicit(false)
M m2 = {std::from_range, R(Iter(ar), Sent(Iter(ar + 9)))};
assert(m2 == m);
}
{
// flat_map(from_range_t, R&&)
// greater
using M = std::flat_map<int, short, std::greater<int>, std::deque<int, min_allocator<int>>, std::deque<short>>;
using Iter = cpp20_input_iterator<const P*>;
using Sent = sentinel_wrapper<Iter>;
using R = std::ranges::subrange<Iter, Sent>;
auto m = M(std::from_range, R(Iter(ar), Sent(Iter(ar + 9))));
assert((m.keys() == std::deque<int, min_allocator<int>>{3, 2, 1}));
LIBCPP_ASSERT((m.values() == std::deque<short>{6, 4, 1}));
}
{
// flat_map(from_range_t, R&&)
// contiguous range
using M = std::flat_map<int, short>;
using R = std::ranges::subrange<const P*>;
auto m = M(std::from_range, R(ar, ar + 9));
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
}
{
// flat_map(from_range_t, R&&, const key_compare&)
using C = test_less<int>;
using M = std::flat_map<int, short, C, std::vector<int>, std::deque<short>>;
using R = std::ranges::subrange<const P*>;
auto m = M(std::from_range, R(ar, ar + 9), C(3));
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
assert(m.key_comp() == C(3));
test_alloc<std::vector, std::vector>();
// explicit(false)
M m2 = {std::from_range, R(ar, ar + 9), C(3)};
assert(m2 == m);
assert(m2.key_comp() == C(3));
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// flat_map(from_range_t, R&&, const Allocator&)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
using R = std::ranges::subrange<const P*>;
auto m = M(std::from_range, R(ar, ar + 9), A1(5));
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(from_range_t, R&&, const Allocator&)
// explicit(false)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
using R = std::ranges::subrange<const P*>;
M m = {std::from_range, R(ar, ar + 9), A1(5)}; // implicit ctor
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(from_range_t, R&&, const key_compare&, const Allocator&)
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, C, std::vector<int, A1>, std::deque<short, A2>>;
using R = std::ranges::subrange<const P*>;
auto m = M(std::from_range, R(ar, ar + 9), C(3), A1(5));
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
assert(m.key_comp() == C(3));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(from_range_t, R&&, const key_compare&, const Allocator&)
// explicit(false)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, std::deque<int, A1>, std::vector<short, A2>>;
using R = std::ranges::subrange<const P*>;
M m = {std::from_range, R(ar, ar + 9), {}, A2(5)}; // implicit ctor
assert(std::ranges::equal(m.keys(), expected | std::views::elements<0>));
LIBCPP_ASSERT(std::ranges::equal(m, expected));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
test<std::deque<int>, std::vector<double>>();
test_alloc<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -31,9 +31,117 @@
#include "test_allocator.h"
#include "test_iterators.h"
#include "test_macros.h"
#include "../helpers.h"
#include "../../../test_compare.h"
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type)
using M = std::flat_map<int, char, std::less<int>, KeyContainer<int>, ValueContainer<char>>;
KeyContainer<int> ks = {1, 2, 4, 10};
ValueContainer<char> vs = {4, 3, 2, 1};
auto ks2 = ks;
auto vs2 = vs;
auto m = M(std::sorted_unique, ks, vs);
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
m = M(std::sorted_unique, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
// explicit(false)
M m2 = {std::sorted_unique, std::move(ks2), std::move(vs2)};
assert(m == m2);
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type)
// non-default container, comparator and allocator type
using Ks = KeyContainer<int, min_allocator<int>>;
using Vs = ValueContainer<char, min_allocator<char>>;
using M = std::flat_map<int, char, std::greater<int>, Ks, Vs>;
Ks ks = {10, 4, 2, 1};
Vs vs = {1, 2, 3, 4};
auto m = M(std::sorted_unique, ks, vs);
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
m = M(std::sorted_unique, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type)
// allocator copied into the containers
using A = test_allocator<int>;
using M = std::flat_map<int, int, std::less<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
auto ks = KeyContainer<int, A>({1, 2, 4, 10}, A(4));
auto vs = ValueContainer<int, A>({4, 3, 2, 1}, A(5));
auto m = M(std::sorted_unique, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.keys().get_allocator() == A(4));
assert(m.values().get_allocator() == A(5));
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type, key_compare)
using C = test_less<int>;
using M = std::flat_map<int, char, C, KeyContainer<int>, ValueContainer<char>>;
KeyContainer<int> ks = {1, 2, 4, 10};
ValueContainer<char> vs = {4, 3, 2, 1};
auto m = M(std::sorted_unique, ks, vs, C(4));
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.key_comp() == C(4));
// explicit(false)
M m2 = {std::sorted_unique, ks, vs, C(4)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type, key_compare, const Allocator&)
using C = test_less<int>;
using A = test_allocator<int>;
using M = std::flat_map<int, int, C, KeyContainer<int, A>, ValueContainer<int, A>>;
KeyContainer<int, A> ks = {1, 2, 4, 10};
ValueContainer<int, A> vs = {4, 3, 2, 1};
auto m = M(std::sorted_unique, ks, vs, C(4), A(5));
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.key_comp() == C(4));
assert(m.keys().get_allocator() == A(5));
assert(m.values().get_allocator() == A(5));
// explicit(false)
M m2 = {ks, vs, C(4), A(5)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
assert(m2.keys().get_allocator() == A(5));
assert(m2.values().get_allocator() == A(5));
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type, const Allocator&)
using A = test_allocator<int>;
using M = std::flat_map<int, int, std::less<int>, KeyContainer<int, A>, ValueContainer<int, A>>;
auto ks = KeyContainer<int, A>({1, 2, 4, 10}, A(4));
auto vs = ValueContainer<int, A>({4, 3, 2, 1}, A(5));
auto m = M(std::sorted_unique, ks, vs, A(6)); // replaces the allocators
assert(!ks.empty()); // it was an lvalue above
assert(!vs.empty()); // it was an lvalue above
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.keys().get_allocator() == A(6));
assert(m.values().get_allocator() == A(6));
// explicit(false)
M m2 = {std::sorted_unique, ks, vs, A(6)};
assert(m2 == m);
assert(m2.keys().get_allocator() == A(6));
assert(m2.values().get_allocator() == A(6));
}
}
constexpr bool test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -57,109 +165,25 @@ int main(int, char**) {
static_assert(!std::is_constructible_v<M2, std::sorted_unique_t, const V1&, const V2&, const C&, const A2&>);
static_assert(!std::is_constructible_v<M3, std::sorted_unique_t, const V2&, const V1&, const C&, const A2&>);
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type)
using M = std::flat_map<int, char>;
std::vector<int> ks = {1, 2, 4, 10};
std::vector<char> vs = {4, 3, 2, 1};
auto ks2 = ks;
auto vs2 = vs;
auto m = M(std::sorted_unique, ks, vs);
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
m = M(std::sorted_unique, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
test<std::vector, std::vector>();
// explicit(false)
M m2 = {std::sorted_unique, std::move(ks2), std::move(vs2)};
assert(m == m2);
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type)
// non-default container, comparator and allocator type
using Ks = std::deque<int, min_allocator<int>>;
using Vs = std::deque<char, min_allocator<char>>;
using M = std::flat_map<int, char, std::greater<int>, Ks, Vs>;
Ks ks = {10, 4, 2, 1};
Vs vs = {1, 2, 3, 4};
auto m = M(std::sorted_unique, ks, vs);
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
m = M(std::sorted_unique, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
test<std::deque, std::vector>();
test<std::deque, std::deque>();
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type)
// allocator copied into the containers
using A = test_allocator<int>;
using M = std::flat_map<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
auto ks = std::vector<int, A>({1, 2, 4, 10}, A(4));
auto vs = std::deque<int, A>({4, 3, 2, 1}, A(5));
auto m = M(std::sorted_unique, std::move(ks), std::move(vs));
assert(ks.empty()); // it was moved-from
assert(vs.empty()); // it was moved-from
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.keys().get_allocator() == A(4));
assert(m.values().get_allocator() == A(5));
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type, key_compare)
using C = test_less<int>;
using M = std::flat_map<int, char, C>;
std::vector<int> ks = {1, 2, 4, 10};
std::vector<char> vs = {4, 3, 2, 1};
auto m = M(std::sorted_unique, ks, vs, C(4));
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.key_comp() == C(4));
return true;
}
// explicit(false)
M m2 = {std::sorted_unique, ks, vs, C(4)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type, key_compare, const Allocator&)
using C = test_less<int>;
using A = test_allocator<int>;
using M = std::flat_map<int, int, C, std::vector<int, A>, std::vector<int, A>>;
std::vector<int, A> ks = {1, 2, 4, 10};
std::vector<int, A> vs = {4, 3, 2, 1};
auto m = M(std::sorted_unique, ks, vs, C(4), A(5));
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.key_comp() == C(4));
assert(m.keys().get_allocator() == A(5));
assert(m.values().get_allocator() == A(5));
// explicit(false)
M m2 = {ks, vs, C(4), A(5)};
assert(m2 == m);
assert(m2.key_comp() == C(4));
assert(m2.keys().get_allocator() == A(5));
assert(m2.values().get_allocator() == A(5));
}
{
// flat_map(sorted_unique_t, key_container_type , mapped_container_type, const Allocator&)
using A = test_allocator<int>;
using M = std::flat_map<int, int, std::less<int>, std::vector<int, A>, std::deque<int, A>>;
auto ks = std::vector<int, A>({1, 2, 4, 10}, A(4));
auto vs = std::deque<int, A>({4, 3, 2, 1}, A(5));
auto m = M(std::sorted_unique, ks, vs, A(6)); // replaces the allocators
assert(!ks.empty()); // it was an lvalue above
assert(!vs.empty()); // it was an lvalue above
assert((m == M{{1, 4}, {2, 3}, {4, 2}, {10, 1}}));
assert(m.keys().get_allocator() == A(6));
assert(m.values().get_allocator() == A(6));
// explicit(false)
M m2 = {std::sorted_unique, ks, vs, A(6)};
assert(m2 == m);
assert(m2.keys().get_allocator() == A(6));
assert(m2.values().get_allocator() == A(6));
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -22,6 +22,7 @@
#include <deque>
#include <flat_map>
#include <functional>
#include <type_traits>
#include <vector>
#include "min_allocator.h"
@@ -31,13 +32,87 @@
#include "../../../test_compare.h"
template <class T, class U>
std::initializer_list<std::pair<T, U>> il = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
constexpr std::initializer_list<std::pair<T, U>> il = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
const auto il1 = il<int, int>;
const auto il2 = il<int, short>;
const auto il3 = il<short, int>;
constexpr auto il1 = il<int, int>;
constexpr auto il2 = il<int, short>;
constexpr auto il3 = il<short, int>;
int main(int, char**) {
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test() {
{
// flat_map(sorted_unique_t, initializer_list<value_type>);
using M = std::flat_map<int, int, std::less<int>, KeyContainer<int>, ValueContainer<int>>;
auto m = M(std::sorted_unique, il1);
auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
assert(m == expected);
// explicit(false)
M m2 = {std::sorted_unique, il1};
assert(m2 == m);
}
if (!TEST_IS_CONSTANT_EVALUATED) {
// flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&);
using M = std::flat_map<int, int, std::function<bool(int, int)>, KeyContainer<int>, ValueContainer<int>>;
auto m = M(std::sorted_unique, il1, std::less<int>());
assert(m == M({{1, 1}, {2, 2}, {4, 4}, {5, 5}}, std::less<>()));
assert(m.key_comp()(1, 2) == true);
// explicit(false)
M m2 = {std::sorted_unique, il1, std::less<int>()};
assert(m2 == m);
}
{
// flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&);
// greater
using M = std::flat_map<int, int, std::greater<int>, KeyContainer<int, min_allocator<int>>, ValueContainer<int>>;
std::initializer_list<std::pair<int, int>> il4{{5, 5}, {4, 4}, {2, 2}, {1, 1}};
auto m = M(std::sorted_unique, il4, std::greater<int>());
assert((m == M{{5, 5}, {4, 4}, {2, 2}, {1, 1}}));
}
{
// flat_map(sorted_unique_t, initializer_list<value_type>, const Allocator&)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
auto m = M(std::sorted_unique, il2, A1(5));
auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
assert(m == expected);
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
// explicit(false)
M m2 = {std::sorted_unique, il2, A1(5)};
assert(m2 == m);
assert(m2.keys().get_allocator() == A1(5));
assert(m2.values().get_allocator() == A2(5));
}
{
// flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&, const Allocator&);
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, C, KeyContainer<int, A1>, ValueContainer<short, A2>>;
auto m = M(std::sorted_unique, il2, C(3), A1(5));
assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}));
assert(m.key_comp() == C(3));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&, const Allocator&);
// explicit(false)
using A1 = test_allocator<short>;
using A2 = test_allocator<int>;
using M = std::flat_map<short, int, std::less<int>, KeyContainer<short, A1>, ValueContainer<int, A2>>;
M m = {std::sorted_unique, il3, {}, A1(5)}; // implicit ctor
assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
}
constexpr bool test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -104,76 +179,23 @@ int main(int, char**) {
std::allocator<int>>);
}
{
// flat_map(sorted_unique_t, initializer_list<value_type>);
using M = std::flat_map<int, int>;
auto m = M(std::sorted_unique, il1);
auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
assert(m == expected);
test<std::vector, std::vector>();
// explicit(false)
M m2 = {std::sorted_unique, il1};
assert(m2 == m);
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&);
using M = std::flat_map<int, int, std::function<bool(int, int)>>;
auto m = M(std::sorted_unique, il1, std::less<int>());
assert(m == M({{1, 1}, {2, 2}, {4, 4}, {5, 5}}, std::less<>()));
assert(m.key_comp()(1, 2) == true);
test<std::deque, std::deque>();
}
// explicit(false)
M m2 = {std::sorted_unique, il1, std::less<int>()};
assert(m2 == m);
}
{
// flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&);
// greater
using M = std::flat_map<int, int, std::greater<int>, std::deque<int, min_allocator<int>>, std::vector<int>>;
std::initializer_list<std::pair<int, int>> il4{{5, 5}, {4, 4}, {2, 2}, {1, 1}};
auto m = M(std::sorted_unique, il4, std::greater<int>());
assert((m == M{{5, 5}, {4, 4}, {2, 2}, {1, 1}}));
}
{
// flat_map(sorted_unique_t, initializer_list<value_type>, const Allocator&)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
auto m = M(std::sorted_unique, il2, A1(5));
auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
assert(m == expected);
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
return true;
}
// explicit(false)
M m2 = {std::sorted_unique, il2, A1(5)};
assert(m2 == m);
assert(m2.keys().get_allocator() == A1(5));
assert(m2.values().get_allocator() == A2(5));
}
{
// flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&, const Allocator&);
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, C, std::vector<int, A1>, std::deque<short, A2>>;
auto m = M(std::sorted_unique, il2, C(3), A1(5));
assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}));
assert(m.key_comp() == C(3));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(sorted_unique_t, initializer_list<value_type>, const key_compare&, const Allocator&);
// explicit(false)
using A1 = test_allocator<short>;
using A2 = test_allocator<int>;
using M = std::flat_map<short, int, std::less<int>, std::deque<short, A1>, std::vector<int, A2>>;
M m = {std::sorted_unique, il3, {}, A1(5)}; // implicit ctor
assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -20,15 +20,141 @@
#include <deque>
#include <flat_map>
#include <functional>
#include <type_traits>
#include <vector>
#include "MinSequenceContainer.h"
#include "min_allocator.h"
#include "test_allocator.h"
#include "test_iterators.h"
#include "test_macros.h"
#include "../../../test_compare.h"
int main(int, char**) {
template <class KeyContainer, class ValueContainer>
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
{
// flat_map(sorted_unique_t, InputIterator, InputIterator);
// cpp17_input_iterator
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
using P = std::pair<Key, Value>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique, cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 4));
auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
assert(m == expected);
// explicit(false)
M m2 = {std::sorted_unique, cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 4)};
assert(m2 == m);
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator);
// contiguous iterator
using C = test_less<Key>;
using P = std::pair<Key, Value>;
using M = std::flat_map<Key, Value, C, KeyContainer, ValueContainer>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique, ar, ar + 4);
auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
assert(m == expected);
}
if (!TEST_IS_CONSTANT_EVALUATED) {
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&);
// cpp_17_input_iterator
using M = std::flat_map<Key, Value, std::function<bool(Key, Value)>>;
using P = std::pair<Key, Value>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique,
cpp17_input_iterator<const P*>(ar),
cpp17_input_iterator<const P*>(ar + 4),
std::less<int>());
assert(m == M({{1, 1}, {2, 2}, {4, 4}, {5, 5}}, std::less<>()));
assert(m.key_comp()(1, 2) == true);
// explicit(false)
M m2 = {std::sorted_unique,
cpp17_input_iterator<const P*>(ar),
cpp17_input_iterator<const P*>(ar + 4),
std::less<int>()};
assert(m2 == m);
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&);
// greater
using M = std::flat_map<Key, Value, std::greater<int>, KeyContainer, ValueContainer>;
using P = std::pair<Key, Value>;
P ar[] = {{5, 5}, {4, 4}, {2, 2}, {1, 1}};
auto m = M(std::sorted_unique,
cpp17_input_iterator<const P*>(ar),
cpp17_input_iterator<const P*>(ar + 4),
std::greater<int>());
assert((m == M{{5, 5}, {4, 4}, {2, 2}, {1, 1}}));
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&);
// contiguous iterator
using C = test_less<Key>;
using M = std::flat_map<Key, Value, C, KeyContainer, ValueContainer>;
std::pair<Key, Value> ar[1] = {{42, 42}};
auto m = M(std::sorted_unique, ar, ar, C(5));
assert(m.empty());
assert(m.key_comp() == C(5));
}
}
template <template <class...> class KeyContainer, template <class...> class ValueContainer>
constexpr void test_alloc() {
{
// flat_map(sorted_unique_t, InputIterator , InputIterator, const Allocator&)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, KeyContainer<int, A1>, ValueContainer<short, A2>>;
using P = std::pair<int, int>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique, ar, ar + 4, A1(5));
auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
assert(m == expected);
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
// explicit(false)
M m2 = {std::sorted_unique, ar, ar + 4, A1(5)};
assert(m2 == m);
assert(m2.keys().get_allocator() == A1(5));
assert(m2.values().get_allocator() == A2(5));
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&, const Allocator&);
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, C, KeyContainer<int, A1>, ValueContainer<short, A2>>;
using P = std::pair<int, int>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique, ar, ar + 4, C(3), A1(5));
assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}));
assert(m.key_comp() == C(3));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&, const Allocator&);
// explicit(false)
using A1 = test_allocator<short>;
using A2 = test_allocator<int>;
using M = std::flat_map<short, int, std::less<int>, KeyContainer<short, A1>, ValueContainer<int, A2>>;
using P = std::pair<int, int>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
M m = {std::sorted_unique, ar, ar + 4, {}, A1(5)}; // implicit ctor
assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
}
constexpr bool test() {
{
// The constructors in this subclause shall not participate in overload
// resolution unless uses_allocator_v<key_container_type, Alloc> is true
@@ -54,118 +180,31 @@ int main(int, char**) {
static_assert(!std::is_constructible_v<M2, std::sorted_unique_t, Iter2, Iter2, const C&, const A2&>);
static_assert(!std::is_constructible_v<M3, std::sorted_unique_t, Iter3, Iter3, const C&, const A2&>);
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator);
// cpp17_input_iterator
using M = std::flat_map<int, int>;
using P = std::pair<int, int>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique, cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 4));
auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
assert(m == expected);
// explicit(false)
M m2 = {std::sorted_unique, cpp17_input_iterator<const P*>(ar), cpp17_input_iterator<const P*>(ar + 4)};
assert(m2 == m);
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator);
// contiguous iterator
using C = test_less<int>;
using M = std::flat_map<int, int, C, std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>;
std::pair<int, int> ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique, ar, ar + 4);
auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
assert(m == expected);
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&);
// cpp_17_input_iterator
using M = std::flat_map<int, int, std::function<bool(int, int)>>;
using P = std::pair<int, int>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique,
cpp17_input_iterator<const P*>(ar),
cpp17_input_iterator<const P*>(ar + 4),
std::less<int>());
assert(m == M({{1, 1}, {2, 2}, {4, 4}, {5, 5}}, std::less<>()));
assert(m.key_comp()(1, 2) == true);
test<std::vector<int>, std::vector<int>>();
test<std::vector<int>, std::vector<double>>();
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
// explicit(false)
M m2 = {std::sorted_unique,
cpp17_input_iterator<const P*>(ar),
cpp17_input_iterator<const P*>(ar + 4),
std::less<int>()};
assert(m2 == m);
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&);
// greater
using M = std::flat_map<int, int, std::greater<int>, std::deque<int, min_allocator<int>>, std::vector<int>>;
using P = std::pair<int, int>;
P ar[] = {{5, 5}, {4, 4}, {2, 2}, {1, 1}};
auto m = M(std::sorted_unique,
cpp17_input_iterator<const P*>(ar),
cpp17_input_iterator<const P*>(ar + 4),
std::greater<int>());
assert((m == M{{5, 5}, {4, 4}, {2, 2}, {1, 1}}));
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&);
// contiguous iterator
using C = test_less<int>;
using M = std::flat_map<int, int, C, std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>;
std::pair<int, int> ar[1] = {{42, 42}};
auto m = M(std::sorted_unique, ar, ar, C(5));
assert(m.empty());
assert(m.key_comp() == C(5));
}
{
// flat_map(sorted_unique_t, InputIterator , InputIterator, const Allocator&)
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, std::less<int>, std::vector<int, A1>, std::deque<short, A2>>;
using P = std::pair<int, int>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique, ar, ar + 4, A1(5));
auto expected = M{{1, 1}, {2, 2}, {4, 4}, {5, 5}};
assert(m == expected);
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
test_alloc<std::vector, std::vector>();
// explicit(false)
M m2 = {std::sorted_unique, ar, ar + 4, A1(5)};
assert(m2 == m);
assert(m2.keys().get_allocator() == A1(5));
assert(m2.values().get_allocator() == A2(5));
}
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&, const Allocator&);
using C = test_less<int>;
using A1 = test_allocator<int>;
using A2 = test_allocator<short>;
using M = std::flat_map<int, short, C, std::vector<int, A1>, std::deque<short, A2>>;
using P = std::pair<int, int>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
auto m = M(std::sorted_unique, ar, ar + 4, C(3), A1(5));
assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}));
assert(m.key_comp() == C(3));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
}
{
// flat_map(sorted_unique_t, InputIterator, InputIterator, const key_compare&, const Allocator&);
// explicit(false)
using A1 = test_allocator<short>;
using A2 = test_allocator<int>;
using M = std::flat_map<short, int, std::less<int>, std::deque<short, A1>, std::vector<int, A2>>;
using P = std::pair<int, int>;
P ar[] = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
M m = {std::sorted_unique, ar, ar + 4, {}, A1(5)}; // implicit ctor
assert((m == M{{1, 1}, {2, 2}, {4, 4}, {5, 5}}));
assert(m.keys().get_allocator() == A1(5));
assert(m.values().get_allocator() == A2(5));
test<std::deque<int>, std::vector<double>>();
test_alloc<std::deque, std::deque>();
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -32,7 +32,7 @@ static_assert(HasStdErase<std::vector<int>>);
static_assert(!HasStdErase<std::flat_map<int, int>>);
template <class M>
M make(std::initializer_list<int> vals) {
constexpr M make(std::initializer_list<int> vals) {
M ret;
for (int v : vals)
ret[static_cast<typename M::key_type>(v)] = static_cast<typename M::mapped_type>(v + 10);
@@ -40,8 +40,8 @@ M make(std::initializer_list<int> vals) {
}
template <class M, class Pred>
void test0(
std::initializer_list<int> vals, Pred p, std::initializer_list<int> expected, std::size_t expected_erased_count) {
constexpr void
test0(std::initializer_list<int> vals, Pred p, std::initializer_list<int> expected, std::size_t expected_erased_count) {
M s = make<M>(vals);
ASSERT_SAME_TYPE(typename M::size_type, decltype(std::erase_if(s, p)));
assert(expected_erased_count == std::erase_if(s, p));
@@ -49,7 +49,7 @@ void test0(
}
template <class S>
void test() {
constexpr void test() {
// Test all the plausible signatures for this predicate.
auto is1 = [](typename S::const_reference v) { return v.first == 1; };
auto is2 = [](typename S::value_type v) { return v.first == 2; };
@@ -76,7 +76,7 @@ void test() {
test0<S>({1, 2, 3}, False, {1, 2, 3}, 0);
}
int main(int, char**) {
constexpr bool test() {
test<std::flat_map<int, char>>();
test<std::flat_map<int,
char,
@@ -84,10 +84,24 @@ int main(int, char**) {
std::vector<int, min_allocator<int>>,
std::vector<char, min_allocator<char>>>>();
test<std::flat_map<int, char, std::greater<int>, std::vector<int, test_allocator<int>>>>();
test<std::flat_map<int, char, std::less<int>, std::deque<int, min_allocator<int>>>>();
test<std::flat_map<int, char, std::greater<int>, std::deque<int, test_allocator<int>>>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::flat_map<int, char, std::less<int>, std::deque<int, min_allocator<int>>>>();
test<std::flat_map<int, char, std::greater<int>, std::deque<int, test_allocator<int>>>>();
}
test<std::flat_map<long, int>>();
test<std::flat_map<double, int>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -30,7 +30,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -70,9 +70,14 @@ void test() {
assert(i == m.begin());
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
test<std::deque<int>, std::vector<char>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<char>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
@@ -92,5 +97,14 @@ int main(int, char**) {
assert(!(cii != ii1));
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -24,7 +24,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -142,11 +142,25 @@ void test() {
assert(cri2 <=> cri1 == std::strong_ordering::greater);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
test<std::deque<int>, std::vector<char>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<char>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -25,48 +25,64 @@
#include <iterator>
#include "MinSequenceContainer.h"
#include "test_macros.h"
#include "min_allocator.h"
int main(int, char**) {
{
using M = std::flat_map<int, char, std::less<int>, std::deque<int>, std::deque<char>>;
M m = {{1, 'a'}, {2, 'b'}, {3, 'c'}, {4, 'd'}};
const M& cm = m;
ASSERT_SAME_TYPE(decltype(m.rbegin()), M::reverse_iterator);
ASSERT_SAME_TYPE(decltype(m.crbegin()), M::const_reverse_iterator);
ASSERT_SAME_TYPE(decltype(cm.rbegin()), M::const_reverse_iterator);
ASSERT_SAME_TYPE(decltype(m.rend()), M::reverse_iterator);
ASSERT_SAME_TYPE(decltype(m.crend()), M::const_reverse_iterator);
ASSERT_SAME_TYPE(decltype(cm.rend()), M::const_reverse_iterator);
static_assert(noexcept(m.rbegin()));
static_assert(noexcept(cm.rbegin()));
static_assert(noexcept(m.crbegin()));
static_assert(noexcept(m.rend()));
static_assert(noexcept(cm.rend()));
static_assert(noexcept(m.crend()));
assert(m.size() == 4);
assert(std::distance(m.rbegin(), m.rend()) == 4);
assert(std::distance(cm.rbegin(), cm.rend()) == 4);
assert(std::distance(m.crbegin(), m.crend()) == 4);
assert(std::distance(cm.crbegin(), cm.crend()) == 4);
M::reverse_iterator i; // default-construct
ASSERT_SAME_TYPE(decltype(i->first), const int&);
ASSERT_SAME_TYPE(decltype(i->second), char&);
i = m.rbegin(); // move-assignment
M::const_reverse_iterator k = i; // converting constructor
assert(i == k); // comparison
for (int j = 4; j >= 1; --j, ++i) { // pre-increment
assert(i->first == j); // operator->
assert(i->second == 'a' + j - 1);
}
assert(i == m.rend());
for (int j = 1; j <= 4; ++j) {
--i; // pre-decrement
assert((*i).first == j);
assert((*i).second == 'a' + j - 1);
}
assert(i == m.rbegin());
template <class KeyContainer, class ValueContainer>
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
M m = {{1, 'a'}, {2, 'b'}, {3, 'c'}, {4, 'd'}};
const M& cm = m;
ASSERT_SAME_TYPE(decltype(m.rbegin()), typename M::reverse_iterator);
ASSERT_SAME_TYPE(decltype(m.crbegin()), typename M::const_reverse_iterator);
ASSERT_SAME_TYPE(decltype(cm.rbegin()), typename M::const_reverse_iterator);
ASSERT_SAME_TYPE(decltype(m.rend()), typename M::reverse_iterator);
ASSERT_SAME_TYPE(decltype(m.crend()), typename M::const_reverse_iterator);
ASSERT_SAME_TYPE(decltype(cm.rend()), typename M::const_reverse_iterator);
static_assert(noexcept(m.rbegin()));
static_assert(noexcept(cm.rbegin()));
static_assert(noexcept(m.crbegin()));
static_assert(noexcept(m.rend()));
static_assert(noexcept(cm.rend()));
static_assert(noexcept(m.crend()));
assert(m.size() == 4);
assert(std::distance(m.rbegin(), m.rend()) == 4);
assert(std::distance(cm.rbegin(), cm.rend()) == 4);
assert(std::distance(m.crbegin(), m.crend()) == 4);
assert(std::distance(cm.crbegin(), cm.crend()) == 4);
typename M::reverse_iterator i; // default-construct
ASSERT_SAME_TYPE(decltype(i->first), const int&);
ASSERT_SAME_TYPE(decltype(i->second), char&);
i = m.rbegin(); // move-assignment
typename M::const_reverse_iterator k = i; // converting constructor
assert(i == k); // comparison
for (int j = 4; j >= 1; --j, ++i) { // pre-increment
assert(i->first == j); // operator->
assert(i->second == 'a' + j - 1);
}
assert(i == m.rend());
for (int j = 1; j <= 4; ++j) {
--i; // pre-decrement
assert((*i).first == j);
assert((*i).second == 'a' + j - 1);
}
assert(i == m.rbegin());
}
constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<char>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
{
// N3644 testing
using C = std::flat_map<int, char>;
@@ -82,6 +98,14 @@ int main(int, char**) {
assert(!(ii1 != cii));
assert(!(cii != ii1));
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -39,7 +39,7 @@ static_assert(
#endif
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -52,13 +52,27 @@ void test() {
assert(m.size() == 0);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<int>>();
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -18,6 +18,7 @@
#include <deque>
#include <tuple>
#include <functional>
#include <type_traits>
#include <vector>
#include "MinSequenceContainer.h"
@@ -39,7 +40,7 @@ static_assert(!CanEmplace<Map, Emplaceable>);
static_assert(!CanEmplace<Map, int, double>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -117,7 +118,7 @@ void test() {
}
template <class KeyContainer, class ValueContainer>
void test_emplaceable() {
constexpr void test_emplaceable() {
using M = std::flat_map<int, Emplaceable, std::less<int>, KeyContainer, ValueContainer>;
using R = std::pair<typename M::iterator, bool>;
@@ -143,23 +144,38 @@ void test_emplaceable() {
assert(m.begin()->second == Emplaceable(2, 3.5));
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test_emplaceable<std::vector<int>, std::vector<Emplaceable>>();
test_emplaceable<std::deque<int>, std::vector<Emplaceable>>();
test_emplaceable<MinSequenceContainer<int>, MinSequenceContainer<Emplaceable>>();
test_emplaceable<std::vector<int, min_allocator<int>>, std::vector<Emplaceable, min_allocator<Emplaceable>>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
test_emplaceable<std::deque<int>, std::vector<Emplaceable>>();
}
if (!TEST_IS_CONSTANT_EVALUATED) {
auto emplace_func = [](auto& m, auto key_arg, auto value_arg) {
m.emplace(std::piecewise_construct, std::tuple(key_arg), std::tuple(value_arg));
};
test_emplace_exception_guarantee(emplace_func);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -17,6 +17,7 @@
#include <cassert>
#include <deque>
#include <functional>
#include <type_traits>
#include <vector>
#include "MinSequenceContainer.h"
@@ -42,7 +43,7 @@ static_assert(!CanEmplaceHint<Map, int, double>);
#endif
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -139,7 +140,7 @@ void test() {
}
template <class KeyContainer, class ValueContainer>
void test_emplaceable() {
constexpr void test_emplaceable() {
using M = std::flat_map<int, Emplaceable, std::less<int>, KeyContainer, ValueContainer>;
using R = M::iterator;
@@ -162,23 +163,37 @@ void test_emplaceable() {
assert(m.begin()->second == Emplaceable(2, 3.5));
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
test_emplaceable<std::deque<int>, std::vector<Emplaceable>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test_emplaceable<std::vector<int>, std::vector<Emplaceable>>();
test_emplaceable<std::deque<int>, std::vector<Emplaceable>>();
test_emplaceable<MinSequenceContainer<int>, MinSequenceContainer<Emplaceable>>();
test_emplaceable<std::vector<int, min_allocator<int>>, std::vector<Emplaceable, min_allocator<Emplaceable>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto emplace_func = [](auto& m, auto key_arg, auto value_arg) {
m.emplace_hint(m.begin(), std::piecewise_construct, std::tuple(key_arg), std::tuple(value_arg));
};
test_emplace_exception_guarantee(emplace_func);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -18,6 +18,7 @@
#include <deque>
#include <flat_map>
#include <functional>
#include <type_traits>
#include <utility>
#include <vector>
@@ -27,7 +28,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -136,16 +137,30 @@ void test() {
assert(i8 == m.end());
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto erase_function = [](auto& m, auto) { m.erase(m.begin() + 2); };
test_erase_exception_guarantee(erase_function);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -17,6 +17,7 @@
#include <deque>
#include <flat_map>
#include <functional>
#include <type_traits>
#include <utility>
#include <vector>
@@ -26,7 +27,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -95,15 +96,30 @@ void test() {
assert(i4 == m.end());
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto erase_function = [](auto& m, auto) { m.erase(m.begin(), m.begin() + 2); };
test_erase_exception_guarantee(erase_function);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -26,7 +26,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer, class Compare = std::less<>>
void test() {
constexpr void test() {
using M = std::flat_map<int, char, Compare, KeyContainer, ValueContainer>;
auto make = [](std::initializer_list<int> il) {
@@ -70,14 +70,20 @@ void test() {
assert(m.empty());
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
test<std::vector<int>, std::vector<char>, std::greater<>>();
test<std::deque<int>, std::vector<char>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<char>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto erase_function = [](auto& m, auto key_arg) {
using Map = std::decay_t<decltype(m)>;
using Key = typename Map::key_type;
@@ -87,5 +93,14 @@ int main(int, char**) {
test_erase_exception_guarantee(erase_function);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -38,9 +38,9 @@ static_assert(!CanErase<const NonTransparentMap>);
template <class Key, class It>
struct HeterogeneousKey {
explicit HeterogeneousKey(Key key, It it) : key_(key), it_(it) {}
operator It() && { return it_; }
auto operator<=>(Key key) const { return key_ <=> key; }
constexpr explicit HeterogeneousKey(Key key, It it) : key_(key), it_(it) {}
constexpr operator It() && { return it_; }
constexpr auto operator<=>(Key key) const { return key_ <=> key; }
friend bool operator<(const HeterogeneousKey&, const HeterogeneousKey&) {
assert(false);
return false;
@@ -50,7 +50,7 @@ struct HeterogeneousKey {
};
template <class KeyContainer, class ValueContainer>
void test_simple() {
constexpr void test_simple() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -71,7 +71,7 @@ void test_simple() {
}
template <class KeyContainer, class ValueContainer>
void test_transparent_comparator() {
constexpr void test_transparent_comparator() {
using M = std::flat_map<std::string, int, TransparentComparator, KeyContainer, ValueContainer>;
M m = {{"alpha", 1}, {"beta", 2}, {"epsilon", 3}, {"eta", 4}, {"gamma", 5}};
ASSERT_SAME_TYPE(decltype(m.erase(Transparent<std::string>{"abc"})), typename M::size_type);
@@ -87,18 +87,24 @@ void test_transparent_comparator() {
assert(m == expected);
}
int main(int, char**) {
constexpr bool test() {
test_simple<std::vector<int>, std::vector<double>>();
test_simple<std::deque<int>, std::vector<double>>();
test_simple<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test_simple<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test_transparent_comparator<std::vector<std::string>, std::vector<int>>();
test_transparent_comparator<std::deque<std::string>, std::vector<int>>();
test_transparent_comparator<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test_transparent_comparator<std::vector<std::string, min_allocator<std::string>>,
std::vector<int, min_allocator<int>>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test_simple<std::deque<int>, std::vector<double>>();
test_transparent_comparator<std::deque<std::string>, std::vector<int>>();
}
{
// P2077's HeterogeneousKey example
using M = std::flat_map<int, int, std::less<>>;
@@ -131,7 +137,7 @@ int main(int, char**) {
assert(n == 1);
assert(transparent_used);
}
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto erase_transparent = [](auto& m, auto key_arg) {
using Map = std::decay_t<decltype(m)>;
using Key = typename Map::key_type;
@@ -147,5 +153,14 @@ int main(int, char**) {
assert(n == 1);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -33,7 +33,7 @@ static_assert(!CanExtract<std::flat_map<int, int> const&>);
static_assert(!CanExtract<std::flat_map<int, int> const&&>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using M = std::flat_map<int, int, std::less<int>, KeyContainer, ValueContainer>;
M m = M({1, 2, 3}, {4, 5, 6});
@@ -49,9 +49,14 @@ void test() {
LIBCPP_ASSERT(m.values().size() == 0);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<int>>();
test<std::deque<int>, std::vector<int>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<int>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<int>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
{
@@ -67,7 +72,7 @@ int main(int, char**) {
LIBCPP_ASSERT(m.values().size() == 0);
}
{
if (!TEST_IS_CONSTANT_EVALUATED) {
#ifndef TEST_HAS_NO_EXCEPTIONS
using KeyContainer = std::vector<int>;
using ValueContainer = ThrowOnMoveContainer<int>;
@@ -87,5 +92,15 @@ int main(int, char**) {
}
#endif
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -23,7 +23,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -64,13 +64,18 @@ void test() {
assert(r.first->second == 3.5);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using value_type = typename FlatMap::value_type;
@@ -79,5 +84,15 @@ int main(int, char**) {
};
test_emplace_exception_guarantee(insert_func);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -12,10 +12,12 @@
// void insert(initializer_list<value_type> il);
#include <algorithm>
#include <flat_map>
#include <cassert>
#include <functional>
#include <deque>
#include <type_traits>
#include "MinSequenceContainer.h"
#include "../helpers.h"
@@ -23,11 +25,10 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
using V = std::pair<const int, double>;
M m = {{1, 1}, {1, 1.5}, {1, 2}, {3, 1}, {3, 1.5}, {3, 2}};
m.insert({
@@ -42,20 +43,29 @@ void test() {
{2, 2},
});
assert(m.size() == 4);
assert(std::distance(m.begin(), m.end()) == 4);
assert(*m.begin() == V(1, 1));
assert(*std::next(m.begin()) == V(2, 1));
assert(*std::next(m.begin(), 2) == V(3, 1));
assert(*std::next(m.begin(), 3) == V(4, 1));
assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3, 4}));
check_possible_values(
m.values(),
std::vector<std::vector<Value>>{
{1, 1.5, 2},
{1, 1.5, 2},
{1, 1.5, 2},
{1, 1.5, 2},
});
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto insert_func = [](auto& m, const auto& newValues) {
using FlatMap = std::decay_t<decltype(m)>;
using value_type = typename FlatMap::value_type;
@@ -64,5 +74,15 @@ int main(int, char**) {
};
test_insert_range_exception_guarantee(insert_func);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -23,7 +23,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -60,13 +60,18 @@ void test() {
assert(r->second == 3.5);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using value_type = typename FlatMap::value_type;
@@ -75,5 +80,15 @@ int main(int, char**) {
};
test_emplace_exception_guarantee(insert_func);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -38,7 +38,7 @@ static_assert(!CanInsert<Map, int, int>);
static_assert(!CanInsert<Map, cpp20_input_iterator<Pair*>, cpp20_input_iterator<Pair*>>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using P = std::pair<int, double>;
using M = std::flat_map<int, double, std::less<int>, KeyContainer, ValueContainer>;
@@ -68,22 +68,45 @@ void test() {
M m;
m.insert(cpp17_input_iterator<P*>(ar1), cpp17_input_iterator<P*>(ar1 + sizeof(ar1) / sizeof(ar1[0])));
assert(m.size() == 3);
M expected{{1, 1}, {2, 1}, {3, 1}};
assert(m == expected);
m.insert(cpp17_input_iterator<P*>(ar2), cpp17_input_iterator<P*>(ar2 + sizeof(ar2) / sizeof(ar2[0])));
assert(m.size() == 5);
M expected2{{0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}};
assert(m == expected2);
assert(std::ranges::equal(m.keys(), KeyContainer{1, 2, 3}));
check_possible_values(
m.values(),
std::vector<std::vector<double>>{
{1, 1.5, 2},
{1, 1.5, 2},
{1, 1.5, 2},
});
auto m2 = m;
m2.insert(cpp17_input_iterator<P*>(ar2), cpp17_input_iterator<P*>(ar2 + sizeof(ar2) / sizeof(ar2[0])));
assert(m2.size() == 5);
assert(std::ranges::equal(m2.keys(), KeyContainer{0, 1, 2, 3, 4}));
check_possible_values(
m2.values(),
std::vector<std::vector<double>>{
{1, 1.5, 2},
{m[1]},
{m[2]},
{m[3]},
{1, 1.5, 2},
});
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto insert_func = [](auto& m, const auto& newValues) { m.insert(newValues.begin(), newValues.end()); };
test_insert_range_exception_guarantee(insert_func);
}
@@ -94,5 +117,14 @@ int main(int, char**) {
assert(std::ranges::equal(m, std::vector<std::pair<int, int>>{{1, 1}, {2, 2}, {3, 3}, {4, 4}}));
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -22,7 +22,7 @@
#include "test_macros.h"
template <class Container, class Pair>
void do_insert_iter_rv_test() {
constexpr void do_insert_iter_rv_test() {
using M = Container;
using P = Pair;
using R = typename M::iterator;
@@ -53,7 +53,7 @@ void do_insert_iter_rv_test() {
}
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -64,17 +64,22 @@ void test() {
do_insert_iter_rv_test<M, CP>();
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::vector<int>, std::vector<MoveOnly>>();
test<std::deque<int>, std::deque<double>>();
test<std::deque<int>, std::deque<MoveOnly>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::deque<double>>();
test<std::deque<int>, std::deque<MoveOnly>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<MinSequenceContainer<int>, MinSequenceContainer<MoveOnly>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
test<std::vector<int, min_allocator<int>>, std::vector<MoveOnly, min_allocator<MoveOnly>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using value_type = typename FlatMap::value_type;
@@ -84,5 +89,14 @@ int main(int, char**) {
test_emplace_exception_guarantee(insert_func);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -78,7 +78,7 @@ static_assert(!CanInsertOrAssignIter<std::flat_map<int, ConstructFrom<V>>, int&&
static_assert(!CanInsertOrAssignIter<std::flat_map<int, AssignFrom<V>>, int&&, V>);
template <class KeyContainer, class ValueContainer>
void test_cv_key() {
constexpr void test_cv_key() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -194,7 +194,7 @@ void test_cv_key() {
}
template <class KeyContainer, class ValueContainer>
void test_rv_key() {
constexpr void test_rv_key() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -311,16 +311,30 @@ void test_rv_key() {
}
}
int main(int, char**) {
constexpr bool test() {
test_cv_key<std::vector<int>, std::vector<Moveable>>();
test_cv_key<std::deque<int>, std::vector<Moveable>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test_cv_key<std::deque<int>, std::vector<Moveable>>();
test_rv_key<std::deque<Moveable>, std::vector<Moveable>>();
}
test_cv_key<MinSequenceContainer<int>, MinSequenceContainer<Moveable>>();
test_cv_key<std::vector<int, min_allocator<int>>, std::vector<Moveable, min_allocator<Moveable>>>();
test_rv_key<std::vector<Moveable>, std::vector<Moveable>>();
test_rv_key<std::deque<Moveable>, std::vector<Moveable>>();
test_rv_key<MinSequenceContainer<Moveable>, MinSequenceContainer<Moveable>>();
test_rv_key<std::vector<Moveable, min_allocator<Moveable>>, std::vector<Moveable, min_allocator<Moveable>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -94,7 +94,7 @@ static_assert(
!CanInsertOrAssignIter<std::flat_map<int, AssignFrom<V>, TransparentComparator>, ConvertibleTransparent<int>, V>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -212,9 +212,14 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<Moveable>>();
test<std::deque<int>, std::vector<Moveable>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<Moveable>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<Moveable>>();
test<std::vector<int, min_allocator<int>>, std::vector<Moveable, min_allocator<Moveable>>>();
@@ -237,22 +242,24 @@ int main(int, char**) {
assert(transparent_used);
}
{
auto insert_or_assign = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
m.insert_or_assign(ConvertibleTransparent<Key>{key_arg}, value_arg);
};
test_emplace_exception_guarantee(insert_or_assign);
}
if (!TEST_IS_CONSTANT_EVALUATED) {
{
auto insert_or_assign = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
m.insert_or_assign(ConvertibleTransparent<Key>{key_arg}, value_arg);
};
test_emplace_exception_guarantee(insert_or_assign);
}
{
auto insert_or_assign_iter = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
m.insert_or_assign(m.begin(), ConvertibleTransparent<Key>{key_arg}, value_arg);
};
test_emplace_exception_guarantee(insert_or_assign_iter);
{
auto insert_or_assign_iter = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
m.insert_or_assign(m.begin(), ConvertibleTransparent<Key>{key_arg}, value_arg);
};
test_emplace_exception_guarantee(insert_or_assign_iter);
}
}
{
// LWG4239 std::string and C string literal
@@ -267,5 +274,14 @@ int main(int, char**) {
assert(it2->second == 2);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -39,7 +39,7 @@ static_assert(!CanInsertRange<Map, std::ranges::subrange<int*>>);
static_assert(!CanInsertRange<Map, std::ranges::subrange<double*>>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
@@ -68,7 +68,7 @@ void test() {
{
// The "uniquing" part uses the comparator, not operator==.
struct ModTen {
bool operator()(int a, int b) const { return (a % 10) < (b % 10); }
constexpr bool operator()(int a, int b) const { return (a % 10) < (b % 10); }
};
using P = std::pair<int, int>;
using M = std::flat_map<Key, Value, ModTen, KeyContainer, ValueContainer>;
@@ -79,9 +79,14 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<int>>();
test<std::deque<int>, std::vector<int>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<int>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<int>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
{
@@ -95,15 +100,25 @@ int main(int, char**) {
{
// The element type of the range doesn't need to be std::pair (P2767).
std::pair<int, int> pa[] = {{3, 3}, {1, 1}, {4, 4}, {1, 1}, {5, 5}};
std::deque<std::reference_wrapper<std::pair<int, int>>> a(pa, pa + 5);
std::vector<std::reference_wrapper<std::pair<int, int>>> a(pa, pa + 5);
std::flat_map<int, int> m;
m.insert_range(a);
std::pair<int, int> expected[] = {{1, 1}, {3, 3}, {4, 4}, {5, 5}};
assert(std::ranges::equal(m, expected));
}
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto insert_func = [](auto& m, const auto& newValues) { m.insert_range(newValues); };
test_insert_range_exception_guarantee(insert_func);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -25,7 +25,7 @@
#include "../helpers.h"
template <class Container, class Pair>
void do_insert_rv_test() {
constexpr void do_insert_rv_test() {
using M = Container;
using P = Pair;
using R = std::pair<typename M::iterator, bool>;
@@ -60,7 +60,7 @@ void do_insert_rv_test() {
}
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -72,9 +72,14 @@ void test() {
do_insert_rv_test<M, CP>();
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<MoveOnly>>();
test<std::deque<int>, std::vector<MoveOnly>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<MoveOnly>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<MoveOnly>>();
test<std::vector<int, min_allocator<int>>, std::vector<MoveOnly, min_allocator<MoveOnly>>>();
@@ -110,7 +115,7 @@ int main(int, char**) {
assert(r.first->first == 3);
assert(r.first->second == 3);
}
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using value_type = typename FlatMap::value_type;
@@ -120,5 +125,14 @@ int main(int, char**) {
test_emplace_exception_guarantee(insert_func);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -23,7 +23,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -39,20 +39,34 @@ void test() {
});
assert(m.size() == 5);
assert(std::distance(m.begin(), m.end()) == 5);
assert(*m.begin() == V(0, 1));
assert(*std::next(m.begin()) == V(1, 1));
assert(*std::next(m.begin(), 2) == V(2, 1));
assert(*std::next(m.begin(), 3) == V(3, 1));
assert(*std::next(m.begin(), 4) == V(4, 1));
auto v1 = *std::next(m.begin());
assert(v1.first == 1);
assert(v1.second == 1 || v1.second == 1.5 || v1.second == 2);
auto v2 = *std::next(m.begin(), 2);
assert(v2.first == 2);
assert(v2.second == 1);
auto v3 = *std::next(m.begin(), 3);
assert(v3.first == 3);
assert(v3.second == 1 || v3.second == 1.5 || v3.second == 2);
auto v4 = *std::next(m.begin(), 4);
assert(v4.first == 4);
assert(v4.second == 1);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto insert_func = [](auto& m, const auto& newValues) {
using FlatMap = std::decay_t<decltype(m)>;
using value_type = typename FlatMap::value_type;
@@ -62,5 +76,14 @@ int main(int, char**) {
test_insert_range_exception_guarantee(insert_func);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -37,7 +37,7 @@ static_assert(!CanInsert<Map, std::sorted_unique_t, int, int>);
static_assert(!CanInsert<Map, std::sorted_unique_t, cpp20_input_iterator<Pair*>, cpp20_input_iterator<Pair*>>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -69,18 +69,32 @@ void test() {
assert(m == expected2);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
auto insert_func = [](auto& m, const auto& newValues) {
m.insert(std::sorted_unique, newValues.begin(), newValues.end());
};
test_insert_range_exception_guarantee(insert_func);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -41,98 +41,42 @@ static_assert(CanInsert<Map, Iter, std::tuple<short, double>&&>);
static_assert(!CanInsert<Map, int>);
static_assert(!CanInsert<Map, Iter, int>);
static int expensive_comparisons = 0;
static int cheap_comparisons = 0;
struct CompareCounter {
int i_ = 0;
CompareCounter(int i) : i_(i) {}
friend auto operator<=>(const CompareCounter& x, const CompareCounter& y) {
expensive_comparisons += 1;
return x.i_ <=> y.i_;
}
bool operator==(const CompareCounter&) const = default;
friend auto operator<=>(const CompareCounter& x, int y) {
cheap_comparisons += 1;
return x.i_ <=> y;
}
};
template <class KeyContainer, class ValueContainer>
void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
const std::pair<int, int> expected[] = {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}};
constexpr bool test() {
{
// insert(P&&)
// template<class K> pair<iterator, bool> insert(P&& x);
bool transparent_used = false;
TransparentComparator c(transparent_used);
using M = std::flat_map<int, int, TransparentComparator>;
M m(std::sorted_unique, {{1, 1}, {2, 2}, {4, 4}}, c);
assert(!transparent_used);
std::same_as<std::pair<typename M::iterator, bool>> decltype(auto) res =
m.insert(std::pair(ConvertibleTransparent<int>{3}, 3));
assert(res.second);
assert(res.first->first == 3);
assert(res.first->second == 3);
// Unlike flat_set, here we can't use key_compare to compare value_type versus P,
// so we must eagerly convert to value_type.
M m = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
expensive_comparisons = 0;
cheap_comparisons = 0;
std::same_as<std::pair<typename M::iterator, bool>> auto p =
m.insert(std::make_pair(3, 3)); // conversion happens first
assert(expensive_comparisons >= 2);
assert(cheap_comparisons == 0);
assert(p == std::make_pair(m.begin() + 2, true));
assert(std::ranges::equal(m, expected));
assert(!transparent_used);
}
{
// insert(const_iterator, P&&)
M m = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
expensive_comparisons = 0;
cheap_comparisons = 0;
std::same_as<typename M::iterator> auto it = m.insert(m.begin(), std::make_pair(3, 3));
assert(expensive_comparisons >= 2);
assert(cheap_comparisons == 0);
assert(it == m.begin() + 2);
assert(std::ranges::equal(m, expected));
}
{
// insert(value_type&&)
M m = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
expensive_comparisons = 0;
cheap_comparisons = 0;
std::same_as<std::pair<typename M::iterator, bool>> auto p =
m.insert(std::make_pair(3, 3)); // conversion happens last
assert(expensive_comparisons >= 2);
assert(cheap_comparisons == 0);
assert(p == std::make_pair(m.begin() + 2, true));
assert(std::ranges::equal(m, expected));
}
{
// insert(const_iterator, value_type&&)
M m = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
expensive_comparisons = 0;
cheap_comparisons = 0;
std::same_as<typename M::iterator> auto it = m.insert(m.begin(), std::make_pair(3, 3));
assert(expensive_comparisons >= 2);
assert(cheap_comparisons == 0);
assert(it == m.begin() + 2);
assert(std::ranges::equal(m, expected));
}
{
// emplace(Args&&...)
M m = {{1, 1}, {2, 2}, {4, 4}, {5, 5}};
expensive_comparisons = 0;
cheap_comparisons = 0;
std::same_as<std::pair<typename M::iterator, bool>> auto p =
m.emplace(std::make_pair(3, 3)); // conversion happens first
assert(expensive_comparisons >= 2);
assert(cheap_comparisons == 0);
assert(p == std::make_pair(m.begin() + 2, true));
assert(std::ranges::equal(m, expected));
}
}
// template<class K> iterator insert(const_iterator hint, P&& x);
bool transparent_used = false;
TransparentComparator c(transparent_used);
using M = std::flat_map<int, int, TransparentComparator>;
M m(std::sorted_unique, {{1, 1}, {2, 2}, {4, 4}}, c);
assert(!transparent_used);
int main(int, char**) {
test<std::vector<CompareCounter>, std::vector<double>>();
test<std::deque<CompareCounter>, std::vector<double>>();
test<MinSequenceContainer<CompareCounter>, MinSequenceContainer<double>>();
test<std::vector<CompareCounter, min_allocator<CompareCounter>>, std::vector<double, min_allocator<double>>>();
std::same_as<typename M::iterator> decltype(auto) res =
m.insert(m.begin(), std::pair(ConvertibleTransparent<int>{3}, 3));
assert(res->first == 3);
assert(res->second == 3);
// Unlike flat_set, here we can't use key_compare to compare value_type versus P,
// so we must eagerly convert to value_type.
assert(!transparent_used);
}
{
// no ambiguity between insert(pos, P&&) and insert(first, last)
using M = std::flat_map<int, int>;
@@ -145,23 +89,26 @@ int main(int, char**) {
ASSERT_SAME_TYPE(decltype(m.insert(m.begin(), Evil())), M::iterator);
ASSERT_SAME_TYPE(decltype(m.insert(m.begin(), m.end())), void);
}
{
auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using tuple_type = std::tuple<typename FlatMap::key_type, typename FlatMap::mapped_type>;
tuple_type t(key_arg, value_arg);
m.insert(t);
};
test_emplace_exception_guarantee(insert_func);
}
{
auto insert_func_iter = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using tuple_type = std::tuple<typename FlatMap::key_type, typename FlatMap::mapped_type>;
tuple_type t(key_arg, value_arg);
m.insert(m.begin(), t);
};
test_emplace_exception_guarantee(insert_func_iter);
if (!TEST_IS_CONSTANT_EVALUATED) {
{
auto insert_func = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using tuple_type = std::tuple<typename FlatMap::key_type, typename FlatMap::mapped_type>;
tuple_type t(key_arg, value_arg);
m.insert(t);
};
test_emplace_exception_guarantee(insert_func);
}
{
auto insert_func_iter = [](auto& m, auto key_arg, auto value_arg) {
using FlatMap = std::decay_t<decltype(m)>;
using tuple_type = std::tuple<typename FlatMap::key_type, typename FlatMap::mapped_type>;
tuple_type t(key_arg, value_arg);
m.insert(m.begin(), t);
};
test_emplace_exception_guarantee(insert_func_iter);
}
}
{
// LWG4239 std::string and C string literal
@@ -173,5 +120,15 @@ int main(int, char**) {
auto it2 = m.insert(m.begin(), {"beta2", 2});
assert(it2 == m.begin() + 2);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -33,7 +33,7 @@ static_assert(!CanReplace<Map, std::vector<int>, const std::vector<int>&>);
static_assert(!CanReplace<Map, const std::vector<int>&, const std::vector<int>&>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -49,13 +49,18 @@ void test() {
assert(std::ranges::equal(m.values(), expected_values));
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
{
if (!TEST_IS_CONSTANT_EVALUATED) {
#ifndef TEST_HAS_NO_EXCEPTIONS
using KeyContainer = std::vector<int>;
using ValueContainer = ThrowOnMoveContainer<int>;
@@ -76,5 +81,15 @@ int main(int, char**) {
}
#endif
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -39,7 +39,7 @@ static_assert(
#endif
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -87,11 +87,25 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -38,7 +38,7 @@ static_assert(
#endif
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -85,11 +85,25 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<double>>();
test<std::deque<int>, std::vector<double>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<double>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<double>>();
test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -63,7 +63,7 @@ static_assert(!CanTryEmplace<Map, Iter, Emplaceable, const Emplaceable&>);
static_assert(!CanTryEmplace<Map, Iter, Emplaceable, int>);
template <class KeyContainer, class ValueContainer>
void test_ck() {
constexpr void test_ck() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -101,7 +101,7 @@ void test_ck() {
assert(r3.first->second.get() == 5); // value
Moveable mv3(-1, 3.0);
std::same_as<R> decltype(auto) r4 = m.try_emplace(117, std::move(mv2));
std::same_as<R> decltype(auto) r4 = m.try_emplace(117, std::move(mv3));
assert(m.size() == 13);
assert(r4.second); // was inserted
assert(mv2.moved()); // was moved from
@@ -135,7 +135,7 @@ void test_ck() {
}
template <class KeyContainer, class ValueContainer>
void test_rk() {
constexpr void test_rk() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -193,54 +193,70 @@ void test_rk() {
}
}
int main(int, char**) {
constexpr bool test() {
test_ck<std::vector<int>, std::vector<Moveable>>();
test_ck<std::deque<int>, std::vector<Moveable>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test_ck<std::deque<int>, std::vector<Moveable>>();
test_rk<std::deque<Moveable>, std::vector<Moveable>>();
}
test_ck<MinSequenceContainer<int>, MinSequenceContainer<Moveable>>();
test_ck<std::vector<int, min_allocator<int>>, std::vector<Moveable, min_allocator<Moveable>>>();
test_rk<std::vector<Moveable>, std::vector<Moveable>>();
test_rk<std::deque<Moveable>, std::vector<Moveable>>();
test_rk<MinSequenceContainer<Moveable>, MinSequenceContainer<Moveable>>();
test_rk<std::vector<Moveable, min_allocator<Moveable>>, std::vector<Moveable, min_allocator<Moveable>>>();
{
auto try_emplace_ck = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
const Key key{key_arg};
m.try_emplace(key, value_arg);
};
test_emplace_exception_guarantee(try_emplace_ck);
if (!TEST_IS_CONSTANT_EVALUATED) {
{
auto try_emplace_ck = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
const Key key{key_arg};
m.try_emplace(key, value_arg);
};
test_emplace_exception_guarantee(try_emplace_ck);
}
{
auto try_emplace_rk = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
m.try_emplace(Key{key_arg}, value_arg);
};
test_emplace_exception_guarantee(try_emplace_rk);
}
{
auto try_emplace_iter_ck = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
const Key key{key_arg};
m.try_emplace(m.begin(), key, value_arg);
};
test_emplace_exception_guarantee(try_emplace_iter_ck);
}
{
auto try_emplace_iter_rk = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
m.try_emplace(m.begin(), Key{key_arg}, value_arg);
};
test_emplace_exception_guarantee(try_emplace_iter_rk);
}
}
{
auto try_emplace_rk = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
m.try_emplace(Key{key_arg}, value_arg);
};
test_emplace_exception_guarantee(try_emplace_rk);
}
return true;
}
{
auto try_emplace_iter_ck = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
const Key key{key_arg};
m.try_emplace(m.begin(), key, value_arg);
};
test_emplace_exception_guarantee(try_emplace_iter_ck);
}
{
auto try_emplace_iter_rk = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
m.try_emplace(m.begin(), Key{key_arg}, value_arg);
};
test_emplace_exception_guarantee(try_emplace_iter_rk);
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -7,6 +7,8 @@
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20
// gcc 15 ICE on this test
// UNSUPPORTED: gcc
// <flat_map>
@@ -65,7 +67,7 @@ static_assert(!CanTryEmplace<NonTransparentMap, TransparentMapConstIter, NonConv
static_assert(!CanTryEmplace<TransparentMap, TransparentMapConstIter, ConvertibleTransparent<int>, int>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -103,7 +105,7 @@ void test() {
assert(r3.first->second.get() == 5); // value
Moveable mv3(-1, 3.0);
std::same_as<R> decltype(auto) r4 = m.try_emplace(ConvertibleTransparent<int>{117}, std::move(mv2));
std::same_as<R> decltype(auto) r4 = m.try_emplace(ConvertibleTransparent<int>{117}, std::move(mv3));
assert(m.size() == 13);
assert(r4.second); // was inserted
assert(mv2.moved()); // was moved from
@@ -136,9 +138,14 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<Moveable>>();
test<std::deque<int>, std::vector<Moveable>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<Moveable>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<Moveable>>();
test<std::vector<int, min_allocator<int>>, std::vector<Moveable, min_allocator<Moveable>>>();
@@ -171,23 +178,34 @@ int main(int, char**) {
auto it2 = m.try_emplace(m.begin(), "beta2", 2);
assert(it2 == m.begin() + 2);
}
{
auto try_emplace = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
m.try_emplace(ConvertibleTransparent<Key>{key_arg}, value_arg);
};
test_emplace_exception_guarantee(try_emplace);
if (!TEST_IS_CONSTANT_EVALUATED) {
{
auto try_emplace = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
m.try_emplace(ConvertibleTransparent<Key>{key_arg}, value_arg);
};
test_emplace_exception_guarantee(try_emplace);
}
{
auto try_emplace_iter = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
m.try_emplace(m.begin(), ConvertibleTransparent<Key>{key_arg}, value_arg);
};
test_emplace_exception_guarantee(try_emplace_iter);
}
}
{
auto try_emplace_iter = [](auto& m, auto key_arg, auto value_arg) {
using M = std::decay_t<decltype(m)>;
using Key = typename M::key_type;
m.try_emplace(m.begin(), ConvertibleTransparent<Key>{key_arg}, value_arg);
};
test_emplace_exception_guarantee(try_emplace_iter);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -16,12 +16,13 @@
#include <cassert>
#include <flat_map>
#include <functional>
#include <type_traits>
#include <utility>
#include <vector>
#include "test_macros.h"
int main(int, char**) {
constexpr bool test() {
{
using M = std::flat_map<int, char>;
using Comp = std::less<int>; // the default
@@ -38,7 +39,7 @@ int main(int, char**) {
assert(vc({1, '2'}, {2, '1'}));
assert(!vc({2, '1'}, {1, '2'}));
}
{
if (!TEST_IS_CONSTANT_EVALUATED) {
using Comp = std::function<bool(int, int)>;
using M = std::flat_map<int, int, Comp>;
Comp comp = std::greater<int>();
@@ -72,7 +73,7 @@ int main(int, char**) {
assert(vc({1, 2}, {2, 1}));
assert(!vc({2, 1}, {1, 2}));
}
{
if (!TEST_IS_CONSTANT_EVALUATED) {
using Comp = std::function<bool(const std::vector<int>&, const std::vector<int>&)>;
using M = std::flat_map<std::vector<int>, int, Comp>;
Comp comp = [i = 1](const auto& x, const auto& y) { return x[i] < y[i]; };
@@ -92,5 +93,15 @@ int main(int, char**) {
assert(!vc(b, a));
assert(!vc(c, b));
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -28,7 +28,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -47,11 +47,25 @@ void test() {
assert(std::ranges::equal(values, expected_values));
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
test<std::deque<int>, std::vector<char>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<char>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -23,7 +23,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
{
@@ -60,11 +60,25 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<int>>();
test<std::deque<int>, std::vector<int>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<int>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<int>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -35,7 +35,7 @@ static_assert(!CanContains<NonTransparentMap>);
static_assert(!CanContains<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -53,9 +53,14 @@ void test() {
assert(m.contains(Transparent<std::string>{"g"}) == false);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<std::string>, std::vector<int>>();
test<std::deque<std::string>, std::vector<int>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<std::string>, std::vector<int>>();
}
test<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test<std::vector<std::string, min_allocator<std::string>>, std::vector<int, min_allocator<int>>>();
@@ -75,5 +80,15 @@ int main(int, char**) {
assert(m.contains("beta") == true);
assert(m.contains("charlie") == false);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -23,7 +23,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
@@ -59,11 +59,25 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<int>>();
test<std::deque<int>, std::vector<int>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<int>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<int>>();
test<std::vector<int, min_allocator<int>>, std::vector<int, min_allocator<int>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -35,7 +35,7 @@ static_assert(!CanCount<NonTransparentMap>);
static_assert(!CanCount<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -53,9 +53,14 @@ void test() {
assert(m.count(Transparent<std::string>{"g"}) == 0);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<std::string>, std::vector<int>>();
test<std::deque<std::string>, std::vector<int>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<std::string>, std::vector<int>>();
}
test<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test<std::vector<std::string, min_allocator<std::string>>, std::vector<int, min_allocator<int>>>();
@@ -76,5 +81,14 @@ int main(int, char**) {
assert(m.count("charlie") == 0);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -24,7 +24,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
{
@@ -68,11 +68,25 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
test<std::deque<int>, std::vector<char>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<char>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -36,7 +36,7 @@ static_assert(!CanEqualRange<NonTransparentMap>);
static_assert(!CanEqualRange<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -81,9 +81,14 @@ void test() {
test_not_found(cm, "zzz", 5);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<std::string>, std::vector<int>>();
test<std::deque<std::string>, std::vector<int>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<std::string>, std::vector<int>>();
}
test<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test<std::vector<std::string, min_allocator<std::string>>, std::vector<int, min_allocator<int>>>();
@@ -105,5 +110,14 @@ int main(int, char**) {
assert(last == m.begin() + 2);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -25,7 +25,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, std::less<Key>, KeyContainer, ValueContainer>;
@@ -45,11 +45,25 @@ void test() {
assert(std::as_const(m).find(9) == m.end());
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
test<std::deque<int>, std::vector<char>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<char>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -36,7 +36,7 @@ static_assert(!CanFind<NonTransparentMap>);
static_assert(!CanFind<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -69,9 +69,14 @@ void test() {
test_find(cm, "zzz", 5);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<std::string>, std::vector<int>>();
test<std::deque<std::string>, std::vector<int>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<std::string>, std::vector<int>>();
}
test<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test<std::vector<std::string, min_allocator<std::string>>, std::vector<int, min_allocator<int>>>();
@@ -92,5 +97,14 @@ int main(int, char**) {
assert(it == m.begin() + 1);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -24,7 +24,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
{
@@ -61,11 +61,25 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
test<std::deque<int>, std::vector<char>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<char>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -36,7 +36,7 @@ static_assert(!CanLowerBound<NonTransparentMap>);
static_assert(!CanLowerBound<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -76,9 +76,14 @@ void test() {
test_lower_bound(cm, "zzz", 5);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<std::string>, std::vector<int>>();
test<std::deque<std::string>, std::vector<int>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<std::string>, std::vector<int>>();
}
test<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test<std::vector<std::string, min_allocator<std::string>>, std::vector<int, min_allocator<int>>>();
@@ -99,5 +104,14 @@ int main(int, char**) {
assert(it == m.begin() + 2);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -24,7 +24,7 @@
#include "min_allocator.h"
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
{
@@ -62,11 +62,25 @@ void test() {
}
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<int>, std::vector<char>>();
test<std::deque<int>, std::vector<char>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<int>, std::vector<char>>();
}
test<MinSequenceContainer<int>, MinSequenceContainer<char>>();
test<std::vector<int, min_allocator<int>>, std::vector<char, min_allocator<char>>>();
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

View File

@@ -36,7 +36,7 @@ static_assert(!CanUpperBound<NonTransparentMap>);
static_assert(!CanUpperBound<const NonTransparentMap>);
template <class KeyContainer, class ValueContainer>
void test() {
constexpr void test() {
using Key = typename KeyContainer::value_type;
using Value = typename ValueContainer::value_type;
using M = std::flat_map<Key, Value, TransparentComparator, KeyContainer, ValueContainer>;
@@ -76,9 +76,14 @@ void test() {
test_upper_bound(cm, "zzz", 5);
}
int main(int, char**) {
constexpr bool test() {
test<std::vector<std::string>, std::vector<int>>();
test<std::deque<std::string>, std::vector<int>>();
#ifndef __cpp_lib_constexpr_deque
if (!TEST_IS_CONSTANT_EVALUATED)
#endif
{
test<std::deque<std::string>, std::vector<int>>();
}
test<MinSequenceContainer<std::string>, MinSequenceContainer<int>>();
test<std::vector<std::string, min_allocator<std::string>>, std::vector<int, min_allocator<int>>>();
{
@@ -98,5 +103,14 @@ int main(int, char**) {
assert(it == m.begin() + 2);
}
return true;
}
int main(int, char**) {
test();
#if TEST_STD_VER >= 26
static_assert(test());
#endif
return 0;
}

Some files were not shown because too many files have changed in this diff Show More