Coalescing lvalue references to std-optionals
So ideally you want to write something like:

template &lt;typename... Ts&gt;
constepxr auto coalesce(std::optional&lt;Ts&gt;&amp;... xs)
{
   return (xs || ...);
}


But the issue here is of course that it will convert the optionals to bool before applying the boolean or-operator. You could however cast it to a type that does provide the right semantics for the boolean or-operator to do the thing you want:

template &lt;typename T&gt;
struct coalescable {
    T &amp;x;
    coalescable(T &amp;x_): x(x_) {}
    constexpr const coalescable &amp;operator||(const coalescable &amp;other) {
        return x.has_value() ? *this : other;
    }
};


And then use that in the fold expression:

template &lt;typename... Ts&gt;
constepxr auto coalesce(std::optional&lt;Ts&gt;&amp;... xs)
{
   return (coalescable(xs) || ...).x;
}