Hi Joerg,
Yep. Here it goes: ---------- #include
using namespace boost::numeric::ublas; template class spline : public std::unary_function { public: spline(const vector_expression<E> &e) : e_ (e) {} T operator() (const T& x){ // the spline interpolation algorithm goes here ... return e_ (0); // do something useful ;-) } private: const vector_expression<E> &e_; }; int main() { vector<double> v(3); spline s1(v); // With GCC's extensions the following works :-) spline s2(v); } ----------
Exactly. This is what I was thinking of. But as I understand now it probably is not such a good idea to keep a reference to an expression at all. Wouldn't it be reevaluated every time I "arg().(i,j)" i.e?
Maybe as an ordinary user you simply should copy the vector
expression into
another vector ;-)
I was thinking of this already. But now as I know my options and have
a better idea what is going on behind the scenes I am much more
comfortable with this. :-)
So I most certainly will end up like that:
void foo(vector<double> arg)
{
}
matrix<double> m(3,3);
vector<double> v(3);
foo(m.row(0));
foo(v);
And the converting constructor will create my temporary, which I do
need anyway, as I can understand now.
And when I really need to keep a reference to my data (or need to
pass a really huge vector):
template<class T>
void foo(const vector<T>& arg)
{
}
template<class E>
void foo(vector_expression<E> arg)
{
foo(vector