Define methods using templates
Claude via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Dec 30 07:31:36 PST 2014
Thanks Steven and Daniel for your explanations.
> mixin template opAssign(alias Field) {
> void opAssign(Tin)(auto ref Tin param) @property pure
> @safe
> {
> Field = param;
> m_matrixCalculated = false;
> }
> }
>
> mixin opAssign!(m_pos) pos;
I tested both the "string mixin" and "opAssign" implementations,
and they work like a charm.
I would have never thought of using both @property and
"opAssign", but it looks like a secure way of doing it for the
compilation fails nicely if I type a wrong field in.
src/camera.d(58): Error: undefined identifier m_os, did you mean
variable m_pos?
More information about the Digitalmars-d-learn
mailing list