www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Unqual doesn't remove qualifiers from pointers

reply John Chapman <johnch_atms hotmail.com> writes:
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.
Nov 20 2018
next sibling parent Stanislav Blinov <stanislav.blinov gmail.com> writes:
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.
Nov 20 2018
prev sibling next sibling parent Eugene Wissner <belka caraus.de> writes:
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*));
Nov 20 2018
prev sibling parent John Colvin <john.loughran.colvin gmail.com> writes:
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 :) )
Nov 20 2018