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>;
}
lexy::forward
is a callback that forwards an existing object.
The primary template accepts const T&
and T&&
and forwards them as a T
.
The specialization for void
is both a callback and a sink.
As a callback it accepts no arguments or a single argument of type lexy::nullopt
, and does nothing to return void
.
As a sink, it can be invoked multiple times with the same arguments, doing nothing and finally returning 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>;
};