kaycxx-assert
C++ assertion library
Loading...
Searching...
No Matches
assert_not_equal.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/equals.hpp>
18#include <kaycxx/assert/detail/to_string.hpp>
19
20namespace kaycxx::assert {
21
39template <typename Actual, typename Expected>
40requires detail::equals_supported<Actual, Expected>
42 Actual const& actual,
43 Expected const& expected,
44 std::string_view reason = {},
45 std::optional<std::source_location> location = KAYCXX_ASSERT_DEFAULT_SOURCE
46) {
47 if (detail::equals(actual, expected)) {
48 auto actual_string = detail::to_string(actual);
49 auto expected_string = detail::to_string(expected);
50 auto message = std::format("Expected <{}> not to equal <{}>", actual_string, expected_string);
51 throw assertion_error(
52 message,
53 reason,
54 std::move(actual_string),
55 std::move(expected_string),
56 location
57 );
58 }
59}
60
61} // namespace kaycxx::assert
Defines the assertion_error type.
Assertion functions and related types.
Definition assert.hpp:15
void assert_not_equal(Actual const &actual, Expected const &expected, std::string_view reason={}, std::optional< std::source_location > location=KAYCXX_ASSERT_DEFAULT_SOURCE)
Asserts that two values are not equal.
Definition assert_not_equal.hpp:41