|
Boost : |
Subject: Re: [boost] Adding polymorphic_value to boost
From: Tom (tomjordan766_at_[hidden])
Date: 2017-11-19 20:14:52
> Message: 10
> Date: Thu, 16 Nov 2017 02:14:30 -0700
> From: Jonathan Coe <jonathanbcoe_at_[hidden]>
> To: boost_at_[hidden]
> Cc: Matt Calabrese <calabrese_at_[hidden]>
> Subject: [boost] Adding polymorphic_value to boost
> Message-ID:
> <CAAbBDD9Ck+LhQ4iUraBtBkxexVKDt167qxyfTpDQqYM9bcMqLQ_at_[hidden]>
> Content-Type: text/plain; charset="UTF-8"
>
> I'd like to propose adding the class-template `polymorphic_value` to boost.
>
> `polymorphic_value` is designed to allow the compiler to correctly generate
> special member functions for classes with polymorphic components (It's
> `any` with an interface).
>
> `polymorphic_value` has been proposed for standardisation in P0201 and has
> advanced through the Library Evolution group in Albuquerque (Nov 5-10).
> https://wg21.link/p0201
>
> A working draft of the proposal and implementation can be found at
> https://github.com/jbcoe/polymorphic_value
>
> I gave a presentation about polymorphic_value at C++::London here:
> https://skillsmatter.com/skillscasts/9539-a-polymorphic-value-type-for-c-plus-plus
>
> Matt Calabrese has kindly offered to be review manager.
>
> Kind regards,
>
> Jon
Hi,
I'd be interested in such a utility. Mathias Gaunard proposed something
similar on the mailing list a long while ago, I implemented a simple
version myself based on that.
I have a small number of questions. Given that this is a value type,
does the current approach over-expose pointer (ownership) in the
interface (in essence it still appears to be a glorified smart pointer)
and understate its more fundamental purpose as a regular value with
dynamic type? There might be other things which can usefully be added
for such a value type, for example permitting direct construction of an
object of specific (derived) type, by passing the type as well as the
arguments for the constructor of that type (or wrapping the arguments in
some kind of in-place factory with explicit type). Something like:
// Simple wrapper to enable a static type to be passed through a
forwarding constructor.
template <typename T>
struct Type {};
// Forwarding constructor - actual type is deduced from type wrapped in
(unnamed) first argument's type
template <typename D, typename... Args>
explicit poly_obj(Type<D>, Args&&... args);
// Also could have an emplace member function
template <typename D, typename... Args>
void emplace(Type<D>, Args&&... args);
In theory you wouldn't need to expose pointers in the interface at all?
In fact, should a type-erasure library be preferred (e.g.,
Boost.TypeErasure or Adobe.Poly) as it provides a more general solution
for manipulating polymorphic value types (though typically harder to use)?
Would you be considering supporting C++98 via using the boost::move library?
Regards,
Tom
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk