Boost logo

Boost :

Subject: Re: [boost] [any] Divergence between Boost.Any and standard library proposal
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2013-05-03 12:30:11


2013/5/3 Beman Dawes <bdawes_at_[hidden]>:
> A fresh draft of the proposal is up at
> http://beman.github.com/dot16/any-proposal.html
>
> In testing new any_cast examples, Boost.Any is handling one case
> differently from the proposal:
>
> any x;
> ...
> x = "Meow"; // x holds const char*
>
> This works fine with the Adobe implementation, but with the Boost
> implementation g++ 4.7.0 -std=c++11 reports:
>
> In file included from any_cast_test.cpp:5:0:
> c:\boost\trunk/boost/any.hpp: In instantiation of
> 'boost::any::holder<ValueType>::holder(c
> onst ValueType&) [with ValueType = char [5]]':
> c:\boost\trunk/boost/any.hpp:52:49: required from
> 'boost::any::any(const ValueType&) [wi
> th ValueType = char [5]]'
> c:\boost\trunk/boost/any.hpp:124:13: required from 'boost::any&
> boost::any::operator=(Va
> lueType&&) [with ValueType = const char (&)[5]; boost::any = boost::any]'
> any_cast_test.cpp:79:7: required from here
> c:\boost\trunk/boost/any.hpp:169:27: error: array used as initializer
>
> VC++ 2012 gets the same error, albeit with a much longer set of messages.
>
> AFAICS, the Adobe (and the proposed standard) behavior is preferred.
> The type does need to decay.
>
> Comments?

Looks like I broke it in https://svn.boost.org/trac/boost/ticket/6999 .

There are also some other differences:
* boost implementation has perfect forwarding of ValueType
(constructor and operator=)
* ValueType requirement is MoveConstructible or CopyConstructible (it
can be used with move only types)
* ~any() is noexcept
* proposal misses noexcept in for bad_any_cast: virtual const char*
what() const;
* Boosts version does not accept Allocator

A few things that I think would be helpful:
* clear() method
* ??? assign() method with Allocator

--
Best regards,
Antony Polukhin

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