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
25 template <class T>
26 requires std::constructible_from<std::string_view, T>
27 // NOLINTNEXTLINE
28 StringViewSourceLoc(const T &msg, const std::source_location loc = std::source_location::current()) noexcept
29 : msg_{msg}, loc_{loc}
30 {
31 }
32
33 std::string_view msg_;
34 std::source_location loc_;
35};
36
45void set_panic_stacktrace_enabled(bool enabled);
46
50[[nodiscard]] bool is_panic_stacktrace_enabled();
51
59[[noreturn]] void panic(const StringViewSourceLoc &s);
60
69void assert_or_panic(bool condition, const StringViewSourceLoc &s);
70
71} // 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:15
std::string_view msg_
Definition panic.hpp:33
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:28
std::source_location loc_
Definition panic.hpp:34