Const vs Non const method
Andrea Fontana via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Feb 25 02:44:49 PST 2016
Check this simple code:
http://dpaste.dzfl.pl/2772c9144f1c
I can't understand how to minimize code duplication for function
like get().
Of course on real case body is much bigger and complex than that.
The only way I found is to move the body of function inside a
mixin template:
mixin template getterImpl()
{
auto getterImpl() { /* very long body */ return inner; }
}
and then:
auto get() const { mixin getterImpl; return getterImpl; }
auto get() { mixin getterImpl; return getterImpl; }
Am I missing something? I don't think it's the right way.
More information about the Digitalmars-d-learn
mailing list