Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-11-30 09:45:41


From: "Gennaro Prota" <gennaro_prota_at_[hidden]>
> On Fri, 29 Nov 2002 21:20:14 +0200, "Peter Dimov" <pdimov_at_[hidden]>
> wrote:
>
> >From: "David Abrahams" <dave_at_[hidden]>
>
> >> Now I have to put on my inference hat.
> >>
> >> ...so the use of identity<> assures that we have a non-deduced
> >> context, which causes the explicit template parameter to be required?
> >>
> >> ...I suppose that T has to be copyable for any of these to work, so
> >> there's no problem with taking T by-value.
> >
> >The main reason to prefer this implementation is that it works in
contexts
> >where the conversion is accessible at the point of the implicit_cast
call,
> >but not accessible to the definition of implicit_cast.
>
> Yes, that's the reason for doing conversion directly "on the
> argument". But I think David was asking why not:
>
> template<class T>
> T implicit_cast(T x) { return x; }

Dave answered his own questions above. :-) I just supplied another "..."
item.

> The identity<> trick avoids this possible oversight (well, you must
> explicitly specify 'Base' instead of 'Base&' as destination type to
> make that error! :-). Maybe there are other reasons too, I asked this
> to you in another post. Are there?

No, the only reason is to make T nondeducible.


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