digitalmars.D.announce - Comparison chart of D and C++ templates
- Walter Bright (2/2) Jan 19 2007 http://www.digitalmars.com/d/template-comparison.html
- Kazuhiro Inaba (10/12) Jan 19 2007 Actually, partial specialization in D is a kind of yes-and-no.
- Walter Bright (7/18) Jan 19 2007 You're right there is a problem when one wants to specialize on a type
- Lionello Lunesu (4/4) Jan 19 2007 I haven't checked the contents yet, but in Firefox the code blocks are
- =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= (2/5) Jan 19 2007 I'm using Firefox 2.0 (1280x1024) on Linux and it's working just fine.
- Lionello Lunesu (1/1) Jan 19 2007 !!?! I just did a reload of the page and now it's OK!
- Frits van Bommel (7/8) Jan 19 2007 The stylesheet must have changed or something.
- Leandro Lucarella (6/7) Jan 19 2007 I had the same problem, and reloaded too, and was gone too. Weird...
- Walter Bright (3/4) Jan 19 2007 I bet your browser was caching the style sheet. The page requires an
- Kyle Furlong (3/6) Jan 19 2007 Links on the "Yes"'s in the D column to the relevant parts of the spec
-
Don Clugston
(2/5)
Jan 19 2007
You left out specialisation of template value parameters
. - Don Clugston (2/10) Jan 19 2007 Oops, I meant default values for template value parameters.
- Leandro Lucarella (8/11) Jan 19 2007 What about the general comparison
- Jarrett Billingsley (4/11) Jan 19 2007 Walter took those out because the chart was deemed.. inflammatory? Nega...
- Jarrett Billingsley (9/11) Jan 19 2007 In the "Pointer parameters" row, you might also want to add "delegates" ...
- Walter Bright (4/11) Jan 19 2007 Templated constructors, yes, but the overloading thing is unnecessary
- Marcin Kuszczak (17/24) Jan 19 2007 I would say it is bad news - calling special degenerated function to
- Chris Nicholson-Sauls (8/22) Jan 19 2007 Out of curiousity, what is it in particular that makes overloading of fu...
- Walter Bright (3/10) Jan 19 2007 It's taking things with very different representations within the
- Yauheni Akhotnikau (49/51) Jan 19 2007 In the sample:
- Walter Bright (3/9) Jan 19 2007 I agree, we need a typename example.
- Lutger (13/16) Jan 19 2007 Informative chart, links to spec and other articles about templates
- Don Clugston (8/27) Jan 19 2007 All of these together give a large part of the functionality of C++0x
- BCS (4/9) Jan 19 2007 is that a good thing?
- Walter Bright (2/5) Jan 19 2007 Posted updated version based on comments so far.
- John Reimer (9/9) Jan 19 2007 Under "Parameters", C++98:
- Walter Bright (2/12) Jan 19 2007 LOL! That's what I get for hopping back and forth over the fence.
- Bruno Medeiros (21/27) Jan 20 2007 What does it mean, the "Pointer Parameters - Yes, a pointer to object or...
- John Reimer (3/11) Jan 20 2007 Yes, I agree. Huge improvement! Nice work, Walter! :)
- janderson (3/6) Jan 20 2007 This is great! I even learned a bit more about C++'s templates.
- janderson (6/9) Jan 20 2007 What about automatic induction? You probably want to link to a reason
- Walter Bright (2/11) Jan 20 2007 What is automatic induction?
- janderson (10/22) Jan 20 2007 Sorry, I mean like:
- janderson (3/32) Jan 20 2007 I think its called "Type induction".
- Kirk McDonald (11/46) Jan 20 2007 That is implicit function template instantiation, and D *does* have it.
- janderson (4/51) Jan 20 2007 Cool. I didn't realize that D now supports that. So why not put these
http://www.digitalmars.com/d/template-comparison.html Comments?
Jan 19 2007
D C++98 C++0x Partial Specialization | Yes Yes NoChangeActually, partial specialization in D is a kind of yes-and-no. In C++98, we can do this: template<class T, class U> class Foo< map<T,U> > { ... }; // Partially specialized to "associative arrays" while in D, cannot: class Foo(T: /* ? */) {} Combination of staticIf/typeof/IFTI may achieve the same effect, but in my opinion it is not partial specialization anymore. -- k.inaba / $B0pMU0l9 (B (http://www.kmonos.net)
Jan 19 2007
Kazuhiro Inaba wrote:You're right there is a problem when one wants to specialize on a type dependent on more than one parameter. You can do things like: class Foo(T, U, M : map!(T,U)) ... but it isn't quite as clean.D C++98 C++0x Partial Specialization | Yes Yes NoChangeActually, partial specialization in D is a kind of yes-and-no. In C++98, we can do this: template<class T, class U> class Foo< map<T,U> > { ... }; // Partially specialized to "associative arrays" while in D, cannot: class Foo(T: /* ? */) {}Combination of staticIf/typeof/IFTI may achieve the same effect, but in my opinion it is not partial specialization anymore.static if can do a reasonable job covering for it.
Jan 19 2007
I haven't checked the contents yet, but in Firefox the code blocks are way too wide. The width of the page is more than twice my screen width (1280). In IE7 it's ok. L.
Jan 19 2007
Lionello Lunesu kirjoitti:I haven't checked the contents yet, but in Firefox the code blocks are way too wide. The width of the page is more than twice my screen width (1280). In IE7 it's ok.I'm using Firefox 2.0 (1280x1024) on Linux and it's working just fine.
Jan 19 2007
!!?! I just did a reload of the page and now it's OK!
Jan 19 2007
Lionello Lunesu wrote:!!?! I just did a reload of the page and now it's OK!The stylesheet must have changed or something. It was also *way* too wide for me before, but a complete reload fixed it somewhat. It's still slightly too wide, but at least if I scroll to the right I can now get the entire width of the table onto the screen. While I look at the table I don't need the menu anyway. Still, it could be a little less wide.
Jan 19 2007
Lionello Lunesu escribió:!!?! I just did a reload of the page and now it's OK!I had the same problem, and reloaded too, and was gone too. Weird... -- Leandro Lucarella Integratech S.A. 4571-5252
Jan 19 2007
Lionello Lunesu wrote:!!?! I just did a reload of the page and now it's OK!I bet your browser was caching the style sheet. The page requires an updated style.css for the code blocks.
Jan 19 2007
Walter Bright wrote:http://www.digitalmars.com/d/template-comparison.html Comments?Links on the "Yes"'s in the D column to the relevant parts of the spec would be nice and also consistent with the old feature comparison table.
Jan 19 2007
Walter Bright wrote:http://www.digitalmars.com/d/template-comparison.html Comments?You left out specialisation of template value parameters <g>.
Jan 19 2007
Don Clugston wrote:Walter Bright wrote:Oops, I meant default values for template value parameters.http://www.digitalmars.com/d/template-comparison.html Comments?You left out specialisation of template value parameters <g>.
Jan 19 2007
Walter Bright escribió:http://www.digitalmars.com/d/template-comparison.html Comments?What about the general comparison and Java are gone? -- Leandro Lucarella Integratech S.A. 4571-5252
Jan 19 2007
"Leandro Lucarella" <llucarella integratech.com.ar> wrote in message news:eoqhgk$1nuq$2 digitaldaemon.com...Walter Bright escribió:Walter took those out because the chart was deemed.. inflammatory? Negative in some way.http://www.digitalmars.com/d/template-comparison.html Comments?What about the general comparison Java are gone?
Jan 19 2007
"Walter Bright" <newshound digitalmars.com> wrote in message news:eoq501$1380$1 digitaldaemon.com...http://www.digitalmars.com/d/template-comparison.html Comments?In the "Pointer parameters" row, you might also want to add "delegates" to the D column, and make some mention of that ability in the "Pointer to member parameters" row (i.e. "No, D doesn't have pointers to parameters, it has delegates instead"). This table also makes some things clear that would be nice to have in D. The ones that jump out at me are templated constructors and overloading templated functions with other functions.
Jan 19 2007
Jarrett Billingsley wrote:In the "Pointer parameters" row, you might also want to add "delegates" to the D column, and make some mention of that ability in the "Pointer to member parameters" row (i.e. "No, D doesn't have pointers to parameters, it has delegates instead").Good call.This table also makes some things clear that would be nice to have in D. The ones that jump out at me are templated constructors and overloading templated functions with other functions.Templated constructors, yes, but the overloading thing is unnecessary and makes things more complicated than needed.
Jan 19 2007
Walter Bright wrote:Great!This table also makes some things clear that would be nice to have in D. The ones that jump out at me are templated constructors and overloading templated functions with other functions.Templated constructors, yes,but the overloading thing is unnecessary and makes things more complicated than needed.I would say it is bad news - calling special degenerated function to overload templated function is really unintuitive and probably every newcomer will fight with this. See my problems with that: http://www.digitalmars.com/d/archives/digitalmars/D/learn/Is_it_a_compiler_bug_5478.html and http://www.digitalmars.com/d/archives/digitalmars/D/bugs/Issue_798_New_Template_function_overloading_problems_9873.html Additionally solutions with dummy template parameters are just ugly... -- Regards Marcin Kuszczak (Aarti_pl) ------------------------------------- Ask me why I believe in Jesus - http://zapytaj.dlajezusa.pl (en/pl) Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/ -------------------------------------
Jan 19 2007
Walter Bright wrote:Jarrett Billingsley wrote:Out of curiousity, what is it in particular that makes overloading of function templates difficult/complicated? I have had occasions myself where it would've been highly welcome. (Especially in the context of mixins, and especially as chains of more than three or four static-if blocks can get mighty unwieldy. I have a project with a /recurring/ chain of about seven static-if's. I'd be much happier with seven implementor's/mixin's that are easier to maintain, and to add/remove.) -- Chris Nicholson-SaulsIn the "Pointer parameters" row, you might also want to add "delegates" to the D column, and make some mention of that ability in the "Pointer to member parameters" row (i.e. "No, D doesn't have pointers to parameters, it has delegates instead").Good call.This table also makes some things clear that would be nice to have in D. The ones that jump out at me are templated constructors and overloading templated functions with other functions.Templated constructors, yes, but the overloading thing is unnecessary and makes things more complicated than needed.
Jan 19 2007
Chris Nicholson-Sauls wrote:Out of curiousity, what is it in particular that makes overloading of function templates difficult/complicated? I have had occasions myself where it would've been highly welcome. (Especially in the context of mixins, and especially as chains of more than three or four static-if blocks can get mighty unwieldy. I have a project with a /recurring/ chain of about seven static-if's. I'd be much happier with seven implementor's/mixin's that are easier to maintain, and to add/remove.)It's taking things with very different representations within the compiler and trying to make them the same.
Jan 19 2007
On Fri, 19 Jan 2007 13:02:47 +0300, Walter Bright <newshound digitalmars.com> wrote:http://www.digitalmars.com/d/template-comparison.html Comments?In the sample: template<class T> class Foo { typedef int A; }; template<class T> class Bar : Foo<T> { A x; // error }; it's more correctly to use protected or public keyword in Foo, I think: template<class T> class Foo { protected: typedef int A; }; because in original code A is a private member of Foo and cannot be accessed from derived classes. And a question. It's necessary to use 'typename T<U>::' in C++ to access to typedef in some template class. Even when classes are not related as base/derived: template< class T > struct Iterator { typedef T value_type; typedef T * pointer_type; }; template< class I > struct IteratorAdapter { typename Iterator< I >::pointer_type ptr; }; int main() { IteratorAdapter< int > a; } I think the same situation is in your sample, because Foo<T> is a template class and it is necessary to use 'typename Foo<T>::' as a prefix for A in Base. So, do you think your sample 'Dependent Base Class Lookup' is correct in this context? May be better to speak about access to typedefs/alias in D's templates without 'typename' keyword? -- Regards, Yauheni Akhotnikau
Jan 19 2007
Yauheni Akhotnikau wrote:it's more correctly to use protected or public keyword in Foo, I think:Right.I think the same situation is in your sample, because Foo<T> is a template class and it is necessary to use 'typename Foo<T>::' as a prefix for A in Base. So, do you think your sample 'Dependent Base Class Lookup' is correct in this context? May be better to speak about access to typedefs/alias in D's templates without 'typename' keyword?I agree, we need a typename example.
Jan 19 2007
Walter Bright wrote:http://www.digitalmars.com/d/template-comparison.html Comments?Informative chart, links to spec and other articles about templates might be useful. Not sure if these belong to the chart, but I find the following features quite valuable with or in conjunction with templates: - Static assert, a no-brainer. - Compile time messages, with static assert for example. I guess this by virtue of the .mangleof property with compile time string parsing? (I'm thinking of Don Clugston's meta.nameof library). Anyway the ability to easily give meaningful and readable error messages without resorting to compiler output parsing like STLlift can be a big time-saver. - 'is' expressions - templated mixins
Jan 19 2007
Lutger wrote:Walter Bright wrote:All of these together give a large part of the functionality of C++0x concepts. void remove_if(T)(T start, T end) { static assert(isForwardIterator!(T), prettytypeof!(T) ~ " is not a forward iterator"); ... }http://www.digitalmars.com/d/template-comparison.html Comments?Informative chart, links to spec and other articles about templates might be useful. Not sure if these belong to the chart, but I find the following features quite valuable with or in conjunction with templates: - Static assert, a no-brainer. - Compile time messages, with static assert for example. I guess this by virtue of the .mangleof property with compile time string parsing? (I'm thinking of Don Clugston's meta.nameof library). Anyway the ability to easily give meaningful and readable error messages without resorting to compiler output parsing like STLlift can be a big time-saver. - 'is' expressions- templated mixins
Jan 19 2007
Walter Bright wrote:http://www.digitalmars.com/d/template-comparison.html Comments?Member Templates, D: yestheir allowed?Redeclaration of Template Parameteris that a good thing? what about mixins?
Jan 19 2007
Walter Bright wrote:http://www.digitalmars.com/d/template-comparison.html Comments?Posted updated version based on comments so far.
Jan 19 2007
Under "Parameters", C++98: template<class T> class Foo { T x; }; Foo!<int> f; Does C++ use the '!' point? I thought that was D. :) -JJR
Jan 19 2007
John Reimer wrote:Under "Parameters", C++98: template<class T> class Foo { T x; }; Foo!<int> f; Does C++ use the '!' point? I thought that was D. :)LOL! That's what I get for hopping back and forth over the fence.
Jan 19 2007
Walter Bright wrote:Walter Bright wrote:What does it mean, the "Pointer Parameters - Yes, a pointer to object or function" or "it has delegates, which can be used as parameters"? Isn't that saying that pointers and delegates can be used as (value) template parameters in D? But that is not the case. In "Member templates parseable without hints", Foo.bar in the D code is a non-definition function declaration, right? Perhaps (just a minor nitpick) we could use an actual definition: Foo bar!(int I){ ... }; since non-definition declaration are not normal D idioms, unlike in C++. BTW, this comparison is very good, unlike the previous one about general language features. It shows how easy it is to use each feature (if available at all), which is what the programmer wants to know, which is what a comparison should show, which in turn most of the time cannot be fully expressed simply with just "Yes|No" remarks. That was a major point of "failure" of the previous comparison table, IMO, it was too fixed in a "has or has not explicit feature X" instead of "how easy it is to do Z". -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#Dhttp://www.digitalmars.com/d/template-comparison.html Comments?Posted updated version based on comments so far.
Jan 20 2007
On Sat, 20 Jan 2007 12:02:34 +0000, Bruno Medeiros wrote:BTW, this comparison is very good, unlike the previous one about general language features. It shows how easy it is to use each feature (if available at all), which is what the programmer wants to know, which is what a comparison should show, which in turn most of the time cannot be fully expressed simply with just "Yes|No" remarks. That was a major point of "failure" of the previous comparison table, IMO, it was too fixed in a "has or has not explicit feature X" instead of "how easy it is to do Z".Yes, I agree. Huge improvement! Nice work, Walter! :) -JJR
Jan 20 2007
Walter Bright wrote:http://www.digitalmars.com/d/template-comparison.html Comments?This is great! I even learned a bit more about C++'s templates. -Joel
Jan 20 2007
Walter Bright wrote:http://www.digitalmars.com/d/template-comparison.html Comments?What about automatic induction? You probably want to link to a reason why D doesn't have it (since it will probably be questioned again and again). You could also mention how aliasing can go some way to solving this difference. -Joel
Jan 20 2007
janderson wrote:Walter Bright wrote:What is automatic induction?http://www.digitalmars.com/d/template-comparison.html Comments?What about automatic induction? You probably want to link to a reason why D doesn't have it (since it will probably be questioned again and again). You could also mention how aliasing can go some way to solving this difference.
Jan 20 2007
Walter Bright wrote:janderson wrote:Sorry, I mean like: template <class C> void Get(C& c) {} ... int X = 0; Get(X); float Y = 0; Get(Y); No need to specify the types.Walter Bright wrote:What is automatic induction?http://www.digitalmars.com/d/template-comparison.html Comments?What about automatic induction? You probably want to link to a reason why D doesn't have it (since it will probably be questioned again and again). You could also mention how aliasing can go some way to solving this difference.
Jan 20 2007
janderson wrote:Walter Bright wrote:I think its called "Type induction". -Joeljanderson wrote:Sorry, I mean like: template <class C> void Get(C& c) {} ... int X = 0; Get(X); float Y = 0; Get(Y); No need to specify the types.Walter Bright wrote:What is automatic induction?http://www.digitalmars.com/d/template-comparison.html Comments?What about automatic induction? You probably want to link to a reason why D doesn't have it (since it will probably be questioned again and again). You could also mention how aliasing can go some way to solving this difference.
Jan 20 2007
janderson wrote:Walter Bright wrote:That is implicit function template instantiation, and D *does* have it. void Get(C)(C c) {} int X = 0; Get(X); float Y = 0; Get(Y); -- Kirk McDonald Pyd: Wrapping Python with D http://pyd.dsource.orgjanderson wrote:Sorry, I mean like: template <class C> void Get(C& c) {} ... int X = 0; Get(X); float Y = 0; Get(Y); No need to specify the types.Walter Bright wrote:What is automatic induction?http://www.digitalmars.com/d/template-comparison.html Comments?What about automatic induction? You probably want to link to a reason why D doesn't have it (since it will probably be questioned again and again). You could also mention how aliasing can go some way to solving this difference.
Jan 20 2007
Kirk McDonald wrote:janderson wrote:Cool. I didn't realize that D now supports that. So why not put these some examples on the webpage instead of just "Yes"? -JoelWalter Bright wrote:That is implicit function template instantiation, and D *does* have it. void Get(C)(C c) {} int X = 0; Get(X); float Y = 0; Get(Y);janderson wrote:Sorry, I mean like: template <class C> void Get(C& c) {} ... int X = 0; Get(X); float Y = 0; Get(Y); No need to specify the types.Walter Bright wrote:What is automatic induction?http://www.digitalmars.com/d/template-comparison.html Comments?What about automatic induction? You probably want to link to a reason why D doesn't have it (since it will probably be questioned again and again). You could also mention how aliasing can go some way to solving this difference.
Jan 20 2007