jeudi 31 mars 2016

how can I deduce template parameter without using decltype [on hold]

For a given the template function

template <int N, typename T> 
std::array<double, N> array_creator ( const T &b )
{
    std::array<double, N> arr;
    for ( int i = 0; i < N; ++i )
        arr[i] = b ( i ); 
    return arr;
}

I don't want to write down T type. That is, I can now write something like this:

Eigen::ArrayXXd m(4,4);
int sz = 1;
auto b = array_creator<2, decltype(m.block<1, 1> ( 1,sz ))>
       ( m.block<1, 1> ( 1,sz ) );

I don't want to write type T as a template parameter, since it can be quite complex, i.e. Eigen::Block<Eigen::ArrayXXd, 1, 2, false>> . Besides, it seems that decltype works, but then I have to copy the expression from function argument. I'd like to write something like this:

auto b = array_creator<2>( m.block<1, 1> ( 1, sz ) );

Any thoughts how this could be done?

Aucun commentaire:

Enregistrer un commentaire