From: Pavol Droba (droba_at_[hidden])
Date: 2006-03-27 11:12:53
On Mon, Mar 27, 2006 at 05:47:35PM +0200, Olaf van der Spek wrote:
> 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&?
This is an option, but there are several problem. First there are some older compilers, that do
not support partial template ordering. Also it would multiply number of functions 2 times.
I'm not sure if it is worth it.
> Or should all functions (in all applications and libraries) return
> const string instead of just string?
Well no, you should make a copy and store it into a variable. There is copying there anyway
and if you don't mind returning std::string, you probably don't have problems with performance issues.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk