Recursively defined matcher function
Per Nordlöw
per.nordlow at gmail.com
Sun Jan 3 18:26:44 UTC 2021
How can I define a function type `Matcher` that takes an array of
`Matcher`s and returns an instance of a `struct Match` defined as
struct Match
{
@safe pure nothrow @nogc:
static Match zero()
{
return typeof(return)(0);
}
static Match none()
{
return typeof(return)(_length.max);
}
/// Match length in number of UTF-8 chars or 0 if empty.
@property uint length()
{
return _length;
}
bool opCast(U : bool)() const
{
return _length != _length.max;
}
this(size_t length)
{
assert(length <= _length.max);
this._length = cast(typeof(_length))length;
}
const uint _length; // length == uint.max is
no match
}
I've tried
alias Matcher = Match function(Matcher[] matchers...);
but it errors as
recursive alias declaration
More information about the Digitalmars-d-learn
mailing list