IFTI with constant args, is this already possible?

Don Clugston dac at nospam.com.au
Thu Feb 1 03:04:13 PST 2007

Chad J wrote:
> Don Clugston wrote:
>> Chad J wrote:
>>> So suppose I have a function template, one that is supposed to be 
>>> instantiated via IFTI.  Then, the user supplies an argument that is 
>>> constant (ex: foo(42,"cat")).  Is there any way that I can grab those 
>>> constant arguments at compile time and use them to do compile time 
>>> computation?  Even better, can I do it in variadic templates?
>>> I'm envisioning a situation like this:
>>> // the string-to-integer conversion is done at compile time
>>> bignum bigAssInteger = "3420894398526094609987620490236001914309690234";
>> There's no syntax sugar for this at present. (Though I've proposed it, 
>> and there are indications that it will happen).
>> But:
>> bigAssInteger = 
>> toBigInt!("3420894398526094609987620490236001914309690234");
>> is currently possible.
>> Until we get early discard of templates, it's not really a good idea 
>> right now because compilation is slow while the compiler generates an 
>> enormous obj file full of junk.
> Ah.  Thanks for the info.

BTW, my proposal was for something like:

BigInt opAssign(super T : char [])(T s){
    static if (is(s == const)) {
      // compile-time assign
    } else {
       // runtime-assign.

Requires (1) super in a template parameter list distinguishes between 
storage classes.
(2) is( A B == const) --> if A is a literal, sets B to be that literal.

Andrei's storageof() proposal could probably achieve the same thing.

More information about the Digitalmars-d-learn mailing list