d-dbapi ALPHA-2 released

Christian Kamm kamm.incasoftware at shift-at-left-and-remove-this.de
Mon Jun 11 09:06:42 PDT 2007


> Oops, I spoke too soon. I have hit a stumbling block. When working with
> tuples, you cannot use non-constant indexes. This is what I was trying
> to achieve (ambitious no? :))

You can use 'static' foreach, however. If you use foreach with tuples, it is
expanded at compile time. 

> T fetchStruc(T) () {
>    static if (is (T == struct)) {
>       auto r = fetchOne!(FieldTypeTuple!(T))();
>       T t;
> 
>       foreach (i, telem; t.tupleof) {
>          // note that using telem doesn't work sometimes,
>          // so I'm using the index
>          t.tupleof[i] = r.t[i]; 
>       }
> 
>       return t;
>    } else {
>       static assert (0);
>    }
> }

And probably something like

> Row!(T) fetchOne(T ...) () {
>    Row!(T) r;
>
>    foreach(i, relem; r.t)
>    {
>       r.t[i] = getRowElement!(typeof(r.t[i]))(i);
>       // do something with null flags
>    }
>    return r;
> }

Cheers,
Christian




More information about the Digitalmars-d-announce mailing list