Jump to page: 1 2
Thread overview
Template expression
Jul 18, 2004
Pac
Jul 19, 2004
J C Calvarese
Jul 19, 2004
Pac
Jul 19, 2004
Sean Kelly
Jul 20, 2004
Norbert Nemec
Jul 20, 2004
Sean Kelly <sean
Jul 19, 2004
Stephen Waits
Jul 20, 2004
Norbert Nemec
Jul 20, 2004
Stephen Waits
Jul 22, 2004
Norbert Nemec
Expression templates (was: Template expression)
Jul 20, 2004
Norbert Nemec
July 18, 2004
Hello,


does D support Templares expression. If yes where may I find some documentation on   it ?


Best regards
Pac


July 19, 2004
Pac wrote:
> Hello,
> 
> 
> does D support Templares expression. If yes where may I find some documentation
> on   it ?
> 
> 
> Best regards
> Pac

What do you mean by "Template expression"?

Have you tried these links?
http://www.digitalmars.com/d/template.html
http://www.dsource.org/tutorials/index.php?show_topic=Templates


-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/
July 19, 2004
In article <cdfnd9$1sr$1@digitaldaemon.com>, J C Calvarese says...
>
>Pac wrote:
>> Hello,
>> 
>> 
>> does D support Templares expression. If yes where may I find some documentation on   it ?
>> 
>> 
>> Best regards
>> Pac
>
>What do you mean by "Template expression"?
>
>Have you tried these links?

of course.


Short example of expression templates in C++ : http://www.cuj.com/documents/s=8232/cuj0303langer/


Best regards

Pac
July 19, 2004
Sort of.  D supports templates so such things are possible, but as D requires explicit type specification this sort of thing is incredibly unwieldy.  There has been some talk of optimized expression evaluation which may obviate the need for expression templates, but it's on the "to do" list.


Sean


July 19, 2004
Pac wrote:
> 
> does D support Templares expression. If yes where may I find some documentation
> on   it ?

The thing about it is.. C++ template expressions are a nasty ugly hack.  My question is, can we get equivalent performance with an increase in elegance an simplicity in D?

The clear answer right now and at least through 1.0 is "NO".

--Steve
July 20, 2004
Hi there,

looking at your later comments, I find that you mean "expression templates".

Actually, these are not just one feature, but a collection of features in C++ that work together allowing a certain way of programming.

Most of these features are present in D as well. Templates in D are conceptually different from C++ templates, but they should allow mostly everything that can be done in C++. Considering the complexity of the C++ template mechanism, it will probably need some more investigation to find out whether D templates really capture all aspects, but I'm pretty confident about this.

The only major point lacking for expression template programming, though, is implicit instantiation of function templates. This has been a reason for debate for some time now. It will most certainly not be part of D 1.0, but I have little doubt that one day, Walter will give in to the fact that without implicit instantiation, things like expression templates are just impossible.

So, the short answer to your question: No, not at the moment, but hopefully, yes, in the future.

Ciao,
Nobbi


Pac wrote:

> Hello,
> 
> 
> does D support Templares expression. If yes where may I find some
> documentation
> on   it ?
> 
> 
> Best regards
> Pac

July 20, 2004
Stephen Waits wrote:

> The thing about it is.. C++ template expressions are a nasty ugly hack.

This is not quite right. It is true, that meta-programming in C++ is a dirty business. But so far, I know of no other language (except a few experimental ones that never made it out into the real world) that offers a similar functionality. I agree, that in C++, the syntax and a few details are designed suboptimal, but I doubt that the core idea of expression templates can be captured by a simpler technique.

>   My question is, can we get equivalent performance with an increase in
> elegance an simplicity in D?

I strongly doubt it. D templates are different from C++, but they share a key property: template parameters are untyped. Template instantiation is mostly a textual copy-and-paste operation done by the compiler. A template cannot be compiled on its own. (This is different to languages that offer "parameterized classes" which can be compiled without knowledge of the types used at instantiation.)

We may have a cleaner syntax for templates in D, as well as a number of convenient features, but in principle, expression templates will either look similar or be less powerful than in C++. (And here I would prefer the first option!)

> The clear answer right now and at least through 1.0 is "NO".

In this, I agree.

July 20, 2004
Sean Kelly wrote:

> Sort of.  D supports templates so such things are possible, but as D
> requires
> explicit type specification this sort of thing is incredibly unwieldy.
> There has been some talk of optimized expression evaluation which may
> obviate the need for expression templates, but it's on the "to do" list.

What was that talk about? If you mean the recent discussion about vector expressions: yes, they would eliminate one of the most common uses of expression templates, but they would not be a replacement for expression templates in general.

If there were an idea to really replace expression templates in general, I would be really interested in it - even though I doubt that it will be possible.

July 20, 2004
In article <cdinql$1a3u$1@digitaldaemon.com>, Norbert Nemec says...
>
>Sean Kelly wrote:
>
>> Sort of.  D supports templates so such things are possible, but as D
>> requires
>> explicit type specification this sort of thing is incredibly unwieldy.
>> There has been some talk of optimized expression evaluation which may
>> obviate the need for expression templates, but it's on the "to do" list.
>
>What was that talk about? If you mean the recent discussion about vector expressions: yes, they would eliminate one of the most common uses of expression templates, but they would not be a replacement for expression templates in general.

That's what I meant.  And I agree that it might only be a partial replacement, though that is contingent on what the solution ends up being :)

>If there were an idea to really replace expression templates in general, I would be really interested in it - even though I doubt that it will be possible.

Same here.  But I think this is something that should probably be delayed until the core language features are pretty well established.  I'm personally still hopeful that implicit template type determination may make it in at some point, though I suppose this would be a 2.0 feature as well.


Sean


July 20, 2004
Norbert Nemec wrote:
> Stephen Waits wrote:
> 
>>The thing about it is.. C++ template expressions are a nasty ugly hack.
> 
> This is not quite right. It is true, that meta-programming in C++ is a dirty
> business. But so far, I know of no other language (except a few
> experimental ones that never made it out into the real world) that offers a
> similar functionality. I agree, that in C++, the syntax and a few details
> are designed suboptimal, but I doubt that the core idea of expression
> templates can be captured by a simpler technique.

I think I'm correct in saying that it's a "nasty ugly hack".  However, I agree, the functionality has yet to be reproduced in a language other than C++.

My idea is that, given what we've learned with C++ in the past decade, perhaps now we can achieve the same functionality, without it being a "nasty ugly hack".  Think it's possible?  Or am I overly optimistic?

> We may have a cleaner syntax for templates in D, as well as a number of
> convenient features, but in principle, expression templates will either
> look similar or be less powerful than in C++. (And here I would prefer the
> first option!)

I too will take performance, and functionality, over any syntax.  In my work it's a major priority.

--Steve
« First   ‹ Prev
1 2