More bugs...
James Miller
james at aatch.net
Sat Apr 28 23:22:32 PDT 2012
On Saturday, 28 April 2012 at 09:36:55 UTC, Timon Gehr wrote:
> On 04/28/2012 08:03 AM, Mehrdad wrote:
>>> You expected that to work?
>>
>> Uhm, why not?
>>
>> template<class T>
>> struct F
>> {
>> F<F<T> > f() { return F<F<T> >(); }
>> };
>>
>> int main()
>> {
>> F<int>().f().f().f().f().f(); // etc.
>> return 0;
>> }
>
>
> D templates are analysed eagerly upon instantiation, whereas
> C++ templates are analysed lazily. This is not a bug, it is a
> feature.
Furthermore, eager analysis is necessary for other D features
like CTFE and compile-time reflection. Honestly, in C++ I would
stay away from code like the above anyway, irrelevant of whether
it compiles, seems too "magic-y" for my tastes. I don't like
things not being explicit.
--
James Miller
More information about the Digitalmars-d
mailing list