By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,377 Members | 1,658 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,377 IT Pros & Developers. It's quick & easy.

More complex expression template

P: n/a
Hi,

I read Klaus Kreft & Angelika Langer's C++ Expression Templates: An
Introduction to the Principles of Expression Templates at
http://www.angelikalanger.com/Articl...nTemplates.htm

It provide an express template for only one argument (see Listing 19
and so on), which can be used to do numerical integral.

I'm wondering how to generalize it to handle multiple arguments.

Say, I change the definition of Identity in Listing 19 such that it
have one `int' template argument. Then I have
Identity<1> x;
Identity<2> y;
Identity<3> z;

(x * y) and (y * z) should return two functions each of which accepts 2
arguments. But ((x * y) * (y * z)) should return a function which
accept 3 (not 4) arguments(and the arguments should be in the order of
x, y, z).

If you know anyone have implement this kind of expression template,
would you please share with me. Or if you can give me some hints on how
to define this expression template, it will helpful as well.

Thanks,
Peng
Best wishes,
Peng

Nov 6 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
* Pe*******@gmail.com:

I read Klaus Kreft & Angelika Langer's C++ Expression Templates: An
Introduction to the Principles of Expression Templates at
http://www.angelikalanger.com/Articl...nTemplates.htm

It provide an express template for only one argument (see Listing 19
and so on), which can be used to do numerical integral.

I'm wondering how to generalize it to handle multiple arguments.

Say, I change the definition of Identity in Listing 19 such that it
have one `int' template argument. Then I have
Identity<1> x;
Identity<2> y;
Identity<3> z;

(x * y) and (y * z) should return two functions each of which accepts 2
arguments. But ((x * y) * (y * z)) should return a function which
accept 3 (not 4) arguments(and the arguments should be in the order of
x, y, z).
Personally I'd go for

template< T > T foo( T x, T y, T z ) { return x*y*y*z; }

I think the "readability" of inline expressions, which is their only
reason for existence, is nothing of the sort: a well-chosen function
name conveys much more and more clearly than a cryptic expression.

But see

<url: http://www.boost.org/doc/html/apa.html#lambda.why_weak_arity>.

If you know anyone have implement this kind of expression template,
would you please share with me. Or if you can give me some hints on how
to define this expression template, it will helpful as well.


I remember reading about it. You'll have to do the equivalent of a set
union for the argument types. A bitvector (or that sort of encoding,
limiting the possible argument types) might just be the thing. But the
result would, IMHO, probably just be an expression utility that allows
you to write even more unreadable and cryptic expressions. Now what's
the arity here...

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Nov 6 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.