WPILibC++ 2027.0.0-alpha-3
Loading...
Searching...
No Matches
assert.hpp
Go to the documentation of this file.
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#ifdef JORMUNGANDR
6#include <source_location>
7#include <stdexcept>
8
9#include <fmt/format.h>
10/**
11 * Throw an exception in Python.
12 */
13#define slp_assert(condition) \
14 do { \
15 if (!(condition)) { \
16 auto location = std::source_location::current(); \
17 throw std::invalid_argument(fmt::format( \
18 "{}:{}: {}: Assertion `{}' failed.", location.file_name(), \
19 location.line(), location.function_name(), #condition)); \
20 } \
21 } while (0);
22#else
23#include <cassert>
24/**
25 * Abort in C++.
26 */
27#define slp_assert(condition) assert(condition)
28#endif