value::try_to_number

Return the stored number as boost::system::result<T>.

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 T is an integral type and the stored value is a number which can be losslessly converted, the conversion is performed without error and result<T> containing the converted number is returned.

  • If T is an integral type and the stored value is a number which cannot be losslessly converted, then result<T> containing the corresponding error_code is returned.

  • If T is 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() returns false, then result<T> containing the corresponding error_code is 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.