Porytiles
Loading...
Searching...
No Matches
panic.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <concepts>
4#include <source_location>
5#include <string_view>
6
7namespace porytiles {
8
29 template <class T>
30 requires std::constructible_from<std::string_view, T>
31 // NOLINTNEXTLINE
32 StringViewSourceLoc(const T &msg, const std::source_location loc = std::source_location::current()) noexcept
33 : msg_{msg}, loc_{loc}
34 {
35 }
36
37 std::string_view msg_;
38 std::source_location loc_;
39};
40
51void set_panic_stacktrace_enabled(bool enabled);
52
58[[nodiscard]] bool is_panic_stacktrace_enabled();
59
69[[noreturn]] void panic(const StringViewSourceLoc &s);
70
81void assert_or_panic(bool condition, const StringViewSourceLoc &s);
82
83} // namespace porytiles
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
Definition panic.cpp:43
void assert_or_panic(bool condition, const StringViewSourceLoc &s)
Conditionally panics if the given condition is false.
Definition panic.cpp:53
bool is_panic_stacktrace_enabled()
Returns whether stacktrace generation is enabled on panic.
Definition panic.cpp:38
void set_panic_stacktrace_enabled(bool enabled)
Enables or disables stacktrace generation on panic.
Definition panic.cpp:33
A wrapper for std::string_view with a taggable std::source_location.
Definition panic.hpp:17
std::string_view msg_
Definition panic.hpp:37
StringViewSourceLoc(const T &msg, const std::source_location loc=std::source_location::current()) noexcept
Constructs a StringViewSourceLoc with a message and optional source location.
Definition panic.hpp:32
std::source_location loc_
Definition panic.hpp:38