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
data locality - fast example
cast operator
Beadandó
queue-with-fixed-size
Finding the first digit of a number
Treap for spoj : MEANARR (we can use policy based data structures instead)
Ultimo intento
DeltaX campus recruitment
pranav pandey
RuntimeError