Thread overview | ||||||
---|---|---|---|---|---|---|
|
November 20, 2018 Unqual doesn't remove qualifiers from pointers | ||||
---|---|---|---|---|
| ||||
Is std.traits.Unqual supposed to work on pointers? const int x; static assert(Unqual!(typeof(&x)) == int*); Compiler says: static assert: `is(const(int)* == int*)` is false If it's a bug I'll report it. |
November 20, 2018 Re: Unqual doesn't remove qualifiers from pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Chapman | On Tuesday, 20 November 2018 at 17:44:02 UTC, John Chapman wrote:
> Is std.traits.Unqual supposed to work on pointers?
>
> const int x;
> static assert(Unqual!(typeof(&x)) == int*);
>
> Compiler says: static assert: `is(const(int)* == int*)` is false
>
> If it's a bug I'll report it.
It does work on pointers:
static assert(is(Unqual!(const(int*)) == const(int)*));
Technically there's nothing to Unqual from that typeof(&x): it's already a const(int)*, i.e. a mutable pointer. But it'd be nice to have some "strip'em all" equivalent.
|
November 20, 2018 Re: Unqual doesn't remove qualifiers from pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Chapman | On Tuesday, 20 November 2018 at 17:44:02 UTC, John Chapman wrote: > Is std.traits.Unqual supposed to work on pointers? > > const int x; > static assert(Unqual!(typeof(&x)) == int*); > > Compiler says: static assert: `is(const(int)* == int*)` is false > > If it's a bug I'll report it. Unqual removes qualifies only from the pointer itself, not the type pointed by it. It is not a bug. You can use PointerTarget with Unqual to remove the qualifiers from the target type: static assert(is(Unqual!(PointerTarget!(typeof(&x)))* == int*)); |
November 20, 2018 Re: Unqual doesn't remove qualifiers from pointers | ||||
---|---|---|---|---|
| ||||
Posted in reply to John Chapman | On Tuesday, 20 November 2018 at 17:44:02 UTC, John Chapman wrote:
> Is std.traits.Unqual supposed to work on pointers?
>
> const int x;
> static assert(Unqual!(typeof(&x)) == int*);
>
> Compiler says: static assert: `is(const(int)* == int*)` is false
>
> If it's a bug I'll report it.
No. Unqual only strips from a type, not from any other types contained in that type.
I.e.
Unqual!string == string
Unqual!const(int*) == const(int)*
Unqual!const(int)* == const(int)*
struct S { const int a; }
typeof(Unqual!(const(S)).a) == const int
typeof(Unqual!(S.a) == const int
Please make a bug report to improve the documentation (and PR as well if you like :) )
|
Copyright © 1999-2021 by the D Language Foundation