Boost logo

Boost :

Subject: Re: [boost] Formal Review Request: TypeErasure
From: Julien Nitard (julien.nitard_at_[hidden])
Date: 2012-06-18 11:26:48


Hi Steven,

>> - I can create an any of a "smaller" concept from an any of a "bigger"
>> concept, but I have to do it explicitly, why ? Couldn't the conversion
>> be automatic when dealing with references ?
>>
>
> The constructors like
>
> template<class Concept1, class Tag2>
> any(const any<Concept2, Tag2>&);
>
> look implicit to me.

Indeed, it works. My bad, it was a stupid mistake: if you want the
conversion to work, you obviously need to take a ref to const or a
value. Unless I am mistaken, the "default" way for a function to work
with "any" should be take a "reference any" by value. It is cheap to
copy from other "reference any" and cheap to create from a "value
any". Taking a "reference any" by reference is not that convenient
because unless it is const, it can't be bound to "value any".
Could you confirm this ?

>> - Why the _self keyword for references ? Wouldn't
>> any<mpl::vector<...>&> work and be more intuitive ?
>>
> It might be more convenient, but it isn't
> logically consistent.
>
> any<mpl::vector<...> > is really
> any<mpl::vector<...>, _self>,
> because of the default argument.

I am not entirely convinced that it would be a big problem that _self
would refer to remove_reference<concept>::type instead of just
concept, but I get your point.

>> - Even better, I'd rather have the ref any type has a typedef for the
>> value any type.
>> typedef any<mpl::vector<...>> MyAnyT;
>> MyAnyT value(x);
>> MyAnyT::RefT ref(y);
>> (and reciprocally MyAnyRefT::ValueT)
>>
>
> By design, the only public members of
> any are constructors, destructors, and
> assignment operators.  Any other name
> could potentially conflict with a
> user-defined member.

Well yes it could. I think I should have mentioned the problem instead
of trying to solve it by myself, sorry.

My main issue is that when I am going to use an any type, I'll need to
use the reference version as often or more as the value version and
I'd like to be able to save the second typedef and have the
relationship between the two appearing clearly in the code.

Maybe a meta function would do the job better :
AsRef<MyAnyType>::type, but it's starting to become verbose. Any idea
?

>> - _self and the placeholders have their underscore at the beginning
>> while typeid_ has its own at the end. I guess this may be uniformized.
> This is following normal boost conventions.
> Only placeholders get a leading underscore.

Duly noted.

Many thanks for your answers and time,

Julien


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