How do I write an ADL-enabled trailing return type, or noexcept specification?

I think I would move it into a separate namespace

namespace tricks {
    using std::swap;

    template <typename T, typename U>
    void swap(T &t, U &u) noexcept(noexcept(swap(t, u)));

template <typename T>
void swap(my_template<T>& x, my_template<T>& y)
  noexcept(noexcept(tricks::swap(std::declval<T>(), std::declval<T>()))) 
    using std::swap;
    swap(x.something_that_is_a_T, y.something_that_is_a_T);

Alternatively you can move the whole code up into tricks and delegate to there.

Leave a Comment