Range interface for std.serialization

Jacob Carlborg doob at me.com
Tue Sep 24 10:02:27 PDT 2013


On 2013-08-28 13:20, Dmitry Olshansky wrote:

Bumping this thread.

> 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
> }

I'm having quite hard time to figure out how this should work. Or I'm 
misunderstanding what you're saying.

If I understand you correctly I should do something like:

class Serializer
{
     void put (T) (T item)
     {
         static if (is(T == int))
             serializeInt(item);

	...
     }

     abstract void serializeInt (int item);
}

But if I'm doing it that way I will still have the problem with a lot of 
methods that need to be implemented in the archiver.

Hmm, I guess it would be possible to minimize the number of methods used 
for built in types. There's still a problem with user defined types though.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list