|
Boost : |
Subject: Re: [boost] Formal Review Request: TypeErasure
From: Nevin Liber (nevin_at_[hidden])
Date: 2012-06-07 16:32:57
On 7 June 2012 14:33, Simonson, Lucanus J <lucanus.j.simonson_at_[hidden]>wrote:
> >> In a nutshell, concept-based-runtime-polymorphism/type-erasure allows
> >> you to have runtime polymorphism while preserving value semantics.
> >> The value of that win is very commonly underestimated.
> >>
> >So, is there a language feature that could be added to C++17 that would
> make implementing type erasure easier?
>
> Standardize Steven's library as part of the STL?
Take the following base class:
struct S
{
void f();
void g();
void h();
};
In the virtual function world, to enforce that interface, one merely has to
write:
struct AbstractS
{
virtual void f() = 0;
virtual void g() = 0;
virtual void h() = 0;
};
and have others derive from it.
If I wanted a type erased version of the equivalent callable interface,
what do I have to do? If it isn't as simple as writing AbstractS above,
only a small fraction of C++ developers will ever attempt it, let alone do
it on a regular basis.
Steven's library does a great job at covering a lot of cases, but adding
custom concepts is a chore. Like lambdas, Steven is showing what is
possible with a library, but I think we need a language extension to make
it useable by the masses.
-- Nevin ":-)" Liber <mailto:nevin_at_[hidden]> (847) 691-1404
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk