[Issue 9983] inout type can not be used as a parameter for structure template
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Mar 9 11:45:29 UTC 2018
https://issues.dlang.org/show_bug.cgi?id=9983
--- Comment #1 from anonymous4 <dfj1esp02 at sneakemail.com> ---
Looks like it can be solved by smart enough container constructors.
See this quick PoC:
---
struct Container(T)
{
T value;
inout(T) get() inout
{
return value;
}
}
/// Smart constructor
auto makeContainer(T)(T arg)
{
alias E=typeof(cast()arg[0]);
static if(is(T==inout(E)[]))
{
return inout(Container!(E[]))(arg);
}
else
{
return Container!T(arg);
}
}
auto f(inout int[] a)
{
return makeContainer(a);
}
void g(immutable int[] a)
{
auto b=f(a);
immutable Container!(int[]) c=b;
immutable int[] d=c.get;
immutable int[] e=b.get;
//static assert(false,typeof(b).stringof);
}
void g(int[] a)
{
auto b=f(a);
Container!(int[]) c=b;
int[] d=c.get;
int[] e=b.get;
//static assert(false,typeof(b).stringof);
}
---
--
More information about the Digitalmars-d-bugs
mailing list