[any] [basic_any] This seems like a little pearl in Boost 1.77, but it's a bit underdocumented?
I just discovered basic_any which is a very nice addition for me. However it's a bit under-documented for the moment. 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)? - An idea would also be to add a flag which breaks compilation if an object larger than the OptimizeForSize argument is assigned? - (For detail) If allocated on the stack, are the first bytes of the basic_any the same as the contained object? /Viktor
On Fri, Aug 20, 2021, 14:24 Viktor Sehr via Boost
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/b4d7770db49979bfc22bdeb4c8e7ca1a39ad1e3...
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
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
On Fri, Aug 20, 2021, 14:24 Viktor Sehr via Boost
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/b4d7770db49979bfc22bdeb4c8e7ca1a39ad1e3...
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
participants (2)
-
Antony Polukhin
-
Viktor Sehr