martinmoene / optional-lite

optional lite - A C++17-like optional, a nullable object for C++98, C++11 and later in a single-file header-only library
Boost Software License 1.0
403 stars 45 forks source link

gcc-4.8 compilation error due to value_or ambiguity #35

Closed SX91 closed 5 years ago

SX91 commented 5 years ago

rvalue version of value_or is currently defined like that:

    template< typename U >
    optional_constexpr value_type value_or( U && v ) const optional_refref_qual
    {
        return has_value() ? std::move( contained.value() ) : static_cast<T>(std::forward<U>( v ) );
    }

which causes compilation error due to an ambiguity.

Changing the signature to optional_constexpr14 value_type value_or( U && v ) optional_refref_qual fixes the issue.

SX91 commented 5 years ago

@martinmoene may I ask what's the point of constexpr value_type const && value() const? It actually disables move-out of optional, isn't it?

martinmoene commented 5 years ago

Perhaps to provide a complete overload-set, see CppCon 2018: Titus Winters “Modern C++ Design (part 1 of 2)” @39.21, for several minutes.