简体   繁体   中英

Is there any reason why `std::exchange` is not `constexpr`?

std::exchange , introduced in C++14, is specified as follows:

 template< class T, class U = T > T exchange( T& obj, U&& new_value ); 

Replaces the value of obj with new_value and returns the old value of obj .

Here's a possible implementation from cppreference:

template<class T, class U = T>
T exchange(T& obj, U&& new_value)
{
    T old_value = std::move(obj);
    obj = std::forward<U>(new_value);
    return old_value;
}

As far as I can see, there's nothing preventing std::exchange from being marked as constexpr . Is there a reason I am missing why it cannot be constexpr , or is this just an oversight?

截至最新的C ++ 20草案,在Albuquerque ISO C ++委员会会议之后std::exchange成为constexpr ,接受了提案P0202R2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM