Passing struct and struct[] into a template
Taylor Gronka via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 21 22:24:26 PDT 2015
On Wednesday, 22 July 2015 at 05:02:59 UTC, Timon Gehr wrote:
> template Uks(T){
> T query(string q){
> T result;
> static if(is(T==S[],S)){
> ulong test=result.length;
> // append
> S newResult;
> result~=newResult;
> }else{
> // assign
> }
> return result;
> }
> }
>
> void main(){
> struct U_Struct{}
> auto res1=Uks!(U_Struct).query("email");
> auto res2=Uks!(U_Struct[]).query("email");
> }
Oh that's phenomenal. Thanks!
For reference, the is() function can accept template parameters.
More here, under isExpression
http://dlang.org/expression.html
More information about the Digitalmars-d-learn
mailing list