On the richness of C++
Edward Diener
eddielee_no_spam_here at tropicsoft.com
Tue Apr 15 13:13:28 PDT 2008
Walter Bright wrote:
> Edward Diener wrote:
>> Thanks for the examples above. I do realize that D has some built-in
>> features which enable template manipulation which Boost MPL has to
>> emulate through some very clever C++ template metaprogramming. In
>> particular, as you have shown above, D has the tuple concept, the
>> static if...else, and also something I like quite a bit, which is that
>> there is no necessity for a base template upon which specializations
>> are built but that each template can be defined with its own
>> specializations. That last feature makes D templates really much
>> easier to write.
>
> One aspect of C++ templates is rendered completely irrelevant in D is
> D's ability to do compile time function execution. Any C++
> metaprogramming that computes a value can be replaced in D with an
> ordinary function, that is then executed at compile time.
>
> Other things that help are D's ability to pass strings as template
> arguments, and parse those strings at compile time, and D's ability to
> access local variables (not just globals) from template expansions.
I assume the first means function execution which produces a constant
expression. I believe C++ has that on the plate for C++0x, but of course
you have evidently have it now.
I never realized that a string, by which I believe you mean a string
literal, could not be passed as a template argument which is a value and
not a type. It does seem an arcane area.
The last point I do not follow. Surely a template can access its own
member variables, but you seem to be saying that it should access local
variables also where it is being instantiated. I can't imagine the usage
for that since the template creator can not possibly know where his
template is being used.
Nonetheless, I will look at these features in order to to understand
them better. Templates are fun, and I imagine that D templates will be
more fun than C++ templates because they are richer and easier to use.
More information about the Digitalmars-d
mailing list