S
SG
In case you havn't heard about Alexandrescu's Google TechTalk "Three
Cool Things about D", Here are a couple of links:
(video of the talk)
http://erdani.com/d/three-cool-things-about-d.pdf (slides)
Since he's arguing for D by comparing it to C++, I thought this could
be of interest to the readers here.
I myself don't find all the arguments particularly compelling. For
example, he's arguing that D has a better support for generic
programming. He does that with an example: a generic min function.
auto min(L,R)(L lhs, R rhs) // this is D2, not C++
{
return rhs < lhs ? rhs : lhs;
}
This is supposedly all it takes for a "complete min implementation".
The problem here is IMHO: What is a "complete min implementation"
actually supposed to do? The different C++ implementations he mentions
(including the 175 lines code from N2199) obviously have different
goals. At least two of the goals of N2199 are not met by the D
implementation from above. That is, it won't return references when it
is safe (i.e. when both arguments were reference-compatible lvalues)
and it will return the wrong results due to implicit conversions
involving signed/unsigned types. So, in my opinion, this is a bit of
an apples-oranges comparison. A nice contender for his min
implementation in D would probably look like this:
template<class T, class U>
auto min(T && t, U && u) -> decltype(u<t?u:t)
{
if (u<t) return forward<U>(u);
return forward<T>(t);
}
which does all that the D implementation from above does and more
(return values are possibly move-constructed --> no unnecessary
copying, support for move-only types. It does return an lvalue
reference in case both arguments were reference-compatible lvalues).
It doesn't solve the signed/unsigned problem but his D version is just
as flawed in that respect.
Any other thoughts?
Cheers!
SG
Cool Things about D", Here are a couple of links:
http://erdani.com/d/three-cool-things-about-d.pdf (slides)
Since he's arguing for D by comparing it to C++, I thought this could
be of interest to the readers here.
I myself don't find all the arguments particularly compelling. For
example, he's arguing that D has a better support for generic
programming. He does that with an example: a generic min function.
auto min(L,R)(L lhs, R rhs) // this is D2, not C++
{
return rhs < lhs ? rhs : lhs;
}
This is supposedly all it takes for a "complete min implementation".
The problem here is IMHO: What is a "complete min implementation"
actually supposed to do? The different C++ implementations he mentions
(including the 175 lines code from N2199) obviously have different
goals. At least two of the goals of N2199 are not met by the D
implementation from above. That is, it won't return references when it
is safe (i.e. when both arguments were reference-compatible lvalues)
and it will return the wrong results due to implicit conversions
involving signed/unsigned types. So, in my opinion, this is a bit of
an apples-oranges comparison. A nice contender for his min
implementation in D would probably look like this:
template<class T, class U>
auto min(T && t, U && u) -> decltype(u<t?u:t)
{
if (u<t) return forward<U>(u);
return forward<T>(t);
}
which does all that the D implementation from above does and more
(return values are possibly move-constructed --> no unnecessary
copying, support for move-only types. It does return an lvalue
reference in case both arguments were reference-compatible lvalues).
It doesn't solve the signed/unsigned problem but his D version is just
as flawed in that respect.
Any other thoughts?
Cheers!
SG