|
Boost : |
From: Isaac Dupree (isaacdupree_at_[hidden])
Date: 2008-08-15 07:37:15
Niels Dekker - mail address until 2008-12-31 wrote:
> I still wonder if this infinite recursion is a compiler bug as well. But
> anyway, it's clear to me now that there's a good reason to keep
> swap_impl out of the boost namespace. :-)
> And secondly, swap_impl allows the user
> to specify the type of both function arguments by one single template
> argument. While the current boost::swap utility no longer does. For
> example:
it's still possible to get those use-cases as long as it
doesn't involve specializing/overloading swap_impl,
e.g. (please include some explanatory comments!:-)
// various workarounds to avoid compiler bugs that make the
compiler
// find boost::swap before std::swap make us
// - put this outside the boost namespace,
// - use a using-directive rather than a using-declaration,
// - and make boost::swap have two template arguments.
namespace boost_swap_impl{
template<typename T> ...swap_using_adl...
}
// we provide swap_using_adl mostly because boost::swap
// has two template arguments, so it's harder to specify the
type
// as an explicit template argument (but it could also
potentially
// be useful to avoid a bit of runtime slowness in a few
situations).
namespace boost{
using ::boost_swap_impl::swap_using_adl;
// or "using namespace ::boost_swap_impl;" if it's necessary
for some reason
}
Although I couldn't say how strong the use-case is; probably
it's rarely if ever a good idea to specify *that* template
argument explicitly.
The function name already confuses me a little though: why
should a function named boost::swap do ADL when the nearly
equivalent name std::swap doesn't? The name swap_using_adl,
besides that not everyone knows the acronym "adl", makes it
less obvious whether it can find the generic std::swap
implementation (through 'using' not ADL). But maybe the
main function has to be named boost::swap to convince
clueless people to use it instead of std::swap...
-Isaac
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk