5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_CONTRACTS_CONTRACT_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_CONTRACTS_CONTRACT_HPP_
15#include "arene/base/detail/raw_c_string.hpp"
16#include "arene/base/stdlib_choice/cstdint.hpp"
37namespace contract_detail {
50struct contract_violation_info {
52 detail::raw_c_string file;
54 detail::raw_c_string line;
56 detail::raw_c_string message;
65template <
typename Factory>
69 static constexpr contract_violation_info value{Factory::arene_contract_make_info()};
74template <
typename Factory>
75constexpr contract_violation_info info_holder<Factory>::value;
81ARENE_NORETURN void contract_violation(contract_violation_info
const& info)
noexcept;
88ARENE_NORETURN constexpr void contract_violation_wrapper(contract_violation_info
const& info)
noexcept {
94 if (info.file != info.line) {
95 contract_violation(info);
97 if (info.file == info.line) {
98 contract_violation(info);
113#define ARENE_INTERNAL_CONTRACT_VIOLATION(violation_type, message) \
115 class arene_contract_info_wrapper { \
118 static constexpr auto arene_contract_make_info() noexcept \
119 -> ::arene::base::contract_detail::contract_violation_info { \
121 static_cast<::arene::base::detail::raw_c_string>(__FILE__), \
122 static_cast<::arene::base::detail::raw_c_string>(ARENE_STRINGIZE(__LINE__)), \
123 static_cast<::arene::base::detail::raw_c_string>(message), \
124 ::arene::base::contract_detail::contract_type::violation_type \
128 ::arene::base::contract_detail::contract_violation_wrapper( \
129 ::arene::base::contract_detail::info_holder<arene_contract_info_wrapper>::value \
136#define ARENE_INTERNAL_CONTRACT_CHECK(violation_type, message, condition) \
138 if (ARENE_EXPECT((condition))) { \
140 ARENE_INTERNAL_CONTRACT_VIOLATION(violation_type, (message)); \
149#ifdef ARENE_DOC_GENERATION_RUNNING
150#define ARENE_PRECONDITION(condition)
152#define ARENE_PRECONDITION(...) ARENE_INTERNAL_CONTRACT_CHECK(precondition, #__VA_ARGS__, (__VA_ARGS__))
159#ifdef ARENE_DOC_GENERATION_RUNNING
161#define ARENE_INVARIANT(condition)
163#define ARENE_INVARIANT(...) ARENE_INTERNAL_CONTRACT_CHECK(invariant, #__VA_ARGS__, (__VA_ARGS__))
168#ifdef ARENE_DOC_GENERATION_RUNNING
170#define ARENE_INVARIANT_UNREACHABLE(message)
172#define ARENE_INVARIANT_UNREACHABLE(message) \
174 ARENE_INTERNAL_CONTRACT_VIOLATION(unreachable, (message)); \
Definition accumulate.hpp:37
Definition accumulate.hpp:36
::uint8_t uint8_t
An 8-bit unsigned integer type.
Definition cstdint.hpp:30
#define ARENE_NORETURN
An alias for [[noreturn]] , or a no-op if the attribute is not supported.
Definition noreturn.hpp:24