foreach in compile time function?

Johan Granberg lijat.meREM at OVE.gmail.com
Sat Mar 10 10:04:35 PST 2007


Sean Kelly wrote:

> Johan Granberg wrote:
>> Is this code supposed to work?
>> 
>> char[] test(char[] d)
>> {
>>         char[] v="";
>>         foreach(dchar c;d)
>>                 v~=c;
>>         return v;
>> }
>> void main()
>> {
>>         const a=test("test");
>>         printf("%*.s",a);
>> }
> 
> This is because you want foreach to implicitly convert your char array
> to dchars, and this happens in the compier runtime at, well, run-time.
> I imagine it would be possible to create compile-time routines to do
> this, but that feature isn't built into the compiler right now.
> 
> 
> Sean

Ok, it would be usefull if it worked thou.


More information about the Digitalmars-d-learn mailing list