Why don't std :: future <T> and std :: shared_future <T> not provide membership swap ()?
All classes in the C ++ Standard Library have a member exchange function, including some polymorphic classes, such as std::basic_ios<CharT>. The template class std::shared_future<T>is the type of value, and std::future<T>is the type of value only for moving. Is there any special reason they don't provide a member function swap()?
The swap member was a massive increase in performance before std::movesupport in C ++ 11. For example, you could move one vector to another place. It was also used in sizes vector, and this meant that inserting vectors into a vector was not a complete suicidal capacity.
After std::movearriving in C ++ 11, with many sometimes empty types was implemented by default std::swap:
template<class T>
void swap( T& lhs, T& rhs ) {
auto tmp = std::move(rhs);
rhs = std::move(lhs);
lhs = std::move(tmp);
}
will be basically as fast as custom-written.
Existing types with members swapare unlikely to lose them (at least right away). However, a new type of API extension should be justified.
std::future std::unique_ptr< future_impl >, 4 , 3 . , 1 (, SSA 2), .swap .
1 , , lhs rhs , tmp : , tmp, , no-op dtor.