Using templates with interfaces

via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 25 10:30:58 PDT 2017


On Sunday, 25 June 2017 at 13:32:57 UTC, Andrew Chapman wrote:
> I think you've answered the question with "You cannot have 
> unimplemented templates in interfaces".  Thanks for the answer.
>  I'll rethink the way I'm doing this.
>
> Cheers.

In your case you can probably use something along the lines of:

interface RelationalDBInterface
{
     // You can even make this protected
     Varaint loadUntypedRow(string sql, Variant[] params);

     final T loadRow(T)(string sql, Variant[] params)
     {
         auto row = loadUntypedRow(sql, params);

         enforce(row.hasValue,
             this.classID ~ "::loadRow - Query returned an empty 
row");
	
	return row.toStruct!T;
     }
}


More information about the Digitalmars-d-learn mailing list