From: David Abrahams (dave_at_[hidden])
Date: 2003-10-23 11:51:41
Beman Dawes <bdawes_at_[hidden]> writes:
> At 10:47 AM 10/23/2003, Pavol Droba wrote:
> >On Thu, Oct 23, 2003 at 11:28:38PM +1000, Thorsten Ottosen wrote:
> >> 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 &);
> >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
> >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
> What is the fix? There really needs to be some convenient way to do a
> find_first on a const container. Provide a version that takes begin
> and end iterators? Or is that already done by one of the algorithms in
> detail that you are going to move into boost::algorithm::string?
I'm not sure a fix is needed. The first variant will already match
const containers, as long as they're not temporaries.
template <class T>
int f(T& x);
int const x;
int y = f(x); // T deduced as const int.
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk