Boost logo

Boost :

From: Dietmar Kuehl (dietmar_kuehl_at_[hidden])
Date: 2001-01-25 15:42:27


Hi,
Matt Austern wrote:

> Yes, a paper on this subject would be very useful. I don't know of any
> promising solutions other than function template partial specialization
> and overloads with namespace std.

It ain't pretty but if we really need function template partial
specialization
we can emulate it:

  template <typename T>
  struct swap_t {
    static void do(T& t1, T& t2) {
      T tmp = t1;
      t1 = t2;
      t2 = tmp;
    }
  };
  template <typename T>
  void swap(T& t1, T& t2) { swap_t<T>::do(t1, t2); }

Now 'swap_t::do()' is a partial specializable function. It isn't pretty
and
would need a lot of change in the library if this is what is supposed to
be
done but it is doable, without a library change and without allowing users

to add overloads into namespace 'std'.


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