kaycxx-assert
C++ assertion library
Loading...
Searching...
No Matches
assert_less.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Klaus Reimer <k@ailis.de>
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
11#include <format>
12#include <string_view>
13#include <utility>
14
16#include <kaycxx/assert/detail/source_location.hpp>
17#include <kaycxx/assert/detail/ordered_value.hpp>
18#include <kaycxx/assert/detail/to_string.hpp>
19
20namespace kaycxx::assert {
21
37template <detail::ordered_value T>
39 T const& actual,
40 T const& expected,
41 std::string_view reason = {},
42 std::optional<std::source_location> location = KAYCXX_ASSERT_DEFAULT_SOURCE
43) {
44 if (!(actual < expected)) {
45 auto actual_string = detail::to_string(actual);
46 auto expected_string = detail::to_string(expected);
47 auto message = std::format("Expected <{}> to be less than <{}>", actual_string, expected_string);
48 throw assertion_error(
49 message,
50 reason,
51 std::move(actual_string),
52 std::move(expected_string),
53 location
54 );
55 }
56}
57
58} // namespace kaycxx::assert
Defines the assertion_error type.
Assertion functions and related types.
Definition assert.hpp:15
void assert_less(T const &actual, T const &expected, std::string_view reason={}, std::optional< std::source_location > location=KAYCXX_ASSERT_DEFAULT_SOURCE)
Asserts that the actual value is less than the expected value.
Definition assert_less.hpp:38