Boost logo

Boost :

From: Niels Dekker - mail address until 2008-12-31 (nd_mail_address_valid_until_2008-12-31_at_[hidden])
Date: 2008-07-26 13:34:13


Steven Watanabe wrote:
> Adding overloads to namespace boost is not guaranteed to work either.
>
> template<class T>
> void foo(T& t1, T&t2) {
> boost::swap(t1, t2);
> }
>
> class X {};
>
> namespace boost {
> void swap(X&, X&); // not found by foo.
> }

Thanks, Steven! So the user should make sure that all of her custom
boost swap overloads are declared, /before/ including any function that
actually calls boost::swap... right?

  class X; // forward declaration.

  namespace boost {
    void swap(X&, X&); // forward declaration.
  }

  template<class T>
  void foo(T& t1, T&t2) {
    boost::swap(t1, t2); // should find swap(X&, X&), right?
  }

  class X {};

David Abrahams wrote:
> Niels is talking about compilers with bugs, though. I don't know
> if this would be a possible workaround for any of those compilers
> or not, but several compilers do all name lookup in phase 2 so
> this stands a chance of working.

We could add more unit tests, to see if it would work for those specific
compilers. But only if we'd agree that there's no objection against
having end-users adding their overloads to the boost namespace... I
tend to think that it's "morally right" to have the end-user provide
template specializations of boost function templates, but I'm not sure
about overloads... what do you think?

>> http://www.boost.org/development/tests/trunk/developer/utility-swap_.html
>> ADL failures appear to occur for GCC 3.3.1 (PathScale), Intel C++ 8.1,
>> MSVC 7.1 (2003), and Borland (up to 5.9.3).
>
> I just looked into some of these; it doesn't look like you need to do
> anything for msvc-7.1 and gcc-3.1.1 other than to place your class in a
> namespace other than the global one.

gcc-3.1.1 can indeed find the custom swap by ADL when the user's class
is in her own namespace (other than the global one). As you see,
"specialized_in_other" succeeds for gcc-3.1.1. Unfortunately this is
not the case for msvc-7.1: msvc-7.1 fails on both
"specialized_in_global" and "specialized_in_other". It just doesn't
seem to do ADL on template arguments. :-(

Thanks for your replies so far,

  Kind regards, Niels


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk