Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Изволов#8
//g++ 5.4.0 // Реализовать функцию universal_swap #include <algorithm> #include <cassert> namespace ns { struct swappable { explicit swappable(int x): x(x) {} // Ни копировать, ни переносить нельзя. swappable(const swappable &) = delete ; swappable(swappable &&) = delete ; swappable& operator= (const swappable &) = delete ; swappable& operator= (swappable &&) = delete ; void swap ( swappable& that ) { std::swap( that.x, this->x); } int x; }; void swap( swappable& l, swappable& r) { l.swap (r); } } template <typename T> void universal_swap(T& left, T& right); // <-- int main () { auto x = 4; auto y = -1; universal_swap(x, y); // <-- assert(x == -1); assert(y == 4); ns::swappable a(3); ns::swappable b(42); universal_swap(a, b); // <-- assert(a.x == 42); assert(b.x == 3); }
run
|
edit
|
history
|
help
0
IndiSort
fibonacci
decrypt_problem_5
Dar
Defining Class Members
Addition of two matrix **Part 1
Test Swap Functions
Zadanie Kolokwium 2013: Trójkąty i trójkąty
Base conversion
Kth smallest element