Something like ADL from C++?
Jonathan M Davis
newsgroup.d at jmdavisprog.com
Thu Dec 5 13:16:06 UTC 2024
On Wednesday, December 4, 2024 7:31:50 PM MST Manu via Digitalmars-d wrote:
> On Wed, 4 Dec 2024 at 08:16, Walter Bright via Digitalmars-d <
>
> digitalmars-d at puremagic.com> wrote:
> > Koenig lookup? I ran away, far away, from that, after implementing it for
> > C++.
> >
> > It's a nightmare.
>
> So what do you suggest?
> UFCS makes this pattern more attractive than ever, but our lookup rules
> inhibit any practical application.
> The problem is essentially that a more-local import or singular declaration
> shadows an entire overload set from a less-local scope, rather than merging
> with it.
The way that I've seen serialization done in D is to use UDAs, and the
(de)serializer uses type introspection to look at the UDAs to see what to
do. It could handle certain types by default (e.g. the built in language
types) and then extrapolate what to do for a type that is made up of known
types but isn't marked up with UDAs - or it could require that any types be
marked up to be (de)serialized. Either way, when dealing with a type that
doesn't have a UDA, the variable declaration using that type could use a UDA
to provide the required functions - or it could provide an intermediate type
(be it one that has a serialize and deseralize function that handles the
variable's type or because it's a type that that variable can be converted
to and from that the (de)serializer knows how to handle). IIRC, the
seralization stuff I saw in Java years ago did something similar (though
obviously with runtime reflection). Though obviously, C++ isn't going to use
that approach unless they've added some form of UDAs in a recent version,
and I missed it.
Obviously, that's a very different approach than what you're talking about,
and it may or may not fit what you're ultimately looking to do, but it's
what I've seen done - e.g. Mir has a serialization solution along those
lines.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list