On the richness of C++

Edward Diener eddielee_no_spam_here at tropicsoft.com
Tue Apr 15 13:00:02 PDT 2008


Walter Bright wrote:
> Edward Diener wrote:
>> The question is: has anyone tackled in D some of the template 
>> metaprogramming tasks which various Boost programmers have 
>> accomplished with C++ ?
> 
> Yes. See std.algorithms, for one. It is written by Andrei Alexandrescu, 
> the guy who revolutionized template programming in C++ with his book 
> "Modern C++ Design."

I know of Andrei and his book. The Boost MPL superceded what he had 
done, but that does not take away from the value of his original work.

> 
>> I am trying to get a feel for how different, or how much easier ( or 
>> perhaps harder ) it would be to do Boost things like Spirit ( 
>> lex/yacc-like DSEL ),
> 
> I wrote a toy Spirit clone a while back, just as a proof of concept. It 
> is very doable.

Good to hear. Then maybe someone will write a real parser in D as rich 
as Spirit, or mayber someone already has. Despite C++ template's 
intricacy, Spirit is a monstrously wonderful piece of software. My hat 
is off to Joel Guzman and Hartmut Kaiser for it.

> 
>> function ( universal callable ), bind and/or lambda ( function object 
>> creation ),
> 
> I believe that closures and delegates make those irrelevant.

I believe you are wrong unless you have managed to combine all callables 
into a single syntax, and have a flexible binding mechanism built into 
the callable concept.

But we had this discussion before where I pointed out that having both 
delegates and function pointers in D was bifurcating a common concept ( 
callable ), and that you should serious think about combining them, 
either through the languiage or perhaps a library, into one.

In C++, boost::function is that library and bind/lambda essentially 
creates callables with various very flexible argument binding 
mechanisms. Perhaps D 2.0 can do all that but my reading of D 1.0 says no.

> 
>> shared_ptr ( sharable smart pointer, obviously for RAII in D because 
>> of GC ),
> 
> Coming with RAII for structs.

I hope it will eventually be coming some day with RAII via scope, per 
our long thread/discussion.

> 
>> signals ( generalized multicast events ), multi_index ( multiple index 
>> containers ),
> 
> I'm not sure what those require of templates.

Signals are built on top of boost::function, and is essentially a 
multi-cast closure for any type of callable. Other than that it is 
probably no more template based than boost::function. But since 
Boost::function has to deal in types for all possibilities of function 
objects up to nn ( defaulted to 10 I believe ) parameters and a return 
type, boost::signals has to also.

> 
>> regex and/or xpressive ( regular expressions ),
> 
> Don Clugston showed how you can to regex in D.

Yes, I realized that D has regular expressions in one of it libraries, 
which is great. Congratulations !

> 
>> tokenizer ( generalized tokening of strings ), date_time ( date/time 
>> and time intervals ) and many others ( the above are just my favorites 
>> but I have hardly explored/used all of them ) which C++ programmers 
>> find very useful. All of these libraries depend on template 
>> metaprogramming in C++. Can their equivalents just as easily be 
>> implemented and have any of them been done already ?
> 
> Since I've implemented both C++ and D templates, I know what 
> capabilities they have. D's exceeds C++'s.

Good to hear. Now that I understand D templates better I can play with 
them a little more.

I still have a gut feeling that D may need an equivalent template 
library like the Boost MPL for compile time type manipulation in order 
to achive the sort of complicated template metaprogramming usage that so 
many Boost libraries have in order to accomplish their ends, but I can 
not prove it and could be entirely wrong about it. Perhaps the Boost MPL 
is a way to do things with C++ templates which D already natively 
provides with D templates.

> 
>> I have not looked at the D libraries, phobos and tango I believe they 
>> are called, so maybe I am way off base comparing the Boost libraries 
>> to what may already be in D. But I am trying to get an idea if D is 
>> capable of doing these Boost things just as easily or easier.
> 
> For one example, I reduced a whole chapter of Andrei's "Modern C++ 
> Design" to one page of D, see std.typetuple.

Is that why Andrei became interested in D <g> ?



More information about the Digitalmars-d mailing list