Skip to content

mp_units::quantity_point::try_make

Constructs quantity_point{q, po}, or returns bounds_violation for a value that is_within_bounds rejects. The overload without an origin takes a quantity at the default origin, and the overload taking a point of another type or a point-like value constructs quantity_point{qp}.

Synopsis

Declared in <mp-units/framework/quantity_point.h>

template<typename FwdQ>
  requires requires(const FwdQ& q) { is_within_bounds(q, PO); } &&
           std::constructible_from<quantity_point, FwdQ, decltype(PO)>
[[nodiscard]] constexpr static std::expected<quantity_point, bounds_violation> try_make(
  FwdQ&& q, decltype(PO));

Description

The value is converted and tested once. A rejected value is never stored, and a value that passes is stored without being tested again. This makes it the wide-contract counterpart of the constructor, whose precondition a rejected value violates when the representation has no constraint_violation_handler. The same function can be written over std::optional or another error type from is_within_bounds and the constructor. The constructor then tests the value a second time, and a point from another absolute origin is projected again. Available where <expected> is.

Return Value

Note

The return value should not be discarded.

See Also