Range interface for std.serialization

Dmitry Olshansky dmitry.olsh at gmail.com
Wed Aug 28 04:20:02 PDT 2013


28-Aug-2013 13:58, Dmitry Olshansky пишет:
> 28-Aug-2013 11:13, Jacob Carlborg пишет:
>> On 2013-08-27 22:12, Dmitry Olshansky wrote:
>
> Rather this:
>
> void toData(Serializer)(Serializer serializer)
>      if(isSerializer!Serializer)
> {
>      ...
> }
>
> There is no need to even know how archiver looks like for the user code
> (wasn't it one of the goals of archivers?).
>
>> The user is either forced to use templates here as well, or:
>>
>> class Foo
>> {
>>      void toData (Serializer!(XmlArchive) serializer);
>> }
>
> The main problem would be that it can't overriden as templates are final.
>
> After all of this I think Archivers are just fine as templates user only
> ever interacts with them during creation. Then it's serializers
> templates that pick up the right types.
>
> Serializers themselves on the other hand are present in user code and
> may need one common polymorphic abstract class that provides 'put' and
> forwards it to a set of abstract methods. All polymorphic wrappers would
> inherit from it.

Taking into account that you've settled on keeping Serializers as 
classes just finalize all methods of a concrete serializer that is 
templated on archiver (and make it a final class).

Should be as simple as:

class Serializer {
	void put(T)(T item){ ...}
	//other methods per specific type
}

final class ConcreteSerializer(Archiver) : Serializer {
final:
	...
	//use Archiver here to implement these hooks
}

Then users that use templates in their code would have concrete types, 
for others it quickly "decays" to the base class they use.

The boilerplate of defining a lot of methods now moves to Serializer but 
there should be only one such (template) class anyway.

-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list