forked from tcbrindle/flux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_unchecked.cpp
63 lines (42 loc) · 1.55 KB
/
test_unchecked.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2023 Tristan Brindle (tcbrindle at gmail dot com)
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <array>
#include "test_utils.hpp"
namespace {
constexpr bool test_unchecked()
{
using namespace flux;
{
auto seq = unchecked(std::array{5, 4, 3, 2, 1});
using S = decltype(seq);
static_assert(contiguous_sequence<S>);
static_assert(sized_sequence<S>);
static_assert(bounded_sequence<S>);
seq.sort();
STATIC_CHECK(check_equal(seq, {1, 2, 3, 4, 5}));
}
{
auto ints = std::array{5, 4, 3, 2, 1};
auto doubles = std::array{3.0, 2.0, 1.0};
auto seq = unchecked(zip(mut_ref(ints), mut_ref(doubles)));
using S = decltype(seq);
static_assert(random_access_sequence<S>);
static_assert(bounded_sequence<S>);
static_assert(sized_sequence<S>);
static_assert(std::same_as<value_t<S>, std::pair<int, double>>);
static_assert(std::same_as<element_t<S>, std::pair<int&, double&>>);
static_assert(std::same_as<rvalue_element_t<S>, std::pair<int&&, double&&>>);
seq.sort(flux::proj(std::weak_order, [](auto p) { return p.second; }));
STATIC_CHECK(check_equal(doubles, {1.0, 2.0, 3.0}));
STATIC_CHECK(check_equal(ints, {3, 4, 5, 2, 1}));
}
return true;
}
static_assert(test_unchecked());
}
TEST_CASE("unchecked adaptor")
{
auto res = test_unchecked();
REQUIRE(res);
}