Range interface for std.serialization
Dmitry Olshansky
dmitry.olsh at gmail.com
Mon Aug 26 03:07:15 PDT 2013
26-Aug-2013 00:50, Dmitry Olshansky пишет:
> 25-Aug-2013 23:15, Dicebot пишет:
>> On Sunday, 25 August 2013 at 08:36:40 UTC, Dmitry Olshansky wrote:
>>> Same thoughts here.
>>> Serializer is an output range for pretty much anything (that is
>>> serializable). Literally isOutputRange!T would be true for a whole lot
>>> of things, making it possible to dumping any ranges of Ts via copy.
>>> Just make its put method work on a variety of types and you have it.
>>
>> Can't it be both OutputRange itself and provide InputRange via
>> `serialize` call (for filters & similar pipe processing)?
>
[...]
> What's lacking is a way to connect a sink to another sink.
>
> My view of it is:
> auto app = appender!(ubyte[])();
> //thus compression is an output range wrapper
> auto compressor = compress!LZMA(app);
>
> In other words an output range could be a filter, or rather forwarder of
> the transformed result to some other output range. And we need this not
> only for serialization (though formattedWrite can arguably be seen as a
> serialization) but anytime we have to turn heterogeneous input into
> homogeneous output and post-process THAT output.
On the subject of it we can do some cool wonders by providing such
adapters, example - calculate SHA1 hash of a message on the fly:
https://gist.github.com/blackwhale/6339932
As a proof of concept to show the power that output range adapters
possess :)
Sadly it hits a bug in LockingTextWriter, namely destructor fails on
T.init (a usual oversight). Patch:
--- a/std/stdio.d
+++ b/std/stdio.d
@@ -1517,9 +1517,12 @@ $(D Range) that locks the file and allows fast
writing to it.
~this()
{
- FUNLOCK(fps);
- fps = null;
- handle = null;
+ if(fps)
+ {
+ FUNLOCK(fps);
+ fps = null;
+ handle = null;
+ }
}
this(this)
--
Dmitry Olshansky
More information about the Digitalmars-d
mailing list