-
Notifications
You must be signed in to change notification settings - Fork 2
/
utility.cpp
54 lines (42 loc) · 1.08 KB
/
utility.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
// SPDX-License-Identifier: BSL-1.0
#undef NDEBUG
#include <etl/cassert.hpp>
#include <etl/type_traits.hpp>
#include <etl/utility.hpp>
auto main() -> int
{
// SWAP
auto v1 = 42;
auto v2 = 100;
etl::swap(v1, v2);
assert(v1 == 100);
assert(v2 == 42);
// EXCHANGE
auto val = 1;
assert(etl::exchange(val, 2) == 1);
// AS CONST
auto c = 1;
static_assert(!etl::is_const_v<decltype(c)>);
static_assert(etl::is_const_v<etl::remove_reference_t<decltype(etl::as_const(c))>>);
// CMP
static_assert(etl::cmp_equal(42, 42));
static_assert(!etl::cmp_equal(42UL, 100UL));
static_assert(etl::cmp_not_equal(42UL, 100UL));
// PAIR construct
auto p1 = etl::pair<int, float>{1, 42.0F};
assert(p1.first == 1);
auto p2 = etl::make_pair(2, 1.43F);
assert(p2.first == 2);
auto p3 = p1;
assert(p3.first == 1);
// PAIR compare
assert(p1 == p3);
assert(p1 != p2);
assert(p2 > p3);
assert(p3 < p2);
// PAIR swap
swap(p2, p3);
assert(p2.first == 1);
assert(p3.first == 2);
return 0;
}