July 24, 2013
T,

I've looked over your code and understand what you are doing but I don't understand the expression

     is(typeof(func(args[0], args[1]))))

you are checking if func(a,b)'s return type is a type?
July 24, 2013
On Wednesday, 24 July 2013 at 17:10:01 UTC, H. S. Teoh wrote:
> On Wed, Jul 24, 2013 at 09:22:14AM -0700, Ali Çehreli wrote:
>> On 07/24/2013 02:56 AM, monarch_dodra wrote:
>> 
>> > On Tuesday, 23 July 2013 at 17:41:01 UTC, Ali Çehreli wrote:
>> 
>> >> Are you aware of version(ctfe)?
>> >
>> > Hum... really? I don't think that exists.
>> 
>> You are right. I must be remembering old proposals about it.
> [...]
>
> There's if(__ctfe), but unfortunately (IIRC) it doesn't work with static
> if, because CTFE runs after static ifs have been processed. So it might
> not be enough if you have code that has parts that can't run under CTFE.
> Those parts will taint all parent functions up the call tree as
> non-CTFEable, so once you have them you're out of luck.
>
> T

That's not true either. The code will compile, and CTFE will only complain if it *runs* into code that can't be executed CTFE-style. For example:

//----
import std.stdio;
import core.stdc.string;

int foo()
{
    if(__ctfe)
    {
        return 1;
    }
    else
    {
        int i = void;
        memset(&i, 0, 4);
        return i;
    }
}

void main(string[] args)
{
    enum a = foo();
    auto b = foo();
    writeln(a, " ", b);
}
//----

This compiles and runs fine, even though memset is not ctfe-able.
July 24, 2013
On Wednesday, 24 July 2013 at 18:12:37 UTC, JS wrote:
T,

Also, I've tried to wrap the template in a function and I can't get it to work:

	
	string join(T...)(string delim, T args)
	{
		return tupleStringReduce!(args);
	}

it seems tupleStringReduce just returns the tuple of of the optimized strings. I'll still need to write code that will deal mixing in the actual compile time and runtime code.

This doesn't seem that hard as tupleReduce essentially outlines the approach. The difference is instead of calling func directly I sort of need to mix it in as a code string.

e.g., for tupleStringReduce, func is x~y. I need to build a string using that "((arg[0]~arg[1])~arg[2])..." which is then mixed in at compile time but at runtime evaluates to a string(not an array).

Since there is no .codeof, AFAIK, I guess the only way to do this is pass func, and the func code string("x~y") in this case.

The idea though is to use the lamba as a ctfe to reduce the tuple when possible but *also* use it at runtime to evaluate the tuple.


Any ideas?


1 2 3
Next ›   Last »