mirror of
https://github.com/dlang/phobos.git
synced 2025-05-12 07:08:48 +03:00

`nullSink` returns the `NullSink` by reference and thus allows using it directly in code which expects an OutputRange by reference. The pattern is providing convenience wrappers for struct construction is very common in Phobos, e.g. `rebindable`, `nullable`, `refCounted`, ...
20 lines
479 B
Text
20 lines
479 B
Text
`nullSink` was added to `std.range`
|
|
|
|
$(REF nullSink, std, range) is a convenience wrapper for $(REF NullSink, std,range)
|
|
and creates an output range that discards the data it receives. It's the range analog
|
|
of `/dev/null`.
|
|
|
|
---
|
|
import std.csv : csvNextToken;
|
|
|
|
string line = "a,b,c";
|
|
|
|
// ignore the first column
|
|
line.csvNextToken(nullSink, ',', '"');
|
|
line.popFront;
|
|
|
|
// look at the second column
|
|
Appender!string app;
|
|
line.csvNextToken(app, ',', '"');
|
|
assert(app.data == "b");
|
|
---
|