我有一个模板sparse_vector<T>
类,我也在使用Boost UBLAS。我如何在sparse_vector<double>
和boost::numeric::ublas::compressed_vector<double>
之间提供隐式转换?
我还想在std::vector<double>
和boost::numeric::ublas::vector<double>
之间提供类似的转换。
(我使用的是gcc 4.4,启用了C ++ 0x。)
答案 0 :(得分:1)
我假设这些类型有一个迭代器构造函数。如果这个假设是准确的,那就像写这样的东西一样简单:
template < typename OutputVector, typename InputVector >
OutputVector vector_cast(InputVector const& input)
{
return OutputVector(input.begin(), input.end());
}
使用方式:compressed_vector<double> vect = vector_cast<compressed_vector<double> >(my_sparse_vector);