1#ifndef LIBSBX_UTILITY_ASSERT_HPP_
2#define LIBSBX_UTILITY_ASSERT_HPP_
6#include <source_location>
11#include <libsbx/utility/target.hpp>
13namespace sbx::utility {
15template<std::convertible_to<
bool> Expression>
16inline auto assert_that(Expression&& expression, std::string_view message,
const std::source_location& source_location = std::source_location::current()) ->
void {
17 if constexpr (build_configuration_v == build_configuration::debug) {
18 if (!
static_cast<bool>(expression)) {
19 const auto error = fmt::format(
"Assertion '{}' at {}:{} in '{}' failed. Terminating", message, source_location.file_name(), source_location.line(), source_location.function_name());
20 std::cerr.write(error.data(),
static_cast<std::streamsize
>(error.size()));
27template<std::convertible_to<
bool> Expression>
28inline auto expect_that(Expression&& expression, std::string_view message,
const std::source_location& source_location = std::source_location::current()) ->
void {
29 if constexpr (build_configuration_v == build_configuration::debug) {
30 if (!
static_cast<bool>(expression)) {
31 const auto warning = fmt::format(
"Expectation '{}' at {}:{} in '{}' failed.", message, source_location.file_name(), source_location.line(), source_location.function_name());
32 std::cerr.write(warning.data(),
static_cast<std::streamsize
>(warning.size()));