From: Olaf van der Spek (olafvdspek_at_[hidden])
Date: 2006-03-27 10:47:35


On 3/27/06, Pavol Droba <droba_at_[hidden]> wrote:
> > > Thanks, that did the trick. I understand T -> T& isn't valid (although
> > > I don't like that), but why doesn't it automatically do T -> const T&?
> >
>
> Sorry, somehow I thought, that it is solved. The main reason why it works this way is the
> template instantiation process.
> const T& is more specific type then T& and so if T& matches the template signature, it is used.

But in this case it can't be used.

> As I mentioned in another post, this behaviour is implemented in the library intentionaly, since
> it disallows to pass temporary objects as the arguments on the certain places.

I understand, but isn't it possible to have both advantages?
For example, by adding a function that takes const T&?

Or should all functions (in all applications and libraries) return
const string instead of just string?