C++ Logo

std-proposals

Advanced search

std::variant still may be valueless_by_exception in too many cases

From: Askar Safin <safinaskar_at_[hidden]>
Date: Tue, 21 Jan 2020 20:29:33 +0300
Hi. As well as I understand, currently any variant, including variant<float, int> may be valueless_by_exception, see example in https://en.cppreference.com/w/cpp/utility/variant/valueless_by_exception . I think this situation is bad, we should make valueless_by_exception as rare as possible. And we should guarantee for some "Types..." (or even for all) that variant will never be valueless_by_exception.

There is good issue, but unfortunately it is not changed since 2017: https://cplusplus.github.io/LWG/lwg-active.html#2881 .

Also, I want type trait "std::always_has_value". It should take variant type. If it always has value, then this type trait should give true. Thus, using static_assert I can be sure that in my particular code base variant is never valueless.

Askar Safin

Received on 2020-01-21 11:32:09