473,320 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

More complex expression template

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
1 2340
* 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Tina Li | last post by:
Hello, I've been struggling with a regular expression for parsing XML files, which keeps giving the run time error "maximum recursion limit exceeded". Here is the pattern string: ...
303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
21
by: Blair | last post by:
could someone PLEASE tell me why this doesn't work... ----------------------------------------- #include <complex> using namespace std; typedef complex<long double> cld; void main() { cld...
5
by: Trail Monster | last post by:
Ok, I've been searching the net now for several days and can't find how to do this anywhere. Version: VS 2005 Professional Release, 2.0 Framework Background: I have a complex business object...
1
by: Oleg Konovalov | last post by:
Hi, I am trying to do an enhancement to Cocoon 2.0/XSLT1.0 application: add a date validation of Excel cells (named Start_Date) in SQLTransformer, so if a Type of that cell is not a DATE, insert...
12
by: Mark P | last post by:
A couple template related questions: 1. In the code pasted below, why does the basic version get selected in the call to foo and the const version get selected in the call to bar? 2. When...
2
by: Arvid Requate | last post by:
Hello, I'd like to understand why the following code does not compile. It looks like a strangeness in connection with overload resolution for the <complex> header: The conversion operator...
7
by: Tina | last post by:
Dear all, I'm looking for a routine which calculates the Gamma Function for a complex valued variable. I'm using #include <complex> to work with complex numbers. I define a complex number...
5
by: jeremit0 | last post by:
I'm trying to sort a vector<complex<double and can't figure it out. I recognize the problem is that there isn't a default operator< for complex data types. I have written my own operator and can...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.