Unqual fails with pointer?

Namespace rswhite4 at googlemail.com
Thu Jun 13 14:52:24 PDT 2013


On Thursday, 13 June 2013 at 21:32:19 UTC, Namespace wrote:
> ----
> import std.traits : Unqual;
>
> void main() {
> 	static assert(is(Unqual!int == int));
> 	static assert(is(Unqual!(const int) == int));
> 	static assert(is(Unqual!(immutable int) == int));
> 	static assert(is(Unqual!(shared int) == int));
> 	static assert(is(Unqual!(shared(const int)) == int));
> 	static assert(is(Unqual!int* == int*));
> 	static assert(is(Unqual!(const int*) == int*)); /// Error: 
> static assert  (is(const(int)* == int*)) is false
> }
> ----
>
> Is this expected?

This works:
----
template UnqualPtr(T) {
	static if (is(T == shared(const U*), U))
		alias UnqualPtr = U*;
	else static if (is(T == const U*, U))
		alias UnqualPtr = U*;
	else static if (is(T == immutable U*, U))
		alias UnqualPtr = U*;
	else static if (is(T == inout U*, U))
		alias UnqualPtr = U*;
	else static if (is(T == shared U*, U))
		alias UnqualPtr = U*;
	else static if (is(T == shared(const U), U))
		alias UnqualPtr = U;
	else static if (is(T == const U, U))
		alias UnqualPtr = U;
	else static if (is(T == immutable U, U))
		alias UnqualPtr = U;
	else static if (is(T == inout U, U))
		alias UnqualPtr = U;
	else static if (is(T == shared U, U))
		alias UnqualPtr = U;
	else
		alias UnqualPtr = T;
}
----


More information about the Digitalmars-d-learn mailing list