Template constraints for reference/value types?
Lodovico Giaretta via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Sep 6 14:00:53 PDT 2016
On Tuesday, 6 September 2016 at 20:46:54 UTC, Jon Degenhardt
wrote:
> Is there a way to constrain template arguments to reference or
> value types? I'd like to do something like:
>
> T foo(T)(T x)
> if (isReferenceType!T)
> { ... }
>
> --Jon
You can use `if(is(T : class) || is(T : interface))`.
If you also need other types, std.traits contains a bunch of
useful templates: isArray, isAssociativeArray, isPointer, ...
More information about the Digitalmars-d-learn
mailing list