Boost logo

Boost :

Subject: Re: [boost] Adding polymorphic_value to boost
From: Richard Hodges (hodges.r_at_[hidden])
Date: 2017-11-20 06:26:02


> On 20 Nov 2017, at 00:41, Peter Dimov via Boost <boost_at_[hidden]> wrote:
>
> Peter Bartlett wrote:
>
>> The only nit I had in the paper was that after all the banging on about it being a value type, we are given operator bool, operator* and operator->, making it pointer-like again. Could operator T& and operator T const& work?
>
> Polymorphic means virtual functions, and when you have a polymorphic_value<T> pv, where T has a virtual function `f`, you can call `pv->f()`. With a conversion to T&, you can't call `pv.f()`.
>

I had a careful think about this. It seems to me that what is at fault is not the interface, but the name.

For the reason of the example below, it is helpful that the interface is consistent with unique_ptr, reference_wrapper, and shared_ptr.

However, I think it is fair to say that the suffix _value is misleading as to intent.

Example:

struct FooConcept
{
    void operator()() const;
    virtual ~FooConcept() = default;
};

template<template<class, class...> class OwnershipHandle>
struct basic_foo_handle
{
    using implementation_pointer = OwnershipHandle<FooConcept>;
    
    void operator()() const { (*impl_)(); }

    implementation_pointer impl_;
};

// a unique, non-copyable Foo
using unique_foo = basic_foo_handle<std::unique_ptr>();

// a shared-body Foo
using shared_foo = basic_foo_handle<std::shared_ptr>();

// observer_ptr would be a more consistent concept name (what happened to that?)
using foo_reference = basic_foo_handle<std::reference_wrapper>();

// deep_copy_ptr might have been a more appropriate name?
using copyable_foo = basic_foo_handle<boost::polymorphic_value>();

> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk