Constexpr-ness of std :: optional <T> :: value_or
As shown on this page , the version of ref std::optional<T>::value_or not defined by constexpr :
template< class U > constexpr T value_or( U&& default_value ) const&; template< class U > T value_or( U&& default_value ) &&; What are the reasons for this? Is this because moving a value can change an optional object?
But if we make the && version also constexpr , it is not good that we can now write:
constexpr int x = std::optional<int>(123).value_or(456); +8
Zizheng tai
source shareNo one has answered this question yet.
See related questions:
2437
838
651
567
526
514
8
6
5
2