How to port C++ std::is_reference<T> to D ?
Paul Backus
snarwin at gmail.com
Wed May 6 16:01:37 UTC 2020
On Wednesday, 6 May 2020 at 09:40:47 UTC, wjoe wrote:
> yes, I did read the spec. I read the language spec on traits as
> well as std.traits docs as well as searching the internet for a
> solution since day before yesterday. But I couldn't bring it
> together because
>
> } else static if (__traits(isRef, T)) {
>
> compiles, but e.g.
>
> assert (modifier!(ref int) == "[out] ");
>
> doesn't.
> Anyways, thanks for your reply.
D doesn't have reference *types*, it only has reference
*parameters*. Here's an example:
void fun(ref int r, int v) {
static assert(is(typeof(r) == int)); // note: not `ref int`
static assert(is(typeof(r) == typeof(v))); // `ref` makes no
difference to type
static assert(__traits(isRef, r)); // note: not
`__traits(isRef, typeof(r))`
static assert(!__traits(isRef, v));
}
More information about the Digitalmars-d-learn
mailing list