Skip to content

Commit c49932f

Browse files
committed
hpp
1 parent 69deb55 commit c49932f

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ target_sources(
8383
BASE_DIRS include "${CMAKE_CURRENT_BINARY_DIR}/include"
8484
FILES
8585
include/eggs/assert.h
86+
include/eggs/assert.hpp
8687
"${CMAKE_CURRENT_BINARY_DIR}/include/eggs/assert-export.h"
8788
)
8889

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
**Eggs.Assert** is a **C++23** assertion library with stacktrace.
66

7+
Link against `Eggs::Assert` and include one of:
8+
9+
- `<eggs/assert.h>` — replaces the standard `assert` macro with one that prints a full stacktrace on failure.
10+
- `<eggs/assert.hpp>` — provides `EGGS_ASSERT` under its own name, leaving the standard `assert` untouched.
11+
712
---
813

914
> Copyright *Agustín Bergé*, *Fusion Fenix* 2026

include/eggs/assert.hpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Eggs.Assert
2+
//
3+
// Copyright Agustin K-ballo Berge, Fusion Fenix 2026
4+
//
5+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
6+
// file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7+
8+
#pragma once
9+
10+
#ifdef NDEBUG
11+
12+
# define EGGS_ASSERT(...) ((void)0)
13+
14+
#else
15+
16+
# include <eggs/assert-export.h>
17+
18+
# include <source_location>
19+
20+
extern "C" [[noreturn]] EGGS_ASSERT_EXPORT void eggs_assert_failed(
21+
char const* message, char const* file, unsigned line, char const* function
22+
);
23+
24+
# define EGGS_ASSERT(...) \
25+
((__VA_ARGS__) \
26+
? (void)0 \
27+
: ::eggs_assert_failed( \
28+
#__VA_ARGS__, std::source_location::current().file_name(), \
29+
(unsigned)std::source_location::current().line(), \
30+
std::source_location::current().function_name() \
31+
))
32+
33+
#endif // NDEBUG

0 commit comments

Comments
 (0)