Header lexy/callback/forward.hpp

Callback lexy::forward

lexy/callback/forward.hpp
namespace lexy
{
    template <typename T>
    constexpr callback auto forward;

    template <>
    constexpr callback auto forward<void>;
}

Forwards an existing object.

The primary template accepts const T& and T&& and forwards them as a T. The specialization for void accepts no arguments and does nothing to return void.

Example 1. Forward the value of child productions
struct boolean
{
    struct true_
    {
        static constexpr auto rule = LEXY_LIT("true");
        // Produce the value `true`.
        static constexpr auto value = lexy::constant(true);
    };
    struct false_
    {
        static constexpr auto rule = LEXY_LIT("false");
        // Produce the value `false`.
        static constexpr auto value = lexy::constant(false);
    };

    static constexpr auto rule = dsl::p<true_> | dsl::p<false_>;
    // Both rules produce a boolean value, just forward that one.
    static constexpr auto value = lexy::forward<bool>;
};