Boost logo

Boost :

From: Pavol Droba (droba_at_[hidden])
Date: 2006-03-27 08:18:25

On Mon, Mar 27, 2006 at 02:53:41PM +0200, Olaf van der Spek wrote:
> On 3/15/06, Olaf van der Spek <olafvdspek_at_[hidden]> wrote:
> > > This is because f() is returning a std::string and this is being passed to the RangeT & argument in the split function. Due to C++ rules, performing the T -> T & conversion is invalid. Try defining f() as:
> > >
> > > const std::string f()
> > > {
> > > return "";
> > > }
> >
> > 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.

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.

Specificaly the search algorithms might give unexpected results, since they return a reference
into the input. Same is true for the split algorithm if you use vector<iterator_range> to hold
results. This solution is suggested in the docs as a way to optimize spliting operation.

There were also other reason, but they were mostly of technical character so I won't mention
them here.

Best regards,

Boost list run by bdawes at, gregod at, cpdaniel at, john at