Boost logo

Boost :

From: Pavol Droba (droba_at_[hidden])
Date: 2003-10-23 09:47:39


On Thu, Oct 23, 2003 at 11:28:38PM +1000, Thorsten Ottosen wrote:
> This is just a small remark regarding the string library and the use of
> container argument algortihms.
>
> Take a look at this function:
>
> template<typename InputContainerT, typename SearchContainerT>
> iterator_range< typename string_algo::container_result_iterator<
> InputContainerT >::type >
> find_first(InputContainerT &, const SearchContainerT &);
>
> There is no overload for a constant first argument, so we can't use an
> rvalue as the first argument even though
> the algorithm does not mutate the argument.
>
> I would say we have to provide
>
> template<typename InputContainerT, typename SearchContainerT>
> iterator_range< typename string_algo::container_const_iterator<
> InputContainerT >::type >
> find_first(const InputContainerT &, const SearchContainerT &);
>
> too for all similar algorithms. I know this will break the implementation on
> compilers without ordering of function templates, but
> then the implementation should fall back on the current one. Did I overlook
> something?
>

Yes you have overlooked one important point. Your second proposed variant
does not make sense and what worse, it is even very dangerous.

find_xxx algorithms return a reference into the input container by the means
of iterators. Using a temporary as an input, you would get an invalid reference as a result.

Returning a reference from a temporary is quite a big error in my opinion.

Regards,

Pavol.


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