Как я могу использовать вывод типа для удаления неизменяемого / const в объявлении переменной? Это вообще возможно?
immutable uint immutableX = 42;
// keep the type (uint) but remove the immutability
/* compiler magic */ mutableX = immutableX;
Решение для вывода без типа:
uint mutableX = immutableX;
Полный пример:
void main()
{
immutable uint immutableX = 42;
pragma(msg, "immutableX: ", typeof(immutableX));
assert(typeof(immutableX).stringof == "immutable(uint)");
// how to use type inference so that possible immutable/const is removed ?
// the expected type of mutableX is uint
auto mutableX = immutableX;
pragma(msg, "mutableX: ", typeof(immutableX));
// this should be true
assert(typeof(immutableX).stringof == "uint");
}