Search code examples
c++boostboost-ublas

boost, matrix_proxy, const matrix


Giving this:

void foo(const matrix<double>& lol)
{
    matrix_row<matrix<double> > lolwut(lol, 5);
}

error:

no matching function for call to ‘boost::numeric::ublas::matrix_row<boost::numeric::ublas::matrix<double> >::matrix_row(const boost::numeric::ublas::matrix<double>&, size_t&)’

How to unconst the reference given in the function's parameter or which workaround to use? I'm not sure if simple assignment

matrix<double> tmp = lol;

will not have any overhead.


Solution

  • Here is how you do this using BOOST_AUTO:

    void foo(const matrix<double>& lol)
    {
        matrix_row< const matrix<double> > lolwut(lol, 5);
    }
    

    The spaces are needed if you are compiling to C++ < 11 otherwise some buggy compilers will interpret it as a right bit-shift (>>) operator