On Tuesday, 14 January 2014 at 13:04:58 UTC, Timon Gehr wrote:
On 01/14/2014 11:09 AM, Jacob Carlborg wrote:
On 2014-01-14 09:36, Jakob Ovrum wrote:
You'll have to get used to the exclamation mark, otherwise
you'll never
be able to fully appreciate D's generic programming. I quite
like it - I
don't think there's anything objectively ugly about it.
Or, in this case, fix the compiler to be able to inline
delegates. Or is
there any other advantage of using an alias parameter instead
of a
delegate?
1. It is likely to result in faster code when inlining fails.
Eg. it will often not allocate when the delegate would, due to
nested template instantiation simplifying escape analysis.
2. IFTI limitations. Eg. the following cannot work with the
current language unless 'map' is specialized to ranges of int:
[1,2,3].map(x=>2*x)
3. Lazy ranges don't have to carry around delegates.
4. Algorithms can specialize depending on the argument function.
However, this is currently only possibly when string lambdas are
used... (e.g. std.algorithm.startsWith does this)
5. Alias parameters receiving function templates have the benefit
of being able to instantiate the function template argument
multiple times with different template arguments. This is murky
territory when it comes to function literals with inferred
parameter types though - they are not guaranteed to be
implemented in terms of function templates.