Value or Reference Semantics Trait

Orvid King blah38621 at gmail.com
Mon Jan 13 07:02:06 PST 2014


On 1/13/14, anonymous <anonymous at example.com> wrote:
> On Monday, 13 January 2014 at 13:41:30 UTC, Orvid King wrote:
>> If you just want to check if specifically it's a structure, you
>> could
>> always check `__traits(compiles, T()) && if(typeof(T()) == T)`
>> beware
>> however that this will evaluate to true if T is a class with a
>> static
>> opCall who's return type is T.
>
> is(T == struct)
>

Or that, yeah XD (For some reason I was thinking about ensuring that
it was constructible, which, after reading the question again, isn't
actually needed, woops :D)

With that in mind, value type semantics would be `enum
hasValueSemantics(T) = is(T == struct) || is(T == enum) || is(T ==
union) || isArray!T;` Be aware however that this assumes you want
arrays to be considered to have value semantics due to their length
and base element being by-value.


More information about the Digitalmars-d-learn mailing list