#pragma once #include "format.hpp" #include "source_location.hpp" #include <format> #include <iostream> #include <string_view> namespace util { template <typename... Ts> struct panic { [[noreturn]] constexpr panic( std::string_view fmt, Ts &&...args, const source_location &source = source_location::current()) noexcept { const auto str = std::format("Panic in function {} in file {}:{},{}: {}\n", source.function_name(), source.file_name(), source.line(), source.column(), format(fmt, std::forward<Ts>(args)...)); std::cerr.write(str.c_str(), str.size()); std::abort(); } }; template <typename... Ts> panic(std::string_view, Ts &&...) -> panic<Ts...>; } // namespace util