value::try_to_number
Return the stored number as boost::system::result.
Synopsis
template<
class T>
boost::system::result< T >
try_to_number() const noexcept;
Description
This function attempts to return the stored value converted to the arithmetic type T which may not be bool:
-
If
Tis an integral type and the stored value is a number which can be losslessly converted, the conversion is performed without error andresult<T>containing the converted number is returned. -
If
Tis an integral type and the stored value is a number which cannot be losslessly converted, thenresult<T>containing the correspondingerror_codeis returned. -
If
Tis a floating point type and the stored value is a number, the conversion is performed without error.result<T>containing the converted number, with a possible loss of precision, is returned. -
Otherwise, if the stored value is not a number; that is, if
this->is_number()returnsfalse, thenresult<T>containing the correspondingerror_codeis returned.
Constraints
std::is_arithmetic< T >::value && ! std::is_same< T, bool >::value
Complexity
Constant.
Exception Safety
No-throw guarantee.
Return Value
boost::system::result<T> with either the converted number or an error_code.