C++ Logo


Advanced search

Re: Function proposal: generic value_or

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Mon, 5 Jul 2021 17:27:36 -0400
On Mon, Jul 5, 2021 at 4:34 PM Roberto Romani via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> If the word “value” in the name of the function may create confusion then
> the function may be called “coalesce”.
> The goal is to have a function that makes cleaner and less error prone
> things like v = p1 ? *p1 : p2 ? *p2 : defaultValue;

So basically, you claim that
    v = p1 ? *p1 : p2 ? *p2 : defaultValue;
is too confusing for the reader to understand at a glance, and you think
the reader would prefer to see
    v = std::coalesce(defaultValue, p1, p2);
And you also claim that it is *not* useful to provide any special library
support for
    v = p1 ? p1[42] : defaultValue;
nor for
    v = p1 ? *p1 : computeDefaultValue();

I don't buy either of these claims. Therefore, I recommend not pursuing
this idea any further.
However, if you do pursue it, you should start by finding about five places *in
existing open-source codebases* where this library function would be
applicable, and then showing how you'd rewrite those snippets to improve
their... clarity, right? You're going for clarity here? So, show the
"before and after." In the WG21 biz, this is known as a "Tony Table."


Received on 2021-07-05 16:27:49