Policy that checks the value is ≥ 0 and reports violations.

Synopsis

Declared in <mp‐units/overflow_policies.h>

struct check_non_negative;

Description

Intended for quantities that are inherently non‐negative (e.g., length, mass, duration). Automatically applied to natural_point_origin<QS> when QS is tagged non_negative in the ISQ.

If the quantity's representation type has a constraint_violation_handler specialization, the handler's on_violation() is called on negative values (providing guaranteed enforcement regardless of build mode). Otherwise, falls back to MP_UNITS_PRECONDITION, which may be disabled in release builds.

Member Functions

Name

Description

operator()

Checks that v is non‐negative and reports a violation otherwise.

Data Members

Name

Description

min

Lower domain bound: zero in any unit. Consumed by quantity_point::min() and std::numeric_limits<quantity_point>::lowest(). The operator() uses V::zero() directly (no unit scaling needed); this member exists solely for the numeric_limits interface.

Created with MrDocs