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
c ++ c ++ 11 c ++ 14 c ++ 17
source share

No one has answered this question yet.

See related questions:

2437
Why "use the std namespace;" considered bad practice?
838
How to convert std :: string to const char * or char *?
651
std :: wstring VS std :: string
567
What is std :: move (), and when should it be used?
526
The difference between `constexpr` and` const`
514
Do const std :: string & transition days go by as a parameter?
8
C ++ 17: Still using enumerations as constants?
6
Idiomatic way to force constexpress functions to execute constexpr
5
std :: mem_fn with ref_qualified member functions
2
constexpr std :: optional possible implementation

All Articles