Template constraint: T is a value type

John Colvin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Oct 29 04:49:58 PDT 2014


On Wednesday, 29 October 2014 at 10:01:18 UTC, Gareth Foster 
wrote:
> Hi there,
>
> I'm looking to write a function template that operates only on 
> value types. Basically I'm looking for an equivalent of
>
>   where T: struct
>
> from C# (http://msdn.microsoft.com/en-us/library/d5x73970.aspx)
>
> I was thinking that maybe using
>
>   template Foo(T) if (is(T : struct) or is(T: union)) { ... }
>
> or perhaps
>
>   template Foo(T) if (!is(T : class)) { ... }
>
> would be correct, but I fear the first may be too limiting 
> (would simple data types such as int, char etc be allowed here? 
> I'd guess not.) and the second may be too lax.
>
> Any advice? Am I even going in remotely the right direction? 
> Thanks.

std.traits.hasIndirections any use for you?


More information about the Digitalmars-d-learn mailing list