D popularity
H. S. Teoh
hsteoh at quickfur.ath.cx
Mon Jan 21 12:57:17 PST 2013
On Mon, Jan 21, 2013 at 09:53:35PM +0100, F i L wrote:
> On Monday, 21 January 2013 at 20:48:22 UTC, Walter Bright wrote:
> >On 1/21/2013 12:31 PM, Rob T wrote:
> >>I have to wonder if many of the features can be generalized down
> >>into less
> >>features without sacrificing anything.
> >
> >Yeah, well, that's the major thing about any language design!
>
> and on that note I hear the C++ community (at least one key member)
> is proposing a:
>
> auto add(auto a, auto b) {
> return a + b;
> }
>
> pretty-template syntax! I wouldn't feel right if C++ had something
> that elegant and D did not *wink* *wink* :-)
D already has that:
auto add(T,U)(T a, U b) {
return a + b;
}
In fact, D does it one step better with signature constraints:
auto add(T,U)(T a, U b)
if (is(typeof(a+b)))
{
return a + b;
}
That way, the compiler won't even bother to instantiate the template if
the two types can't be added in the first place.
T
--
Life would be easier if I had the source code. -- YHL
More information about the Digitalmars-d
mailing list