numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
precondition.h File Reference

Definition of NUM_COLLECT_PRECONDITION macro. More...

#include <iterator>
#include <string_view>
#include <utility>
#include <fmt/base.h>
#include <fmt/format.h>
#include "num_collect/base/exception.h"
#include "num_collect/logging/logger.h"
#include "num_collect/logging/logging_macros.h"
#include "num_collect/util/source_info_view.h"
+ Include dependency graph for precondition.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NUM_COLLECT_PRECONDITION(CONDITION, ...)
 Check whether a precondition is satisfied and throw an exception if not.
 

Functions

template<typename... Args>
requires (sizeof...(Args) > 0)
void base::impl::handle_precondition_failure (util::source_info_view source, std::string_view condition, const logging::logger &logger, fmt::format_string< Args... > description_format, Args &&... description_args)
 Handle a failure of a precondition.
 
void base::impl::handle_precondition_failure (util::source_info_view source, std::string_view condition, const logging::logger &logger, std::string_view description)
 Handle a failure of a precondition.
 
template<typename... Args>
requires (sizeof...(Args) > 0)
void base::impl::handle_precondition_failure (util::source_info_view source, std::string_view condition, fmt::format_string< Args... > description_format, Args &&... description_args)
 Handle a failure of a precondition.
 
void base::impl::handle_precondition_failure (util::source_info_view source, std::string_view condition, std::string_view description)
 Handle a failure of a precondition.
 

Detailed Description

Definition of NUM_COLLECT_PRECONDITION macro.

Definition in file precondition.h.

Macro Definition Documentation

◆ NUM_COLLECT_PRECONDITION

#define NUM_COLLECT_PRECONDITION ( CONDITION,
... )
Value:
/* NOLINT */ \
do { \
if (!(CONDITION)) [[unlikely]] { \
::num_collect::base::impl::handle_precondition_failure( \
__VA_ARGS__); \
} \
} while (false)
Class to hold information of source codes.

Check whether a precondition is satisfied and throw an exception if not.

This macro can be usable as one of the following signatures:

Arguments are as follows:

  • CONDITION: Condition.
  • LOGGER: num_collect::logging::logger object to write the log.
  • DESCRIPTION: Description of the precondition.
  • DESCRIPTION_FORMAT: Format string of the description.
  • DESCRIPTION_ARGS...: Arguments for the format string of the description.

Definition at line 137 of file precondition.h.

Function Documentation

◆ handle_precondition_failure() [1/4]

template<typename... Args>
requires (sizeof...(Args) > 0)
void base::impl::handle_precondition_failure ( util::source_info_view source,
std::string_view condition,
const logging::logger & logger,
fmt::format_string< Args... > description_format,
Args &&... description_args )
inline

Handle a failure of a precondition.

Template Parameters
ArgsTypes of arguments of the format string of the description.
Parameters
[in]sourceInformation of the source code.
[in]conditionString expression of the condition.
[in]loggerLogger.
[in]description_formatFormat string of the description.
[in]description_argsArguments for the format string of the description.

Definition at line 81 of file precondition.h.

◆ handle_precondition_failure() [2/4]

void base::impl::handle_precondition_failure ( util::source_info_view source,
std::string_view condition,
const logging::logger & logger,
std::string_view description )
inline

Handle a failure of a precondition.

Parameters
[in]sourceInformation of the source code.
[in]conditionString expression of the condition.
[in]loggerLogger.
[in]descriptionDescription of the precondition.

Definition at line 44 of file precondition.h.

◆ handle_precondition_failure() [3/4]

template<typename... Args>
requires (sizeof...(Args) > 0)
void base::impl::handle_precondition_failure ( util::source_info_view source,
std::string_view condition,
fmt::format_string< Args... > description_format,
Args &&... description_args )
inline

Handle a failure of a precondition.

Template Parameters
ArgsTypes of arguments of the format string of the description.
Parameters
[in]sourceInformation of the source code.
[in]conditionString expression of the condition.
[in]description_formatFormat string of the description.
[in]description_argsArguments for the format string of the description.

Definition at line 105 of file precondition.h.

◆ handle_precondition_failure() [4/4]

void base::impl::handle_precondition_failure ( util::source_info_view source,
std::string_view condition,
std::string_view description )
inline

Handle a failure of a precondition.

Parameters
[in]sourceInformation of the source code.
[in]conditionString expression of the condition.
[in]descriptionDescription of the precondition.

Definition at line 61 of file precondition.h.