Skip to content

Class EpiAssert

ClassList > EpiAssert

Argument-assertion utilities for epiworld. More...

  • #include <epiassert-bones.hpp>

Public Static Functions

Type Name
void check (const T value, Predicate pred, const std::string message, const std::string caller="")
Assert that pred returnstrue forvalue .
void check_bounds (const T value, const BoundT lower, const BoundT upper, const std::string varname="value", const std::string caller="")
Assert that value is in[lower, upper] .
void check_non_negative (const T value, const std::string varname="value", const std::string caller="")
Assert that value is non-negative.
void check_probability (const T value, const std::string varname="value", const std::string caller="")
Assert that value is a valid probability in[0, 1] .
void check_size (const T values, size_t expected, const std::string varname="values", const std::string caller="")
Assert that values has exactlyexpected elements.
void check_sum (const T values, double target, const std::string varname="values", const std::string caller="", double tolerance=1e-8)
Assert that the elements of values sum totarget within ±tolerance .

Detailed Description

All methods are static and accept an optional varname (for the variable being checked) and caller (for the function or method that called the check). Both are used only in the error message.

Public Static Functions Documentation

function check

Assert that pred returnstrue forvalue .

template<typename T, typename Predicate>
static inline void EpiAssert::check (
    const T value,
    Predicate pred,
    const std::string message,
    const std::string caller=""
) 

The predicate receives the value by const reference and should return true when the value is valid.

Exception:

  • std::invalid_argument with the caller-provided message when the predicate returns false.

function check_bounds

Assert that value is in[lower, upper] .

template<typename T, typename BoundT>
static inline void EpiAssert::check_bounds (
    const T value,
    const BoundT lower,
    const BoundT upper,
    const std::string varname="value",
    const std::string caller=""
) 

For container types every element is checked individually.

Exception:

  • std::range_error if any value violates the bounds.

function check_non_negative

Assert that value is non-negative.

template<typename T>
static inline void EpiAssert::check_non_negative (
    const T value,
    const std::string varname="value",
    const std::string caller=""
) 

For container types every element is checked individually.

Exception:

  • std::range_error if any value is negative.

function check_probability

Assert that value is a valid probability in[0, 1] .

template<typename T>
static inline void EpiAssert::check_probability (
    const T value,
    const std::string varname="value",
    const std::string caller=""
) 

For container types every element is checked individually.

Exception:

  • std::range_error if any value is outside [0, 1].

function check_size

Assert that values has exactlyexpected elements.

template<typename T>
static inline void EpiAssert::check_size (
    const T values,
    size_t expected,
    const std::string varname="values",
    const std::string caller=""
) 

Exception:

  • std::invalid_argument if the size differs.

function check_sum

Assert that the elements of values sum totarget within ±tolerance .

template<typename T>
static inline void EpiAssert::check_sum (
    const T values,
    double target,
    const std::string varname="values",
    const std::string caller="",
    double tolerance=1e-8
) 

Exception:

  • std::invalid_argument if the sum is outside [target − tolerance, target + tolerance].


The documentation for this class was generated from the following file epiworld-src/include/epiworld/epiassert-bones.hpp