473,657 Members | 2,484 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2361
* 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 "readabilit y" 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
3175
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: r'<code>(?P<c>.*?)</code>.*?<targetSeq name="(?P<tn>.*?)">.*?<target>(?P<t>.*?)</target>.*?<align>(?P<a>.*?)</align>.*?<template>(?P<temp>.*?)</template>.*?<an otherTag>(?P<at>.*?)</anotherTag>.*?<yetAnotherTag>(?P<yat>.*?)</yetAnotherTag>' The file format...
303
17593
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. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
21
4113
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 cmplx, temp;
5
3470
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 Employee that contains public properties and several nested objects such as a Spouse object and a List of Coverage objects.
1
1291
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 that row into Error table (otherwise to the Main table). I tried: <xsl:when test='not(sht:Cell/@ValueType = "DATE")' >
12
1641
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 working with STL output iterators, is there any general advice on whether they should be passed by value or reference? I have templated code which takes ostream_iterators or back_insert_iterators which I inititally chose to pass by reference, but...
2
9781
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 double() of class B is called for the member complex::operator*=(double) as expected, but not for operator*(complex, double). The effect is, that the template matching (or overload resolution)
7
8604
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 as complex <doublealpha(3.0, 1.0)
5
6045
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 use it, but std::sort doesn't seem to find it. I have copied a very simple example below. Everything compiles just fine when the line with std::sort function is commented out, but with that line included a whole slew of errors are given like: ...
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.