About 232,000 results
Open links in new tab
  1. c++ - How does the standard library implement std::swap ... - Stack ...

    Aug 13, 2014 · A swap member function can temporarily break invariants if doing so is faster than doing three full moves that have to maintain invariants after each move. If there's an efficient X::swap(X&) …

  2. c++ - What is the copy-and-swap idiom? - Stack Overflow

    A swap function is a non-throwing function that swaps two objects of a class, member for member. We might be tempted to use std::swap instead of providing our own, but this would be impossible; …

  3. c++ - how to provide a swap function for my class? - Stack Overflow

    It's also said that the standard library uses an unqualified call to the swap function in order to call user-defined swap for a user class if such user-defined swap is provided.

  4. Is there a built in swap function in C? - Stack Overflow

    Jan 14, 2012 · Is there any built in swap function in C which works without using a third variable?

  5. How to use c++ swap function? - Stack Overflow

    Apr 2, 2020 · The arguments to std::swap() are two integer pointers, not two addresses of an array with an index. For swapping normal singular int values you will have to use a pointer (call by reference), …

  6. c++ - How to implement swap ()? - Stack Overflow

    Jul 24, 2012 · The C++11 standard says an object t is swappable with an object u if swap(t, u) and swap(u, t) are valid expressions that select non-member functions called swap from an overload set …

  7. c++ - How to overload std::swap () - Stack Overflow

    You're not allowed (by the C++ standard) to overload std::swap, however you are specifically allowed to add template specializations for your own types to the std namespace.

  8. c++ - Does swap () function works in iostream header? - Stack Overflow

    Jan 20, 2022 · swap is not a keyword in C++ but rather a function from the C++ standard library. So to use it you need to bring in the function from the appropriate C++ standard library header.

  9. C++ trying to swap values in a vector - Stack Overflow

    Jun 3, 2011 · I had this same issue, and there are a lot of answers recommending std::swap (like the highest voted one here does) but std::swap does not work (directly) for swapping the contents of two …

  10. Swapping addresses of pointers in C++ - Stack Overflow

    Dec 1, 2009 · The swap(int*a, int*b) function has two pointers, holding the address of two integers in memory. So, what it can do is [1] set aside a copy of the first integer, [2] copy the second integer in …