Split out of #30643
To avoid repetition and make the diff trivial between the two branches (calling the copy vs move constructors), this expression was originally written as a ternary, which unfortunately introduced an additional copy operation (and was reverted to a verbose if statement with a comment). This change attempts to restore the signal to noise ratio of such a simple expression while retaining its performance.
See related discussions:
And reproducer that demonstrates the behavior of all 3 cases: