Safer casts
Yigal Chripun
yigal100 at gmail.com
Sun May 11 03:03:27 PDT 2008
Janice Caron wrote:
> On 11/05/2008, Yigal Chripun <yigal100 at gmail.com> wrote:
>> BUT, the main difference
>> is that for C++ this is probably the only reasonable solution as C++
>> doesn't have delegates.
>
> C++ has functors (classes which overload operator ()), and they're a
> bit like delgates. What C++ doesn't have is alias template parameters,
> nor string template parameters.
>
> sort!("a.member > b.member")(array)
>
> simply couldn't be done in C++. This is /not/ a C++ solution. It's a D
> solution, and a fantastically brilliant one.
>
> Perhaps what you mean when you say "C++ solution", is, "it uses templates"?
it mis-uses templates, as I said in my previous post. it's the same C++
mind set. the only difference is that it utilizes more D++ features to
accomplish the same thing.
Personally, I prefer a smalltalk like collections framework over the c++
generic templates solution. it makes so much more sense to me to have a
orderedCollection interface which defines a sort method, than a c++
generic sort template.
It makes more sense to me to write:
array.sort(); or array.sort(aDelegate);
instead of using:
sort(array); or sort(array, aDelegate); or even worse:
sort!(aDelegate)(array);
C++ avoids using real OOP encapsulation since it perceives it as adding
unnecessary overhead. this is plain wrong since the overhead is
orthogonal to the design principles. This is why C++ is adding the
notion of concepts (which facilitate compile time OOP) to the next
standard.
--Yigal
More information about the Digitalmars-d
mailing list