
"Eric Niebler" <eric@boost-consulting.com> writes:
David Abrahams wrote:
Eric Niebler <eric@boost-consulting.com> writes:
Put the overload in an associated namespace of the type. Or for maximum portability, you could put the overload at global scope.
Really? If invoked from within a template, global scope overloads won't be found unless an argument is in the global namespace or the overloads happen to appear before the point of definition of the template.
That was the idea, yes.
If you want a way to make this portable, consider adding a dummy parameter that comes from namespace Boost and asking people to overload there (the Ramey trick).
I'm not sure how this helps on compilers that don't do ADL. This is a macro. BOOST_FOREACH(foo, bar) will expand to something that makes a non-qualified call to boost_foreach_has_cheap_copy *in the context of the BOOST_FOREACH invocation*. This could be any context, in any namespace.
Right. Including from within a template, which could foil lookup in the global namespace.
If I want this to work on compilers that don't do ADL, requiring people to make their overloads visible at global scope seems necessary, but I've likely overlooked something.
namespace boost { template <class T> struct foreach_has_cheap_copy { char (& test(...)) [2]; char test(mpl::true_*); typedef mpl::bool_< sizeof( test( boost_foreach_has_cheap_copy( (T*)0, boost::whatever()) )) > type; }; } Now all compilers will look in namespace boost, whether or not they support ADL. -- Dave Abrahams Boost Consulting www.boost-consulting.com