www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Comparison chart of D and C++ templates

reply Walter Bright <newshound digitalmars.com> writes:
http://www.digitalmars.com/d/template-comparison.html

Comments?
Jan 19 2007
next sibling parent reply Kazuhiro Inaba <kiki kmonos.net> writes:
                          D  C++98 C++0x
Partial Specialization | Yes  Yes  NoChange
Actually, 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
parent Walter Bright <newshound digitalmars.com> writes:
Kazuhiro Inaba wrote:
                          D  C++98 C++0x
 Partial Specialization | Yes  Yes  NoChange
Actually, 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: /* ? */) {}
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.
 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
prev sibling next sibling parent reply Lionello Lunesu <lio lunesu.remove.com> writes:
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
parent reply =?ISO-8859-1?Q?Jari-Matti_M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
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
parent reply Lionello Lunesu <lio lunesu.remove.com> writes:
!!?! I just did a reload of the page and now it's OK!
Jan 19 2007
next sibling parent Frits van Bommel <fvbommel REMwOVExCAPSs.nl> writes:
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
prev sibling next sibling parent Leandro Lucarella <llucarella integratech.com.ar> writes:
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
prev sibling parent Walter Bright <newshound digitalmars.com> writes:
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
prev sibling next sibling parent Kyle Furlong <kylefurlong gmail.com> writes:
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
prev sibling next sibling parent reply Don Clugston <dac nospam.com.au> writes:
Walter Bright wrote:
 http://www.digitalmars.com/d/template-comparison.html
 
 Comments?
You left out specialisation of template value parameters <g>.
Jan 19 2007
parent Don Clugston <dac nospam.com.au> writes:
Don Clugston wrote:
 Walter Bright wrote:
 http://www.digitalmars.com/d/template-comparison.html

 Comments?
You left out specialisation of template value parameters <g>.
Oops, I meant default values for template value parameters.
Jan 19 2007
prev sibling next sibling parent reply Leandro Lucarella <llucarella integratech.com.ar> writes:
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
parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Leandro Lucarella" <llucarella integratech.com.ar> wrote in message 
news:eoqhgk$1nuq$2 digitaldaemon.com...
 Walter Bright escribió:
 http://www.digitalmars.com/d/template-comparison.html

 Comments?
What about the general comparison Java are gone?
Walter took those out because the chart was deemed.. inflammatory? Negative in some way.
Jan 19 2007
prev sibling next sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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
parent reply Walter Bright <newshound digitalmars.com> writes:
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
next sibling parent Marcin Kuszczak <aarti interia.pl> writes:
Walter Bright wrote:

 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,
Great!
 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
prev sibling parent reply Chris Nicholson-Sauls <ibisbasenji gmail.com> writes:
Walter Bright wrote:
 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.
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-Sauls
Jan 19 2007
parent Walter Bright <newshound digitalmars.com> writes:
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
prev sibling next sibling parent reply "Yauheni Akhotnikau" <eao197 intervale.ru> writes:
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
parent Walter Bright <newshound digitalmars.com> writes:
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
prev sibling next sibling parent reply Lutger <lutger.blijdestijn gmail.com> writes:
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
parent Don Clugston <dac nospam.com.au> writes:
Lutger wrote:
 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
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"); ... }
 - templated mixins
Jan 19 2007
prev sibling next sibling parent BCS <BCS pathlink.com> writes:
Walter Bright wrote:
 http://www.digitalmars.com/d/template-comparison.html
 
 Comments?
 Member Templates, D: yes
their allowed?
Redeclaration of Template Parameter
is that a good thing? what about mixins?
Jan 19 2007
prev sibling next sibling parent reply Walter Bright <newshound digitalmars.com> writes:
Walter Bright wrote:
 http://www.digitalmars.com/d/template-comparison.html
 
 Comments?
Posted updated version based on comments so far.
Jan 19 2007
next sibling parent reply John Reimer <terminal.node gmail.com> writes:
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
parent Walter Bright <newshound digitalmars.com> writes:
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
prev sibling parent reply Bruno Medeiros <brunodomedeiros+spam com.gmail> writes:
Walter Bright wrote:
 Walter Bright wrote:
 http://www.digitalmars.com/d/template-comparison.html

 Comments?
Posted updated version based on comments so far.
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#D
Jan 20 2007
parent John Reimer <terminal.node gmail.com> writes:
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
prev sibling next sibling parent janderson <askme me.com> writes:
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
prev sibling parent reply janderson <askme me.com> writes:
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
parent reply Walter Bright <newshound digitalmars.com> writes:
janderson wrote:
 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.
What is automatic induction?
Jan 20 2007
parent reply janderson <askme me.com> writes:
Walter Bright wrote:
 janderson wrote:
 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.
What is automatic induction?
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.
Jan 20 2007
next sibling parent janderson <askme me.com> writes:
janderson wrote:
 Walter Bright wrote:
 janderson wrote:
 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.
What is automatic induction?
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.
I think its called "Type induction". -Joel
Jan 20 2007
prev sibling parent reply Kirk McDonald <kirklin.mcdonald gmail.com> writes:
janderson wrote:
 Walter Bright wrote:
 
 janderson wrote:

 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.
What is automatic induction?
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.
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.org
Jan 20 2007
parent janderson <askme me.com> writes:
Kirk McDonald wrote:
 janderson wrote:
 Walter Bright wrote:

 janderson wrote:

 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.
What is automatic induction?
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.
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);
Cool. I didn't realize that D now supports that. So why not put these some examples on the webpage instead of just "Yes"? -Joel
Jan 20 2007