Template parameter-dependent attributes

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Wed Dec 16 09:14:50 PST 2015


So, I wrote this beautiful BigO framework: <400 lines all told, clear 
code, real nice. Then I got this cold shower:

void insertFrontMany(C, R)(C container, R range)
     @BigO(complexity!(C.insertFront) * linearTime)
{
    ...
}

My hope being of course that for containers with linear insertion time 
at the front I'll get quadratic, etc. The hitch is:

test.d(377): Error: undefined identifier 'C.insertFront'

So... attributes are currently not allowed to depend on template 
parameters, which is a serious damper on enthusiasm.

Seems to me this is a bug - different instantiations should have 
different attributes etc. Is there any matter of principle making this 
not work?

If this won't work at all, I'll need to resort to expressing complexity 
via traits. Not as nice!


Thanks,

Andrei


More information about the Digitalmars-d mailing list