views:

74

answers:

1

I have a templated sparse_vector<T> class, and I am also using Boost UBLAS. How would I provide implicit conversions between sparse_vector<double> and boost::numeric::ublas::compressed_vector<double>?

I would also like to provide similar conversions between std::vector<double> and boost::numeric::ublas::vector<double>.

(I am using gcc 4.4 with C++0x enabled.)

+1  A: 
Noah Roberts
Thanks for taking the time to answer. I'm actually asking if an implicit conversion can be written, so that I can use std::vector<...> in a context where boost::...::vector is expected. (I've edited the question to make that clearer.)
Neil G
That can't be done. You can override each such function and then call the original with the above explicit "cast" but that's as close as you'll ever get without actually altering the objects in question.
Noah Roberts
Thanks. I just wanted to make sure it was impossible.
Neil G
Is it possible to have a member function in a templated class that is conditionally added depending on the templated type?
Neil G
Yes. Have a look at boost::enable_if
Noah Roberts