|
Boost : |
From: Steven Watanabe (steven_at_[hidden])
Date: 2007-08-11 13:04:56
AMDG
David Abrahams <dave <at> boost-consulting.com> writes:
> >
> > template <class T>
> > void koenig_swap(T& left, T& right)
> > {
> > using std::swap;
> > swap(left,right);
> > }
> >
> > Several boost libraries (multi array, compressed pair, graph,
> > optional, spirit) already use this technique, each time explicitly
> > with 'using std::swap' instead of abstracting it out.
>
> The appropriate name for that function is boost::swap
>
To prevent infinite recursion or ambiguity we need:
namespace boost_swap_impl {
template<class T>
void swap_impl(T& left, T&, right) {
using std::swap;
swap(left, right);
}
}
namespace boost {
namespace swap_adl_barrier {
template<class T>
void swap(T& left, T& right) {
::boost_swap_impl::swap_impl(left, right);
}
}
using swap_adl_barrier::swap;
}
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk