Boost logo

Boost :

From: Thorsten Ottosen (nesotto_at_[hidden])
Date: 2002-11-15 12:47:35


----- Original Message -----
From: "Pavol Droba" <droba_at_[hidden]>

> As there has been an interest I'd like to ask you if such a library should
become a part of boots
> in the future. I'd be happy to hear any opinions and suggestions.
I would always like prefer a library function to writing my own :-)

Ok, so a few comments:

> Trimming:
>
> Iterator trim_begin( Iterator InBegin, Iterator InEnd, const
std::locale& Loc=std::locale() )
> Seq ltrim( const Seq& Input, const std::locale& Loc=std::locale() )
> Seq& ltrim_in( Seq& Input, const std::locale& Loc=std::locale() )
> Seq rtrim( const Seq& Input, const std::locale& Loc=std::locale() )
> Seq& rtrim_in( Seq& Input, const std::locale& Loc=std::locale() )
> Seq trim( const Seq& Input, const std::locale& Loc=std::locale() )
> Seq& trim_in( Seq& Input, const std::locale& Loc=std::locale() )

I would find it more naturally to say

string s = ...;
trim( s );

than to use 'trim_in()'. I think the functions that return a new 'Seq'
should be the special cases, perhaps
just with an appended underscore? Or maybe we should rely on that there is
only one version of trim etc.
and we would do

string s2 = s;
trim( s2 )

instead of

string s2 = trim( s );

? I guess could be considered for the rest of the library and I think It
would simplify usage too, since it
destinguishes between queries and commands. The prototype would then just be

void trim( Seq& input, ... );

> Predicates:
>
> bool start_with(
> InputIterator Begin, InputIterator End,
> SubIterator SubBegin, SubIterator SubEnd,
> BinaryPredicate Comp )
> bool start_with( const Seq1& Input, const Seq2& Prefix, BinaryPredicate
Comp )
> bool end_with( const Seq1& Input, const Seq2& Prefix, BinaryPredicate
Comp )
> bool contains( const Seq1& Input, const Seq2& Prefix, BinaryPredicate
Comp )

I think the names should be 'starts_with' and 'ends_with', right?

BTW, much of the argument passing resembles what will be possible in the new
container algorithms I'm working on.
I guess you might just forward 'Seq.begin()' and 'Seq.end()'. In the
container
algorithms it will be possible to say

int a[] = ...;
pair<iterator,iterator> p = <two iterators denoting a range>
vector<int> v = ...;

for_each( array, print() );
for_each( p, print() );
for_each( v, print() );

What is relevant here is that the code below does not call .begin()/.end(),
but overloaded
freestanding begin() / end() functions. If your code should work with char
arrays or iterator ranges,
then you could benefit from the container algo. begin/end functions
approach. However, there is a big problem, namely that
the container algorithms don't work on eg. VC6/7.

regards

Thorsten Ottosen, AAU


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