Boost logo

Boost :

From: Viktor Sehr (viktor.sehr_at_[hidden])
Date: 2021-09-21 19:40:50


Hi Antony,

*- No. For what were you planning to rely on that? (allocating the object
at the first bytes of the any)*
Assuming the object is allocated inside the boost::any, there might be
optimization opportunities for the compiler as
const T& value = *reinterpret_cast<T*>(&any) would be a valid way to access
the contained value.
(Note that I said might, I'm not sure of this).

I'll take a look of what I thought was missing in the documentation when I
have time (quite busy with a release for the moment)

Best
/Viktor

On Mon, Sep 13, 2021 at 12:11 PM Antony Polukhin <antoshkka_at_[hidden]>
wrote:

>
>
> On Fri, Aug 20, 2021, 14:24 Viktor Sehr via Boost <boost_at_[hidden]>
> wrote:
>
>> I just discovered basic_any which is a very nice addition for me. However
>> it's a bit under-documented for the moment.
>>
>
> Thanks! Glad to hear that.
>
> It's quite hard to write a good docs, I'd appreciate help. Feel free to
> provide PRs to adjust the docs
> https://github.com/boostorg/any/blob/b4d7770db49979bfc22bdeb4c8e7ca1a39ad1e32/doc/any.xml#L592
>
>>
>> For example:
>> - I assume it's stack-allocated, does it allocate on the heap if assigned
>> an object larger than the stack (like small_vector) or is this not allowed
>> (like static_vector)?
>>
>
> Yes, it allocates on the heap if the object does not fit. It's documented
> here, somewhere between the lines
> https://www.boost.org/doc/libs/1_77_0/doc/html/boost/anys/basic_any.html
>
>
> - An idea would also be to add a flag which breaks compilation if an object
>> larger than the OptimizeForSize argument is assigned?
>>
>
> Good idea. Please fill a feature request
> https://github.com/boostorg/any/issues
>
>
> - (For detail) If allocated on the stack, are the first bytes of the
>> basic_any the same as the contained object?
>>
>
> No. For what were you planning to rely on that?
>
>
> /Viktor
>>
>> _______________________________________________
>> 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