-
Notifications
You must be signed in to change notification settings - Fork 122
/
terse.cpp
49 lines (40 loc) · 1.21 KB
/
terse.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
//
// Copyright (c) 2019-2020 Kris Jusiak (kris at jusiak dot net)
//
// 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 <boost/ut.hpp>
constexpr auto sum = [](auto... args) { return (0 + ... + args); };
struct foo {
int a{};
bool b{};
constexpr auto operator==(const foo& other) const {
return a == other.a and b == other.b;
}
constexpr auto operator!=(const foo& other) const {
return not(*this == other);
}
friend auto& operator<<(std::ostream& os, const foo& f) {
return (os << "foo{" << f.a << ',' << f.b << '}');
}
};
int main() {
using boost::ut::operator""_test;
using namespace boost::ut::literals;
using namespace boost::ut::operators::terse;
"terse"_test = [] {
6_i == sum(1, 2, 3);
sum(1, 1) == 2_i;
(42_i == sum(40, 2)) and (0_i != sum(1) or 4_i == 3);
};
// clang-format off
"terse type"_test = [] {
foo{.a = 42, .b = true}%_t == foo{42, true};
foo{.a = 43, .b = true} != foo{42, true}%_t;
constexpr auto make_foo = [](auto... args) { return foo{args...}; };
foo{42, true} == make_foo(42, true)%_t;
};
// clang-format on
}