swap
语法:
1 |
void swap( deque &target ); |
swap()函数交换target和现双向队列中元素。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
源代码 /** * @brief Swaps data with another %deque. * @param x A %deque of the same element and allocator types. * * This exchanges the elements between two deques in constant time. * (Four pointers, so it should be quite fast.) * Note that the global std::swap() function is specialized such that * std::swap(d1,d2) will feed to this function. */ void swap(deque& __x) { std::swap(this->_M_impl._M_start, __x._M_impl._M_start); std::swap(this->_M_impl._M_finish, __x._M_impl._M_finish); std::swap(this->_M_impl._M_map, __x._M_impl._M_map); std::swap(this->_M_impl._M_map_size, __x._M_impl._M_map_size); } |
测试代码
测试结果
1 1 1 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0