tess
0.4.0
Performance-first tile and path simulation substrate
Toggle main menu visibility
Loading...
Searching...
No Matches
assert.h
1
#pragma once
2
3
#include <cstdio>
4
#include <cstdlib>
5
6
// TESS_ASSERT documents and enforces preconditions of unchecked fast-path
7
// APIs (for example World::resolve with an out-of-shape coordinate).
8
//
9
// Policy:
10
// - Checked entry points (try_resolve, try_field, plan validation) stay the
11
// runtime-validated API and never assert on bad input.
12
// - Unchecked hot accessors keep noexcept and assert their preconditions.
13
// - Asserts are enabled when TESS_ENABLE_ASSERTS is defined non-zero, and
14
// default to on exactly when NDEBUG is absent. Release and bench builds
15
// define NDEBUG, so asserts have zero cost there.
16
// - A failed assert aborts; it never throws, so noexcept functions stay
17
// noexcept.
18
#if !defined(TESS_ENABLE_ASSERTS)
19
#if defined(NDEBUG)
21
#define TESS_ENABLE_ASSERTS 0
22
#else
23
#define TESS_ENABLE_ASSERTS 1
24
#endif
25
#endif
26
27
namespace
tess::detail {
28
29
[[noreturn]]
inline
void
assert_fail(
const
char
* expression,
const
char
* file,
30
unsigned
line)
noexcept
{
31
std::fprintf(stderr,
"%s:%u: tess assertion failed: %s\n"
, file, line,
32
expression);
33
std::abort();
34
}
35
36
}
// namespace tess::detail
37
38
#if TESS_ENABLE_ASSERTS
40
#define TESS_ASSERT(condition) \
41
((condition) ? static_cast<void>(0) \
42
: ::tess::detail::assert_fail(#condition, __FILE__, __LINE__))
44
#define TESS_ASSERT_MSG(condition, message) \
45
((condition) ? static_cast<void>(0) \
46
: ::tess::detail::assert_fail(message, __FILE__, __LINE__))
47
#else
48
#define TESS_ASSERT(condition) static_cast<void>(0)
49
#define TESS_ASSERT_MSG(condition, message) static_cast<void>(0)
50
#endif
include
tess
core
assert.h
Generated by
1.17.0