On Tuesday, 10 November 2020 at 17:09:00 UTC, Paul Backus wrote:
bool between(Value, Bound)(auto ref Value value, auto ref Bound low, auto ref Bound high)
{
    return (low < value) && (value < high);
}

You need `auto ref` because either Bound or Value may have copying disabled. Because the function is a template, attributes like `scope` will be inferred when applicable (modulo compiler bugs).

Interesting, so "auto ref T" is the go-to type specifier for generic code then? I guess I also should conditionally add things like pure, nogc, nothrow... I assume I would have to test the comparison operator. I actually want to implement

(low <= value) && (value < high)

So I guess I need to test both. But how...? compiles-trait?

Reply via email to