o!(const(T)) parameter.
sclytrack via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Apr 25 07:52:44 PDT 2015
I want a function with parameter o!(const(Form)) to accept both
o!(Form) and o!(immutable(Form))
Is there a way to do it?
import std.stdio;
import std.traits;
class Form
{
int number = 10;
}
struct o(T)
{
T data;
this(T data)
{
this.data = data;
}
o!(const(Unqual!(T))) constify() const
{
return o!(const(Unqual!(T)))(data);
}
alias constify this;
}
void hello(o!(const(Form)) frm)
{
writeln(frm.data.number);
writeln(typeof(frm.data).stringof);
}
void main()
{
writeln("This application works nicely");
auto frm = o!(Form) (new Form());
// auto ifrm = o!(immutable(Form)) (new immutable Form());
hello(frm);
// hello(ifrm);
}
More information about the Digitalmars-d-learn
mailing list