[string algorithms] trim, functors

Hello. Could you answer these two questions: 1. Are there trim range algorithms that work with iterators, instead of strings? (I didn't find such). If not, why not to add them? Something like this: http://pastebin.org/146696 2. How can I use, for example, boost::algorithm::is_space() with standard functors? This: boost::not1(boost::algorithm::is_space()) doesn't work. It's enough to specialize boost::unary_traitsboost::algorithm::detail::is_classifiedF, but the fact that 'is_classifiedF' is in 'detail' namespace is a bit confusing. Is it ok to use it? Thanks.

Gaydov Victor a écrit :
Hello. Could you answer these two questions:
1. Are there trim range algorithms that work with iterators, instead of strings? (I didn't find such). If not, why not to add them? Something like this: http://pastebin.org/146696
You found it yourself: boost::algorithm::detail::trim_end I suppose it could become first-class, but there are better solutions, like taking a range and returning a subrange.
2. How can I use, for example, boost::algorithm::is_space() with standard functors? This:
boost::not1(boost::algorithm::is_space())
doesn't work.
What's the error? I guess it doesn't work because it doesn't have a result_type typedef.

Hi, On 11. 4. 2010 19:40, Mathias Gaunard wrote:
Gaydov Victor a écrit :
Hello. Could you answer these two questions:
1. Are there trim range algorithms that work with iterators, instead of strings? (I didn't find such). If not, why not to add them? Something like this: http://pastebin.org/146696
You found it yourself: boost::algorithm::detail::trim_end I suppose it could become first-class, but there are better solutions, like taking a range and returning a subrange.
sub_range was not at hand at the time of writting. I had an idea about to make a kind of trim - finder, but it didn't made into the real implementation.
2. How can I use, for example, boost::algorithm::is_space() with standard functors? This:
boost::not1(boost::algorithm::is_space())
doesn't work.
You are trying to mix apples with oranges. classification predicates in StringAlgo library are not compatible with standard stl functors, because they have templated operator. This is very useful, since you don't have to provide explicit type when passing to an algorithm. The library provides a set of basic combinators. You can simply write (!boost::is_space() || boost::is_digit). Just check the documentation. In addition you can use boost::lambda tools. All classification predicates are compatible with it. Best Regards, Pavol.

On Sun, 2010-04-11 at 21:02 +0200, Pavol Droba wrote:
Hi,
On 11. 4. 2010 19:40, Mathias Gaunard wrote:
Gaydov Victor a écrit :
Hello. Could you answer these two questions:
1. Are there trim range algorithms that work with iterators, instead of strings? (I didn't find such). If not, why not to add them? Something like this: http://pastebin.org/146696
You found it yourself: boost::algorithm::detail::trim_end I suppose it could become first-class, but there are better solutions, like taking a range and returning a subrange.
Is it ok, generally, to expect the code using functions from detail:: to work with future versions of boost?
What's the error? I guess it doesn't work because it doesn't have a result_type typedef.
Yes.
You are trying to mix apples with oranges. classification predicates in StringAlgo library are not compatible with standard stl functors, because they have templated operator. This is very useful, since you don't have to provide explicit type when passing to an algorithm.
The library provides a set of basic combinators. You can simply write (!boost::is_space() || boost::is_digit). Just check the documentation.
Thank you. I understand now.
In addition you can use boost::lambda tools. All classification predicates are compatible with it.
Best Regards, Pavol.

Gaydov Victor a écrit :
On Sun, 2010-04-11 at 21:02 +0200, Pavol Droba wrote:
Hi,
On 11. 4. 2010 19:40, Mathias Gaunard wrote:
Hello. Could you answer these two questions:
1. Are there trim range algorithms that work with iterators, instead of strings? (I didn't find such). If not, why not to add them? Something like this: http://pastebin.org/146696 You found it yourself: boost::algorithm::detail::trim_end I suppose it could become first-class, but there are better solutions,
Gaydov Victor a écrit : like taking a range and returning a subrange.
Is it ok, generally, to expect the code using functions from detail:: to work with future versions of boost?
No. They're implementation details and shouldn't be used.

On Mon, 2010-04-12 at 23:28 +0100, Mathias Gaunard wrote:
Gaydov Victor a écrit :
On Sun, 2010-04-11 at 21:02 +0200, Pavol Droba wrote:
Hi,
On 11. 4. 2010 19:40, Mathias Gaunard wrote:
Hello. Could you answer these two questions:
1. Are there trim range algorithms that work with iterators, instead of strings? (I didn't find such). If not, why not to add them? Something like this: http://pastebin.org/146696 You found it yourself: boost::algorithm::detail::trim_end I suppose it could become first-class, but there are better solutions,
Gaydov Victor a écrit : like taking a range and returning a subrange.
Is it ok, generally, to expect the code using functions from detail:: to work with future versions of boost?
No. They're implementation details and shouldn't be used.
Ok, thanks.
participants (3)
-
Gaydov Victor
-
Mathias Gaunard
-
Pavol Droba