Boost logo

Boost :

From: Dave Abrahams (abrahams_at_[hidden])
Date: 2000-01-18 20:33:25


Valentin wrote.
>> I'm not absolutely sure what the policy ought to be for generic code, though
>> I lean toward the high-labor, low-intrusiveness approach (option 2).
>
> Since there is no such thing a function partial specialization,
> option 2 is unusable for any kind of generic code.

Of course. I must have been temporarily insane. Why there is no function
partial specialization is a mystery to me, but that's beside the point.

I disagree that option 2 is unusable for generic code, but it makes for an
even greater amount of labor: to write generic code using it, you simply
have to avoid using free functions at all. Instead of

    std::swap(a, b)

you must write:

    std::swapper<A>()(a, b)

This is starting to get ridiculous in light of the lack of a typeof
operator.

Suppose std::swap were implemented thusly:

namespace std
{
    template <class A> struct swapper {
        void operator()(A& x, A& y) { A tmp(x); x = y; y = tmp; }
    };
    template <class A> void swap(A& x, A& y) { swapper<A>()(x, y); }
}

Then we could partially specialize swapper to control the implementation of
swap. It's ugly, and I don't like it.

In absence of such awful hacks:
Full specialization gets us part of the way there, but is useless for
specializing w.r.t. templates (e.g. a swap for shared_ptr).

I think function partial specialization for templates can be roughly
approximated with the B&N trick, and the only obstacle is the prohibition
against overloading in namespace std... but after trying to write it once it
is probably too cumbersome to be worth it.

> I understand that deserving a name in all namespaces isn't
> pleasant.

I think you meant "reserving".

Ick. It looks like we're stuck with koenig lookup then.

:(


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