Re: Is it possible to force CTFE?

2012-10-01 Thread Don Clugston
On 27/09/12 15:01, bearophile wrote: Tommi: 2) Is it possible to specialize a function based on whether or not the parameter that was passed in is a compile time constant? I am interested in this since some years. I think it's useful, but I don't know if it can be implemented. I don't

Re: Is it possible to force CTFE?

2012-09-28 Thread Tommi
One use case I can think of for specializing functions based on whether or not its arguments are compile-time evaluable: // Big container that can't be accessed in constant time: immutable cachedResults = init(); double getResult(args) if (areCompileTimeConstants!(args) == false) {

Re: Is it possible to force CTFE?

2012-09-28 Thread Tommi
On Friday, 28 September 2012 at 17:52:55 UTC, Tommi wrote: In a perfect world, I think, the compiler would always evaluate all possible functions at compile-time, given that doing so would produce a smaller (or equal size) executable than what not-evaluating-at-compile-time would produce.

Re: Is it possible to force CTFE?

2012-09-27 Thread Tommi
On Sunday, 10 June 2012 at 10:16:23 UTC, jerro wrote: No, but you could wrap it in a template to force it to always execute at compile time. So, I just realized, I could have just this one convenience template that I can use whenever I want to force an expression to be evaluated at

Re: Is it possible to force CTFE?

2012-09-27 Thread bearophile
Tommi: 2) Is it possible to specialize a function based on whether or not the parameter that was passed in is a compile time constant? I am interested in this since some years. I think it's useful, but I don't know if it can be implemented. I don't remember people discussing about this

Re: Is it possible to force CTFE?

2012-09-27 Thread Jacob Carlborg
On 2012-09-27 15:01, bearophile wrote: Tommi: 2) Is it possible to specialize a function based on whether or not the parameter that was passed in is a compile time constant? I am interested in this since some years. I think it's useful, but I don't know if it can be implemented. I don't

Re: Is it possible to force CTFE?

2012-09-27 Thread bearophile
Jacob Carlborg: I am interested in this since some years. I think it's useful, but I don't know if it can be implemented. I don't remember people discussing about this much. There's the if (__ctfe) hack. Also using only template parameters will force the function to be CTFE. This is quite

Is it possible to force CTFE?

2012-06-10 Thread Tommi
Three related questions: 1) Is there a way to force a function to be always executed at compile time (when it's possible to do so) no matter what context it's called in? 2) Is it possible to specialize a function based on whether or not the parameter that was passed in is a compile time

Re: Is it possible to force CTFE?

2012-06-10 Thread jerro
1) Is there a way to force a function to be always executed at compile time (when it's possible to do so) no matter what context it's called in? No, but you could wrap it in a template to force it to always execute at compile time. Of course it could then only be called at compile time. 2) Is

Re: Is it possible to force CTFE?

2012-06-10 Thread Timon Gehr
On 06/10/2012 09:04 AM, Tommi wrote: Three related questions: 1) Is there a way to force a function to be always executed at compile time (when it's possible to do so) no matter what context it's called in? No there is not. You could use a template that calls a private function at compile

Re: Is it possible to force CTFE?

2012-06-10 Thread Tommi
On Sunday, 10 June 2012 at 10:23:09 UTC, Timon Gehr wrote: No there is not. You could use a template that calls a private function at compile time instead. What is your use case? I was just thinking about a situation where a property accessor/mutator methods are not as simple as read/assign