Boost logo

Glas :

Re: [glas] When to evaluate expressions

From: Marcin Zalewski (marcin.zalewski_at_[hidden])
Date: 2007-01-03 13:37:22


Neal,

I think you are right; most of the time it would be best if the compiler
could decide what to do. Unfortunately though, since expression templates
are by their very design a user-level optimization, a compiler cannot
optimize much. C++ will probably never include lazy computations like, for
example, Haskell. The way to go is probably with external tools that
translate generic code to C++ and choose how to handle lazy computations.

-m

On 1/3/07, Neal Becker <ndbecker2_at_[hidden]> wrote:
>
> I've been thinking about this subject, and wondered if any of you have
> some
> ideas on this. (Disclaimer - I'm no expert).
>
> With expression templates, evaluation of expressions is deferred. This is
> a
> bit like lazy evaluation in languages such as Haskell.
>
> Evaluation usually? occurs on assignment to a concrete container:
>
> vector<T> out = in1 * in2;
>
> But can be carried in deferred form:
>
> typeof (in1 * in2) out = in1 * in2;
>
> So the current practice (which is what I'm identifying above) is relying
> on
> the programmer to decide when evaluation occurs.
>
> My question is, is this the right appoach? Perhaps, instead, by default
> the
> compiler should decide?
>
> This is a lot like other forms of optimization. Ultimately, hand-tuned
> assembly can out-perform compiled code - but only when the programmer has
> a
> lot of knowledge and a lot of spare time. Otherwise, the compiler can
> generate better code.
>
> Does anyone agree with me that it is desirable for a compiler to decide on
> the
> point of evaluation of expressions (rather than the programmer)? If so,
> is
> there any reasonable way to implement this in c++?
> _______________________________________________
> glas mailing list
> glas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/glas
>