Topic: Generic type erasure


Author: Fabio Fracassi <f.fracassi@gmx.net>
Date: Wed, 1 Jul 2009 23:03:18 CST
Raw View
On 1 Jul., 00:59, Mathias Gaunard <loufo...@gmail.com> wrote:
> On 30 juin, 16:19, David Peklak <dpek...@gmail.com> wrote:
>
> > Hi
> > I stumbled over examples of type-erasure several times lately (e.g.
> > Thomas Becker's iterator type erasure
> > or the polymorphic function wrappers in the C++0x standard draft).
> > The pattern is always the same: A wrapper passes function calls on to
> > polymorphic wrappers that share
> > the same (abstract) base class, and these concrete wrappers pass the
> > call on to an object, who's type
> > is "erased".
> > Even though the pattern is always the same, the code for it has to be
> > handcrafted for each new interface.
> > [...]
> > Since I am pretty sure I am not the first one who has this idea, is
> > there any further reading on this or
> > similar ideas?
>
> See Adobe.Poly and its related papers.
> Mapping a concept to type erasure would be nice, but no one has come
> up with satisfying mechanisms as of now.
>
> Personally, I think having a langauge feature to convert a concept C
> into an abstract base class and into a template class that inherits
> from it and forwards each call to its template argument ought to be
> enough.
>

... and one that automatically instantiates that forwarding template
for each
conncept map. I am however not sure how that would work with N2906
("Simplifying use of concepts",
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2906.pdf).

regards

Fabio








--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Roman Perepelitsa <Roman.Perepelitsa@gmail.com>
Date: Wed, 1 Jul 2009 23:06:29 CST
Raw View
On 30 June, 16:19, David Peklak <dpek...@gmail.com> wrote:
> In other words, that would provide something like an artificial base-
> class for any types that (partly)
> share the same interface, without having to write the code for it
> manually.

It's not the first time someone asks for this feature. Unfortunately,
there has not been any serious proposals addressing it.

The most close library satisfying your requirements is
adobe.poly. And I'm not aware of any real alternatives,
apart from manual implementation of each interface.

Roman Perepelitsa.

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: David Peklak <dpeklak@gmail.com>
Date: Tue, 30 Jun 2009 08:19:29 CST
Raw View
Hi
I stumbled over examples of type-erasure several times lately (e.g.
Thomas Becker's iterator type erasure
or the polymorphic function wrappers in the C++0x standard draft).
The pattern is always the same: A wrapper passes function calls on to
polymorphic wrappers that share
the same (abstract) base class, and these concrete wrappers pass the
call on to an object, who's type
is "erased".
Even though the pattern is always the same, the code for it has to be
handcrafted for each new interface.

I was wondering whether that could be solved more generically, by a
language enhancement, making use
of concepts.
Basically, would it be possible to provide a mechnism that creates a
type-erasure class for a given
concept, i.e. a class that fits that concept and forwards all calls to
the associated functions of that concept
on to objects of any type, that themselves also fit the concept?

In other words, that would provide something like an artificial base-
class for any types that (partly)
share the same interface, without having to write the code for it
manually.

Since I am pretty sure I am not the first one who has this idea, is
there any further reading on this or
similar ideas?

Regards,
David

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]





Author: Mathias Gaunard <loufoque@gmail.com>
Date: Tue, 30 Jun 2009 16:59:59 CST
Raw View
On 30 juin, 16:19, David Peklak <dpek...@gmail.com> wrote:
> Hi
> I stumbled over examples of type-erasure several times lately (e.g.
> Thomas Becker's iterator type erasure
> or the polymorphic function wrappers in the C++0x standard draft).
> The pattern is always the same: A wrapper passes function calls on to
> polymorphic wrappers that share
> the same (abstract) base class, and these concrete wrappers pass the
> call on to an object, who's type
> is "erased".
> Even though the pattern is always the same, the code for it has to be
> handcrafted for each new interface.
> [...]
> Since I am pretty sure I am not the first one who has this idea, is
> there any further reading on this or
> similar ideas?

See Adobe.Poly and its related papers.
Mapping a concept to type erasure would be nice, but no one has come
up with satisfying mechanisms as of now.

Personally, I think having a langauge feature to convert a concept C
into an abstract base class and into a template class that inherits
from it and forwards each call to its template argument ought to be
enough.

--
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html                      ]