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
#define ASSERT(X) {}
38
#define ENSURES(X) {}
39
#define EXPECTS_WITH_MESSAGE(X, ...) {}
40
#define ASSERT_WITH_MESSAGE(X, ...) {}
41
#define ENSURES_WITH_MESSAGE(X, ...) {}
42
43
#else
44
45
#include <exception>
46
#include <iostream>
47
48
#define EXPECTS(X) \
49
if (!(X)) { \
50
std::cerr << "Precondition " << AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
51
std::terminate(); \
52
}
53
#define ASSERT(X) \
54
if (!(X)) { \
55
std::cerr << "Assertion " << AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
56
std::terminate(); \
57
}
58
#define ENSURES(X) \
59
if (!(X)) { \
60
std::cerr << "Postcondition " << AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
61
std::terminate(); \
62
}
63
64
#define EXPECTS_WITH_MESSAGE(X, ...) \
65
if (!(X)) { \
66
std::cerr << "Precondition " << AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
67
std::cerr << "Error message : " << __VA_ARGS__ << std::endl; \
68
std::terminate(); \
69
}
70
#define ASSERT_WITH_MESSAGE(X, ...) \
71
if (!(X)) { \
72
std::cerr << "Assertion " << AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
73
std::cerr << "Error message : " << __VA_ARGS__ << std::endl; \
74
std::terminate(); \
75
}
76
#define ENSURES_WITH_MESSAGE(X, ...) \
77
if (!(X)) { \
78
std::cerr << "Postcondition " << AS_STRING(X) << " violated at " << __FILE__ << ":" << __LINE__ << "\n"; \
79
std::cerr << "Error message : " << __VA_ARGS__ << std::endl; \
80
std::terminate(); \
81
}
82
83
#endif
// NDEBUG
84
85
#endif
// _CCQ_MACROS_GUARD_H
nda
macros.hpp
Generated by
1.13.2