Make a function accepting an optional to accept a non-optional?

Another version. This one doesn’t involve anything:

template <typename T>
void f(T&& t) {
    std::optional opt = std::forward<T>(t);
}

Class template argument deduction already does the right thing here. If t is an optional, the copy deduction candidate will be preferred and we get the same type back. Otherwise, we wrap it.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)