Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > More complex expression template

Reply
Thread Tools

More complex expression template

 
 
PengYu.UT@gmail.com
Guest
Posts: n/a
 
      11-06-2005
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

 
Reply With Quote
 
 
 
 
Alf P. Steinbach
Guest
Posts: n/a
 
      11-06-2005
* http://www.velocityreviews.com/forums/(E-Mail Removed):
>
> 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?
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Do you think Java is getting more and more complex? howa Java 17 07-01-2007 03:02 AM
Compiler error occurred when try to use a flexible template expression in preprocessor definesCompiler error occurred when try to use a flexible template expression in preprocessor defines snnn C++ 6 03-14-2005 04:09 PM
For expert on complex loops (reposted) - complex looping problem news.amnet.net.au Java 1 04-13-2004 07:10 AM



Advertisments