Namespaces
Variants
Views
Actions

Talk:cpp/algorithm/swap

From cppreference.com

[edit] Which header

std::swap is defined in header <algorithm> in C++03 (25.2.2[lib.alg.swap]) but in header <utility> in C++11 (FDIS 20.2.2[utility.swap]). How can that difference be expressed? --Cubbi 11:25, 23 August 2011 (PDT)

Fixed that.P12 13:33, 23 August 2011 (PDT)

[edit] Possible implementation

Would it be OK to add a "possible implementation" section?

template<class T>
void swap(T& lhs, T& rhs) {
    T tmp = move(lhs);    // T satisfies MoveConstructible
    lhs = move(rhs);      // T satisfies MoveAssignable
    rhs = move(tmp);      // T satisfies MoveAssignable
}

-- [email protected] (talk) 16:30, 26 September 2017 (PDT)