Skip to content

Instantly share code, notes, and snippets.

@Dich0tomy
Created March 13, 2022 10:12
Show Gist options
  • Save Dich0tomy/31943a9c1af9ac65444e69ca0615a0f3 to your computer and use it in GitHub Desktop.
Save Dich0tomy/31943a9c1af9ac65444e69ca0615a0f3 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstring>
#include <cstddef>
#include <string>
namespace impl {
template <typename Type>
auto swap(Type& first, Type& second) -> void {
std::cout << "No swap :(";
auto temp = std::move(first);
first = std::move(second);
second = std::move(temp);
}
} // namespace impl
namespace my_own_std {
template <typename Type>
auto swap(Type& first, Type& second) -> void {
using impl::swap;
swap(first, second);
}
} // namespace my_own_std
namespace own {
class IHaveMyOwn {};
class IDontHaveMyOwn {};
auto swap(IHaveMyOwn&, IHaveMyOwn&) -> void { std::cout << "I have my own!\n"; }
} // namespace own
auto main() -> int {
auto i_have_my_own = own::IHaveMyOwn();
auto i_have_my_own2 = own::IHaveMyOwn();
my_own_std::swap(i_have_my_own, i_have_my_own2);
auto i_dont_have_my_own = own::IDontHaveMyOwn();
auto i_dont_have_my_own2 = own::IDontHaveMyOwn();
my_own_std::swap(i_dont_have_my_own, i_dont_have_my_own2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment