.. _swappable: *************** meta::swappable *************** Defined in header ````. .. code-block:: cpp template concept swappable = requires(T& a, T& b) { /* using std::swap; */ swap(a, b); }; Pre-C++20 implementation of the :concept:`swappable` concept. ---- Differences with the C++20 version ================================== * The implementation does not rely on :cpp:`std::ranges::swap `, but on the usual customization point idiom, i.e. ``using std::swap; swap(/* ... */);``. * The :concept:`std::swappable_with ` concept cannot be implemented using :cpp:`std::swap `, since it constrains its parameters to have the exact same type. Concept emulation ================= .. code-block:: cpp namespace mgs { namespace meta { template struct is_swappable { /* ... */ }; template constexpr auto is_swappable_v = is_swappable::value; template >> using swappable = T; } // namespace meta } // namespace mgs Example ======= .. code-block:: cpp #include using namespace mgs::meta; struct dummy_swappable { // prevent from being used by default std::swap dummy_swappable(dummy_swappable const&) = delete; }; void swap(dummy_swappable&, dummy_swappable&); static_assert(is_swappable_v, ""); static_assert(is_swappable_v, "");