indexing tuples using strings

Sergey Gromov snake.scaly at gmail.com
Thu Dec 4 06:16:10 PST 2008


Mon, 1 Dec 2008 22:49:24 +0000 (UTC), BCS wrote:

> Reply to Jason,
> 
>> No recursive template-foo needed
> 
> template IndexOf(char[] str, Strs...)
> {
>     const int IndexOf = typeof(
>     *{
>        foreach(int i, char[] s; Strs)
>        {
>            static char[i] r;
>            static if(Strs[i] == str)
>                return &r;
>        }
>     }()).length;
> }
> 
> import std.stdio;
> void main()
> {
>     writef("%d\n", IndexOf!("hello", "go", "say", "hello", "to", "bob"));
> }

Master!



More information about the Digitalmars-d mailing list