TRIQS/nda
1.3.0
Multi-dimensional array library for C++
Loading...
Searching...
No Matches
macros.hpp
Go to the documentation of this file.
1
// Copyright (c) 2019--present, The Simons Foundation
2
// This file is part of TRIQS/nda and is licensed under the Apache License, Version 2.0.
3
// SPDX-License-Identifier: Apache-2.0
4
// See LICENSE in the root of this distribution for details.
5
10
11
#ifndef _CCQ_MACROS_GUARD_H
12
#define _CCQ_MACROS_GUARD_H
13
14
// CCQ, TRIQS general macros
15
// GUARD IT do not use pragma once
16
// hence one can simply include them in every project
17
18
// ---------------- Stringify ----------------
19
20
#define AS_STRING(...) AS_STRING2(__VA_ARGS__)
21
#define AS_STRING2(...) #__VA_ARGS__
22
23
// ---------------- Print ----------------
24
25
#define PRINT(X) std::cerr << AS_STRING(X) << " = " << X << " at " << __FILE__ << ":" << __LINE__ << '\n'
26
#define NDA_PRINT(X) std::cerr << AS_STRING(X) << " = " << X << " at " << __FILE__ << ":" << __LINE__ << '\n'
27
28
// ---------------- Inline ----------------
29
30
#define FORCEINLINE __inline__ __attribute__((always_inline))
31
32
// ---------------- Debugging ----------------
33
34
#ifdef NDEBUG
35
36
#define EXPECTS(X) \
37
{}
38
#define ASSERT(X) \
39
{}
40
#define ENSURES(X) \
41
{}
42
#define EXPECTS_WITH_MESSAGE(X, ...) \
43
{}
44
#define ASSERT_WITH_MESSAGE(X, ...) \
45
{}
46
#define ENSURES_WITH_MESSAGE(X, ...) \
47
{}
48
49
#else
50
51
#include <exception>
52
#include <iostream>
53
54
#define EXPECTS(X) \
55
if (!(X)) { \
56
std::cerr << "Precondition " << AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
57
std::terminate(); \
58
}
59
#define ASSERT(X) \
60
if (!(X)) { \
61
std::cerr << "Assertion " << AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
62
std::terminate(); \
63
}
64
#define ENSURES(X) \
65
if (!(X)) { \
66
std::cerr << "Postcondition " << AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
67
std::terminate(); \
68
}
69
70
#define EXPECTS_WITH_MESSAGE(X, ...) \
71
if (!(X)) { \
72
std::cerr << "Precondition " << AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
73
std::cerr << "Error message : " << __VA_ARGS__ << std::endl; \
74
std::terminate(); \
75
}
76
#define ASSERT_WITH_MESSAGE(X, ...) \
77
if (!(X)) { \
78
std::cerr << "Assertion " << AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
79
std::cerr << "Error message : " << __VA_ARGS__ << std::endl; \
80
std::terminate(); \
81
}
82
#define ENSURES_WITH_MESSAGE(X, ...) \
83
if (!(X)) { \
84
std::cerr << "Postcondition " << AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
85
std::cerr << "Error message : " << __VA_ARGS__ << std::endl; \
86
std::terminate(); \
87
}
88
89
#endif
// NDEBUG
90
91
#endif
// _CCQ_MACROS_GUARD_H
nda
macros.hpp
Generated by
1.15.0