Opened 11 years ago

Last modified 11 years ago

#6683 assigned Feature Requests

find family of functions needs const Range1T& Input overloads

Reported by: sairony@… Owned by: Marshall Clow
Milestone: To Be Determined Component: algorithm
Version: Boost 1.48.0 Severity: Problem
Keywords: Cc:

Description

It's cumbersome to have to create named temporaries when searching using these functions. I presume the reason for why Input isn't const is due to the fact that iterator_range<> that's returned can modify Input. In the spirit of std & the rest of boost I propose an overload which returns const_iterator_range<>, which would provide the same functionality as iterator_range<> save for being able to modify the source.

Change History (4)

comment:1 by Marshall Clow, 11 years ago

Status: newassigned

Ok, I'm confused here; the title says "needs const Range1 T& input overloads", but the body talks about having an overload that returns a range.

The search algorithms return a single iterator, not a range. If you look in the file boyer_moore.hpp, there are a set of calls that take ranges. I have to add those calls to the other search algorithms, but I'd appreciate it if you would tell me what you think is lacking there.

comment:2 by anonymous, 11 years ago

Sorry. The signature for lets say find_first is:

template<typename Range1T, typename Range2T> inline iterator_range< BOOST_STRING_TYPENAME range_iterator<Range1T>::type > find_first( Range1T& Input, const Range2T& Search )

As Input isn't const it's not possible to pass rvalues. Now, what I speculate is the reason for why it isn't const ( because it would be natural to assume that merely searching would not need to alter the content ), is because iterator_range<> in this case which is returned from the function gives the caller the opportunity to alter Input indirectly through the iterator_range. So, what I propose is something which would have the following signature instead added as an overload:

template<typename Range1T, typename Range2T> inline const_iterator_range< BOOST_STRING_TYPENAME const_range_iterator<Range1T>::type > find_first( const Range1T& Input, const Range2T& Search )

const_iterator_range in this case would serve the same role that const_iterator does compared to iterator in std.

comment:3 by Marshall Clow, 11 years ago

Ok - my bad. I thought that you were talking about the stuff I just added like boyer_moore_search, etc. You meant the string routines.

So, in addition to

iterator_range<typename range_iterator<Range1T>::type> 
find_first( Range1T& Input, const Range2T& Search);

you want something like:

const_iterator_range<typename const_range_iterator<Range1T>::type> 
find_first( const Range1T& Input, const Range2T& Search);

Basically, when you pass in a constant range, you get back a constant range. is that correct?

comment:4 by anonymous, 11 years ago

Yupp, I want to be able to write for example:

if( !find_first( foo.getName(), bar.getName() ).empty() ) { ... }
Note: See TracTickets for help on using tickets.