Boost logo

Boost :

From: Markus Schöpflin (markus.schoepflin_at_[hidden])
Date: 2002-04-26 03:33:30

I don't agree at all.

> Bjorn.Karlsson_at_[hidden] wrote:
> I think there are reasons:
> 0) Ease of use. With an explicit constructor, you couldn't do this:
> int main() {
> std::vector<boost::any> vec;
> vec.push_back(5);
> vec.push_back(std::string(", this works!"));

I did think implicit conversions are generally considered dangerous.
What is so bad if you have to write

vec.push_back(boost::any(std::string(", this works!")));


> // Note that the following line uses the any_print class defined earlier
> std::cout << "Because of implicit conversion" << vec[1] << '\n';

This works because any_print can be implicitly constructed from any. Even an
explicit constructor for any allows this to work.

> return 0;
> }
> Weak argument? Perhaps.
> 1) Compiler deficiencies. I gave it a quick try on three compilers, and these were the results:
> * Compiler X didn't care about explicit for templated constructors...

So nothing changes for this compiler.

> * Compiler Y worked!

So something improves (IMHO) for this compiler.

> * Compiler Z understood the explicit part, but couldn't even pass a correctly constructed const any& to functions afterwards...

Could you give an example, please?

> Weak argument? Perhaps.
> Bjorn Karlsson


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