Boost logo

Boost Users :

From: Terry G (tjgolubi_at_[hidden])
Date: 2008-08-17 17:34:06


I notice that Boost now has it's own boost::swap and that it has had recent
trouble before the 1.36 release.
How should a user/developer like me implement a custom swap so that users
get the benefit of my::swap, then boost::swap, and finally std::swap without
putting too much burden on my user.

So I have three questions. (1) How should user-code use boost:swap? (2)
How should boost-developers use boost::swap()?
(3) How should non-boost-developers provide swap()?

Consider my motivating (to me) example...

Let's say I have a move library that works, hypothetically.

namespace my {

// These are defined and actually work, hypothetically.
template <class T> struct is_moveable;
template <class T> struct move_from { };
template <class T>T& move(T& x);

template <class T>
void swap(T& x, T& y) {
  T tmp = move(x);
  x = move(y);
  y = move(tmp);
} // swap

} // namespace my

If the user does this...

using namespace std;
using namespace boost;
using namespace my;

And then somewhere in his code...

   HisType a = MakeA();
   HisType b = MakeB();
   swap(a, b); // Unqualified? Or should the user specify a namespace?
Which one?

What I wish would happen would be...

   If the user has his own swap(HisType, HisType) invoke that.
  Otherwise, if HisType.swap() exists, then use that.
   Otherwise, use my::swap() if its "better" than boost::swap
  Otherwise, use boost::swap(), if its "better" than std::swap
  Otherwise, just use std::swap().

Sorry about all the ambiguity. But that's the real problem, isn't it?

terry


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net