value::to_number

Return the stored number cast to an arithmetic type.

Synopsis

template<
    class T>
T
to_number(
    boost::system::error_code& ec) const noexcept; (1)

template<
    class T>
T
to_number(
    std::error_code& ec) const noexcept; (2)

template<
    class T>
T
to_number() const; (3)

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 the converted number is returned.

  • If T is an integral type and the stored value is a number which cannot be losslessly converted, then the operation fails with an error.

  • If T is a floating point type and the stored value is a number, the conversion is performed without error. The converted number is returned, with a possible loss of precision.

  • Otherwise, if the stored value is not a number; that is, if this->is_number() returns false, then the operation fails with an error.

Constraints

std::is_arithmetic< T >::value && ! std::is_same< T, bool >::value

Complexity

Constant.

Exception Safety

No-throw guarantee.

Return Value

The converted number.

Return Value

The converted number.

Return Value

The converted number.

Parameters

Name Description

ec

Set to the error, if any occurred.

Exceptions

Type Thrown On

boost::system::system_error

Thrown on error.