开发者

Providing *implicit* conversion operator for template specialization

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::numeri开发者_运维技巧c::ublas::vector<double>.

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


I'd assume that there's an iterator constructor for these types. If that assumption is accurate then it would be as simple as writing something like so:


template < typename OutputVector, typename InputVector >
OutputVector vector_cast(InputVector const& input)
{
  return OutputVector(input.begin(), input.end());
}

Use like: compressed_vector<double> vect = vector_cast<compressed_vector<double> >(my_sparse_vector);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜