Expression templates and array indexing

D

Dominic Chandar

Hi,

I have read the section on Expression templates from Vandevoorde
and Josuttis, and I have coded a lighter version of the expression
template example, and it works quite well.
In the assignment operator :

template <typename T2, typename Rep2>
Array & operator = ( Array<T2, Rep2> const & b )
{

for ( int idx = 0; idx < b.size ; ++idx )
expr_rep[idx] = b[idx] ;

}

Note that the same index "idx" is passed on to all the nested
objects.. So if I have an expression like x*y + x, then the
assignment operation would see x*y + x. Agreed..
What if i need different indices for each of the operation, like:

x*y[i+1] + x[i-1];

Lets assume that the for loop doesn't span the full data range, so as
to accommodate the i-1 and i+1 index... Is there a way to expand
b[idx] such that I can pinpoint the operands individually ?

-Dominic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,103
Latest member
VinaykumarnNevatia
Top