write a function template specialisation that tests if an argument is known at compile time

Cecil Ward d at cecilward.com
Sat Aug 11 06:16:38 UTC 2018


On Saturday, 11 August 2018 at 05:17:51 UTC, Cecil Ward wrote:
> T myfunc(T)( T x, uint mask )
>    if ( mask == 3 )
>    {
>    return fast_func( x, mask );
>    }
>
> but of course this doesn't work because mask is not known at 
> compile-time.

Actually is there an opportunity for some kind of language 
enhancement there? I do not really know what I am talking about 
AT ALL but if the compiler could silently add an extra 
specialisation that gets generated at compile time, with constant 
folding and all the optimisations that follow from it, if a call 
with an appropriate constant argument is seen? But this is 
probably horrible because that kind of stuff is ph performed at a 
completely different point ?


More information about the Digitalmars-d-learn mailing list