operator overloading

Pages: 12
That code is basically how expression templates work, it's just that expression templates
are more generalized whereas the above code essentially ONLY handles one specific
expression (M*V+W). Basically what it does is it delays the computation until the end,
and then it performs both operations at once, to avoid the temporary that would result
from M*V.

So here's an idea that stems from that. Since you don't want to keep a temporary,
because of it's size, could you perhaps instead define your own iterator classes? For
example, an iterator that iterates from one index containing 42 to another?

Constructing the iterator would be easy, but the increment operators would be expensive
since they would be linear searches. But it avoids the temporary copy.

Does that sound like it would fit what you want?

Hi jsmith,
Yes, it seems a better (or rather best) way compared to using statics, for instance. But I couldn't get hold of literature of expression templates. I searched in Stroustrup "C++ programming language" as well as Lafore "Object oriented programming in C++". Could you guide me where I can get some info on the subject and also illustrate your idea a bit further with examples?

thank you very much once again!
Which way? The iterator solution does not use expression templates. Are you referring
to the expression template solution or the iterator solution?

For expression templates, check out
http://www.angelikalanger.com/Articles/Cuj/ExpressionTemplates/ExpressionTemplates.htm

or just google "expression templates c++"

(WARNING: Expression templates are not easy.)
I was actually referring to expression templates as a better solution, but iterators as a easy solution. Yes, I just found some other literature on expression templates and it certainly isn't a piece of cake... especially to a non-expert user of templates... I have never used a template as, template <typename T, typename T1, typename T2> for example! Your link seems more resourceful than the one I could get a hold of.
But in the meanwhile, I would like to know the iterator (hack) around this issue with an example if its possible...

thank you.
I'll see if I can put something together for you as an example, but it will take me a while
to make a useful example.
sure, thank you very much once again.
Topic archived. No new replies allowed.
Pages: 12