Boost logo

Boost :

From: Bjorn.Karlsson_at_[hidden]
Date: 2004-02-25 08:53:45

> From: Vladimir Prus [mailto:ghost_at_[hidden]]
> Hi,
> I just had a couple of bugs caused by the fact that
> constructor of boost::any
> is not explicit. For example:
> void do_something(boost::any& v) { ... }
> class variable {
> /////
> boost::any& value() {}
> };
> variable v;
> do_something(v);
> The intention was to call do_somethin on 'v.value()' but
> non-explicit ctor is
> happy to accept 'variable', after which 'do_something' breaks.
> Anybody has an opinion? Is non-explicit ctor really necessary?

(Note that the example above avoids the issue of implicit conversion (it
won't compile), because it takes the parameter by non-const reference. With
the current implementation, this is a good trick to use.)

I agree that the constructor should be made explicit. I seem to recall that
we discussed this on the list about a year ago, and the main objection
against an explicit constructor was that the behavior across different
compilers wasn't consistent (some compilers didn't like explicit template
constructors at all). But now, a year later, perhaps it's time to go ahead
and make the change? It's unfortunate that it's a change that will break
code; perhaps some legacy mode needs to be provided.

Anyway, there have been several requests for this and thus far no strong
opinions against it.


Boost list run by bdawes at, gregod at, cpdaniel at, john at