|
Boost : |
From: David Abrahams (abrahams_at_[hidden])
Date: 2000-11-01 13:44:24
----- Original Message -----
From: "Peter Dimov" <pdimov_at_[hidden]>
To: "Griffiths, Alan" <Alan.Griffiths_at_[hidden]>; "'David Abrahams'"
<abrahams_at_[hidden]>
Sent: Wednesday, November 01, 2000 11:57 AM
Subject: Re: Shades, swap or whatever
> > > Eventually, we came across this case posted by Peter Dimov to
> > > c.l.c++.m:
> > >
> > > template <class T> void f(T); // #1
> > > template <> void f<int*>(int*); // #2
> > > template <class T> void f(T*); // #3
> > >
> > > int *x;
> > > f(x); // which one gets called? #3, surprisingly
> >
> > Not that surprising - obvious once someone has contrived the example.
> > (Good work Peter!)
>
> It gets even better if you take advantage of the template argument
> deduction for explicit specializations (something that I feel should be
> disallowed):
>
> template <> void f(int*); // #2
>
> > Presumably this arises from the interaction with overloading.
> > Something like:
> >
> > template <class T> void f(T); // #1
> > template <class T> void f(T*); // #2
> > template <> void f<int*>(int*); // specialising #1 or #2?
>
> #1, obviously. Just substitute T = int*. The story is a bit more
> complicated with partial specializations:
>
> template<class U> void f<U*>(U*);
>
> but still non-ambiguous, I believe.
>
> --
> Peter Dimov
> Multi Media Ltd.
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk