codac 1.5.6
Loading...
Searching...
No Matches
codac2_assert.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <cstdlib>
13#include <cassert>
14#include <sstream>
15// C++20 not fully supported by compilers yet: #include <source_location>
16
17namespace codac2
18{
19 #if defined FAST_RELEASE & defined NDEBUG
20
21 #define assert_release(ignore_test) ((void)0)
22
23 #else
24
25 #if defined __PRETTY_FUNCTION__
26
27 #define assert_release(test) \
28 if(!(test)) \
29 { \
30 std::string s = std::string("\n=============================================================================") \
31 + "\nThe following Codac assertion failed:\n\n\t" + std::string(#test) \
32 + "\n \nIn: " + std::string(__FILE__) + ":" + std::to_string(__LINE__) \
33 + "\nFunction: " + std::string(__PRETTY_FUNCTION__) \
34 + "\nYou need help? Submit an issue on: https://github.com/codac-team/codac/issues" \
35 + "\n============================================================================="; \
36 throw std::invalid_argument(s); \
37 abort(); \
38 } \
39 \
40
41 #else
42
43 #define assert_release(test) \
44 if(!(test)) \
45 { \
46 std::string s = std::string("\n=============================================================================") \
47 + "\nThe following Codac assertion failed:\n\n\t" + std::string(#test) \
48 + "\n \nIn: " + std::string(__FILE__) + ":" + std::to_string(__LINE__) \
49 + "\nFunction: " + std::string(__func__) \
50 + "\nYou need help? Submit an issue on: https://github.com/codac-team/codac/issues" \
51 + "\n============================================================================="; \
52 throw std::invalid_argument(s); \
53 abort(); \
54 } \
55 \
56
57 #endif
58
59 #endif
60}
61
62#if 0
63
64 #define assert_release(test) \
65 if(!(test)) \
66 { \
67 auto l = std::source_location::current(); \
68 std::ostringstream s; \
69 s << l.file_name() << '(' \
70 << l.line() << ':' \
71 << l.column() << ")\n " \
72 << l.function_name() << "\n"; \
73 throw std::invalid_argument("Wrong assertion in the following function:\n " + s.str()); \
74 abort(); \
75 } \
76 \
77
78#endif