On Friday, 6 December 2019 at 07:03:45 UTC, berni44 wrote:
My real question is: Can this code duplication be avoided somehow? (I ask, because I've got a PR running, which increases the size of these functions and it doesn't feel good to have two long, almost identical functions.)

You can use a template this parameter [1] to have a new copy of opCmp generated for each qualified version of Tuple it's called with:

int opCmp(R, this This)(R rhs) const
if (areCompatibleTuples!(typeof(this), R, "<"))
{
    ...
}

This may lead to binary bloat, though, since you can potentially have separate instantiations for mutable, const, immutable, inout, shared, etc.

[1] https://dlang.org/spec/template.html#template_this_parameter

Reply via email to