Header lexy/callback/constant.hpp
Callback lexy::constants
lexy/callback/constant.hpp
namespace lexy
{
template <typename Args>
consteval callback auto constant(Arg&& arg);
}
Produces a constant value.
It is a callback that accepts zero arguments and produces a copy of the constant.
Example 1. Produce constant values
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>;
};