Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 974 Bytes

swap2.md

File metadata and controls

53 lines (41 loc) · 974 Bytes

rome:: swap(rome::delegate)

template<typename Ret, typename... Args, typename Behavior>
void swap(
    delegate<Ret(Args...), Behavior>& lhs,
    delegate<Ret(Args...), Behavior>& rhs) noexcept;

Overloads the commonly used swap algorithm for rome::delegate. Exchanges the stored callable objects of both instances. Effectively calls lhs.swap(rhs).

Parameters

lhs, rhs -- The rome::delegate instances whose content to exchange.

Return value

(none)

Examples

See the code in examples/swap.cpp.

#include <iostream>
#include <utility>
#include <rome/delegate.hpp>

int main() {
    rome::delegate<void()> d1 = []() { std::cout << "1\n"; };
    rome::delegate<void()> d2 = []() { std::cout << "2\n"; };
    d1();
    d2();
    d1.swap(d2);
    d1();
    d2();
    {
        using std::swap;
        swap(d1, d2);
    }
    d1();
    d2();
}

Output:

1
2
2
1
1
2