From: Pavol Droba (droba_at_[hidden])
Date: 2002-11-18 03:25:38
On Sun, Nov 17, 2002 at 05:36:35PM +0100, Gennaro Prota wrote:
> Hi Pavol, I haven't been following this thread so please forgive me if
> I'm just pointing out something stupid, or problems that you already
> know. I had a quick glance at the library and I'm a little confused at
> what is its scope. For instance the "is space" generalization makes in
> fact functions like trim() and the like generic algorithms that remove
> a given element (or its equivalents) from the beginning and the end of
> a sequence. At this point either you make clear that the library isn't
> specifically a "string library" or that isspaceF is actually a generic
> functor that can test whatever charT you like (and change its name at
You are probably right that some ideas are confusing without explanation.
It should all go into documentation, but there no such a thing right now,
because of very preliminary version of the lib.
Idea of the string lib is to provide a set of string related algorithms,
but not necessary working only with basic_string. So you can use most of
the algorithms on any compatible sequence. It makes it easy for instance
to compine basic_string<char> with vector<int> in one function call.
This makes sense for example if you are trying to call som C-style API
for which vector is much better variant then basic_string.
> > 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() )
> This is in accordance with my confusion :-) What has a locale to do
> with a generic sequence? If I imagine a generalized trim function
> (say, a function that removes all the odd numbers from the beginning
> and the end of a vector<int>) I imagine, type requirements about the
> iterators etc. aside, signatures like:
> template <typename Iterator, typename Elem>
> Iterator trim (Iterator start, Iterator end, Elem const &);
> template <typename Iterator, typename Pred>
> Iterator trim (Iterator start, Iterator end, Pred pred);
> It seems that either the design is seriously flawed or (more likely)
> I'm missing something.
I have already a plan for changing this. The reason for locale paramter is that
most obvious scenario for using trim it to remove spaces. And term "space" is
locale specific. Locales are not working above a generic sequence, but with every single element,
so if you try vector<char> everything is perfectly correct.
What I want to do in the future is to change default signature of trim to something
like you're proposing. There will be a variant with predicate and a set of standard
predicates. This way the locale stuff will be moved out to the predicate and will
not confuse you any more, I hope :)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk