Header lexy/callback/integer.hpp

Callback lexy::as_integer

lexy/callback/integer.hpp
namespace lexy
{
    template <typename T>
    constexpr callback auto as_integer;
}

Creates an integer of type T.

It is a callback with three overloads:

(const auto& value)

returns T(value).

(lexy::plus_sign, const auto& value)

returns T(value).

(lexy::minus_sign, const auto& value)

returns T(-value).

It is best used together with lexy::dsl::integer and lexy::dsl::sign.

Example 1. A number with an optional plus/minus sign
struct production
{
    // Sign followed by a decimal integer.
    static constexpr auto rule  = dsl::sign + dsl::integer<int>(dsl::digits<>);
    static constexpr auto value = lexy::as_integer<int>;
};

See also