Template reference parameter

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 23 15:13:37 PDT 2015


On Mon, 23 Mar 2015 22:01:03 +0000, rumbu wrote:

> I'm trying to construct a struct template where one of the template
> parameters is passed by reference (as option)
> 
> struct S(T, U)
> {
>     void opCall(T t, U u) { }
> }
> 
> alias X = S!(T, U);
> alias RX = S!(T, ref U); //not working
> 
> The objective is  to call X(t, u) or RX(t, u), but in second case I want
> "u" to be passed by reference.
> 
> The only solution I found is to pass U as a pointer or as a class.

`ref` is not a part of a type, so you can't do it like this. you have to 
have two different templates for that. or try to use `auto ref`, it may 
help.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150323/2c5688cb/attachment.sig>


More information about the Digitalmars-d-learn mailing list