[Issue 13428] Add template to perform appropriate substitution for inout when it appears in a type
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Aug 16 10:50:06 UTC 2019
https://issues.dlang.org/show_bug.cgi?id=13428
--- Comment #3 from Simen Kjaeraas <simen.kjaras at gmail.com> ---
I revisited this today, and realized it does not handle mixed qualifiers, like
inout(const(int)*). As this is a rather big oversight, here's an improved
implementation:
template SubstituteInout(FromType, ToType)
{
alias Modifiers(T) = CopyTypeQualifiers!(FromType, T);
alias Next(T) = SubstituteInout!(FromType, T);
static if (is(ToType U == immutable U)) alias SubstituteInout
= immutable Next!U;
else static if (is(ToType U == shared inout const U)) alias SubstituteInout
= shared const Modifiers!(Next!U);
else static if (is(ToType U == shared inout U)) alias SubstituteInout
= shared Modifiers!(Next!U);
else static if (is(ToType U == shared const U)) alias SubstituteInout
= shared const Next!U;
else static if (is(ToType U == shared U)) alias SubstituteInout
= shared Next!U;
else static if (is(ToType U == inout const U)) alias SubstituteInout
= const Modifiers!(Next!U);
else static if (is(ToType U == inout U)) alias SubstituteInout
= Modifiers!(Next!U);
else static if (is(ToType U == const U)) alias SubstituteInout
= const Next!U;
else static if (is(ToType U == U* )) alias SubstituteInout
= Next!U*;
else static if (is(ToType U == U[] )) alias SubstituteInout
= Next!U[];
else static if (is(ToType U == U[N], size_t N)) alias SubstituteInout
= Next!U[N];
else static if (is(ToType U == U[K], K)) alias SubstituteInout
= Next!U[Next!K];
else alias SubstituteInout
= ToType;
}
unittest {
static assert(is(SubstituteInout!(const(string), int) == int));
static assert(is(SubstituteInout!(const(string), inout(int)[]) ==
const(int)[]));
static assert(is(SubstituteInout!(const(string), inout(int)) ==
const(int)));
static assert(is(SubstituteInout!(const(string), inout(int)*[][3][int]) ==
const(int)*[][3][int]));
static assert(is(SubstituteInout!(const(string), inout(int)[inout(string)])
== const(int)[const(string)]));
static assert(is(SubstituteInout!(const(int), inout(const(int)*)) ==
const(int*)));
static assert(is(SubstituteInout!(int, inout(const(int)*)) ==
const(int)*));
}
--
More information about the Digitalmars-d-bugs
mailing list