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