On the richness of C++

Jason House jason.james.house at gmail.com
Tue Apr 15 15:59:55 PDT 2008


Walter Bright wrote:

> Jason House wrote:
>> 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." [...] For one example, I
>>> reduced a whole chapter of Andrei's "Modern C++ Design" to one page
>>> of D, see std.typetuple.
>> 
>> 
>> I'd love to see some kind of page comparing D with the contents of
>> Modern C++ Design.  It'd be a good selling point for D when the
>> hoards of disgruntled C++ programmers start looking at D.  I wonder
>> what could be done within copy right restrictions...
> 
> If you want to write such a page, I'm sure Andrei would be willing to
> discuss it with you.

That'd be a nice exercise in learning to stress D :)  I'm assuming Andrei
won't read and reply to this post, so what would be the next step forward?



>>>> function ( universal callable ), bind and/or lambda ( function
>>>> object creation ),
>>> I believe that closures and delegates make those irrelevant.
>> 
>> 
>> Unfortunately not.
>> 
>> Function collapses *all* the various function types into one easy to
>> use form.  D has both function and delegate, so some 3rd party
>> utility is still needed.
> 
> I'm not sure that's such a big deal.

It's a corner case.  Corner case elimination is a bigger deal to me than
keyword elimination.



>> Closures capture variables by reference.  This means that creating
>> delegates inside a foreach loop (with deferred evaluation) could fail
>> to have the expected behavior.  Bind stores stuff by value, so I
>> still find myself using bind libraries.
> 
> If you expect captured variables to be by value, sure. But I always
> expected them to be by reference!

By reference is nice in many cases, but in others it's frustrating.  How do
you implement the following?

foreach(job; queue)
  runthread(void delegate(){job.execute;});

(Somehow I expect someone to pick apart the example, but I hope the point is
clear)



More information about the Digitalmars-d mailing list