numerical-collection-cpp
0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
assert.h
Go to the documentation of this file.
1
/*
2
* Copyright 2022 MusicScience37 (Kenta Kabashima)
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
20
#pragma once
21
22
#include <cstdio>
23
#include <cstdlib>
24
#include <string_view>
25
26
#include <fmt/base.h>
27
28
#include "
num_collect/util/source_info_view.h
"
29
30
namespace
num_collect::util::impl
{
31
38
[[noreturn]]
inline
void
handle_assertion_failure
(
39
std::string_view condition_str,
40
source_info_view
source =
source_info_view
()) {
41
fmt::print(stderr,
"Assertion failed at {}:{} ({}): {}\n"
,
42
source.file_path(), source.line(), source.function_name(),
43
condition_str);
44
std::abort();
45
}
46
47
}
// namespace num_collect::util::impl
48
54
#define NUM_COLLECT_ASSERT_IMPL(CONDITION)
/* NOLINT */
\
55
do {
/* NOLINT */
\
56
if (!(CONDITION)) [[unlikely]] { \
57
::num_collect::util::impl::handle_assertion_failure((#CONDITION)); \
58
} \
59
} while (false)
/* NOLINT */
60
66
#define NUM_COLLECT_ASSERT(CONDITION)
/* NOLINT */
\
67
NUM_COLLECT_ASSERT_IMPL(CONDITION)
/* NOLINT */
68
69
#ifdef NUM_COLLECT_DOCUMENTATION
75
#define NUM_COLLECT_DEBUG_ASSERT(CONDITION) NUM_COLLECT_ASSERT(CONDITION)
76
#elif !defined(NDEBUG)
82
#define NUM_COLLECT_DEBUG_ASSERT(CONDITION)
/* NOLINT */
\
83
NUM_COLLECT_ASSERT(CONDITION)
/* NOLINT */
84
#else
90
#define NUM_COLLECT_DEBUG_ASSERT(CONDITION)
/* NOLINT */
[] {}()
91
#endif
num_collect::util::source_info_view
Class to hold information of source codes.
Definition
source_info_view.h:35
num_collect::util::impl
Namespace of internal implementations.
Definition
assert.h:30
num_collect::util::impl::handle_assertion_failure
void handle_assertion_failure(std::string_view condition_str, source_info_view source=source_info_view())
Handle a failure of an assertion.
Definition
assert.h:38
source_info_view.h
Definition of source_info_view class.
include
num_collect
util
assert.h
Generated on Sat Jan 18 2025 03:47:34 for numerical-collection-cpp by
1.12.0