Looking for an equivalent to C++ std::getline in D
Stanislav Blinov via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat May 6 02:24:38 PDT 2017
On Saturday, 6 May 2017 at 08:34:11 UTC, k-five wrote:
> Also what is the parameter "a.empty" for template filter
Jonathan covered the type part. As for that last bit, the filter
template takes a predicate as parameter. This predicate is called
for each input element, and if returns false, the element is
ignored. The predicate can be a function, or, for example, a
lambda:
auto input = args[1].splitter('/').filter!((string s) { return
!s.empty; })();
or a template lambda:
auto input = arga[1].splitter('/').filter!((s) => !s.empty)();
By convention, predicates in Phobos can also be compile-time
strings. In that case, std.functional.unaryFun is used to turn
that string into a function. By default, unaryFun names the
argument 'a', so the "!a.empty" will be expanded by unaryFun into
(a) => !a.empty.
More information about the Digitalmars-d-learn
mailing list