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
29
31
38[[noreturn]] inline void handle_assertion_failure(
39 std::string_view condition_str,
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
Class to hold information of source codes.
Namespace of internal implementations.
Definition assert.h:30
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
Definition of source_info_view class.