Skip to content

Commit

Permalink
🆕 [ut] Add ""_b named boolean expression
Browse files Browse the repository at this point in the history
Problem:
- Use `true_b/false_` doesn't say much about the intent.

Solution:
- Named boolean expressions makes it convenient and cleaner.
  • Loading branch information
kris-jusiak authored and krzysztof-jusiak committed Mar 8, 2020
1 parent 7c7e9aa commit 5cc7950
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions example/expect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,10 @@ int main() {
expect(bool(std::make_unique<int>()));
expect(not bool(std::unique_ptr<int>{}));
};

"boolean"_test = [] {
expect("true"_b);
expect("true"_b and not false_b);
expect(not"true"_b == false_b);
};
}
3 changes: 3 additions & 0 deletions include/boost/ut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1976,6 +1976,9 @@ struct suite {

[[maybe_unused]] constexpr auto true_b = detail::integral_constant<true>{};
[[maybe_unused]] constexpr auto false_b = detail::integral_constant<false>{};
constexpr auto operator""_b(const char*, decltype(sizeof(""))) {
return true_b;
}

[[maybe_unused]] inline auto log = detail::log{};
[[maybe_unused]] inline auto that = detail::that_{};
Expand Down
1 change: 1 addition & 0 deletions test/ut/ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ int main() {
{
static_assert(true_b);
static_assert(not false_b);
static_assert("named"_b);
static_assert(42 == 42_i);
static_assert(0u == 0_u);
static_assert(42u == 42_u);
Expand Down

0 comments on commit 5cc7950

Please sign in to comment.