Boost logo

Boost :

Subject: Re: [boost] [outcome] High level summary of review feedback accepted so far
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2017-06-03 16:22:28


Le 03/06/2017 à 11:25, Peter Dimov via Boost a écrit :
> Vicente J. Botet Escriba wrote:
>
>> I see that the implementation you have done don't allows to return it
>> by reference, and I was wondering if the variant2::subset function
>> (which could for usability purposes be a non-member function)
>> couldn't return by reference.
> ...
>> Note that a variant with less alternatives than another one has the
>> "same shared representation".
>
> It doesn't. The underlying recursive unions are completely different
> types, and the indices don't match. But even if it were, why would I
> want to return by reference? I don't. Returning by reference is bad
> practice, it breaks encapsulation, creates lifetime problems, and so
> on. It's only done when one must. I don't agree with your mindset in
> which returning by reference is somehow desirable.
>
>

We don't agree with returning by reference to be good or bad. No problem.

You are right that the indexes will not match in general so the subset
operation cannot return the same instance. We will some kind of view
that rearranges the indexes :(
For get my comment my comment about returning by reference.

What about the non-member function, so that we don't have code as
x.template subset<E2...>() and we have subset<E2...>(x) instead?

Vicente


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