Boost logo

Boost :

From: Jens Theisen (jens.theisen_at_[hidden])
Date: 2005-03-20 10:44:20


implicit_cast was once in cast.hpp, but as the comments says, it has
been removed due to uncertain purpose. I have to purposes of which I am
wondering how to do them otherwise:

1. take the address of the conversion
2. initialise a std::vector< int > with a boost::assign::list_of in a
constructor initialiser

The latter is a bit subtle. list_of uses a templated conversion operator
to containers (but technically everything) and std::vector's ctor are
then all tried with taking converted arguments, which leads into an
ambiguity. Using implicit_cast solves the problem, since then the
constructor call to std::vector and the call to the conversion operator
in list_of are both taken as user defined conversions, and there can
only be one of them.

vector< int > v = list_of(1)(2); // works

vector< int > v(list_of(1)(2)); // ambiguous

ctor() : v(implicit_cast< vector< int > >(list_of(1)(2)))
{ } // ambiguous

ctor() : v(list_of(1)(2)) { } // ambiguous

Any thoughts on this?

Regards, Jens


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