kaycxx-assert
C++ assertion library
Loading...
Searching...
No Matches
assert_null.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/nullable.hpp>
18#include <kaycxx/assert/detail/to_string.hpp>
19
20namespace kaycxx::assert {
21
33template <detail::nullable T>
35 T const& actual,
36 std::string_view reason = {},
37 std::optional<std::source_location> location = KAYCXX_ASSERT_DEFAULT_SOURCE
38) {
39 if (!(actual == nullptr)) {
40 auto actual_string = detail::to_string(actual);
41 auto message = std::format("Expected <{}> to be null", actual_string);
42 throw assertion_error(
43 message,
44 reason,
45 std::move(actual_string),
46 "null",
47 location
48 );
49 }
50}
51
52} // namespace kaycxx::assert
Defines the assertion_error type.
Assertion functions and related types.
Definition assert.hpp:15
void assert_null(T const &actual, std::string_view reason={}, std::optional< std::source_location > location=KAYCXX_ASSERT_DEFAULT_SOURCE)
Asserts that the argument is null.
Definition assert_null.hpp:34