|
Boost Users : |
From: Pavol Droba (droba_at_[hidden])
Date: 2006-03-03 16:11:39
Hi,
On Fri, Mar 03, 2006 at 02:42:14PM +0100, Olaf van der Spek wrote:
> Pavol Droba wrote:
> > The functionality is in cvs. I have added lexicographical_compare (also in i variant)
> > and comparison predicates is_(i)less, is_not_(i)greater.
> >
> > Check it out.
>
> struct is_not_greater
> {
> template< typename T1, typename T2 >
> bool operator()( const T1& Arg1, const T2& Arg2 ) const
> {
> return Arg1>=Arg2;
> }
> };
>
> >=, isn't that is_not_less?
Oh, this is what happens when the regression tests are not complete.
Thanks for notice, you are right of couse. The operator should be reversed.
>
> struct is_iless
> {
> is_iless( const std::locale& Loc=std::locale() ) :
> m_Loc( Loc ) {}
>
> template< typename T1, typename T2 >
> bool operator()( const T1& Arg1, const T2& Arg2 ) const
> {
> #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) &&
> (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
> return std::toupper(Arg1)<std::toupper(Arg2);
> #else
> return std::toupper(Arg1,m_Loc)<std::toupper(Arg2,m_Loc);
> #endif
> }
> }
>
> What about 'A' vs 'a'? Shouldn't 'A' < 'a'?
Hmm, interesting point. But it is not fully correct. Take this example:
str1="Aab"
str2="aAa"
in my opinion following should hold str1>str2, however if 'A' < 'a' then the comparison
would yield the oposite.
Such a comparison make sense only if both strings are equal (except the case).
Current implementation of ilexicographical_compare does not perform this extra step
since it tries to be compliant with std::lexicographical_compare.
>
> I'm also wondering how expensive std::toupper is. Would it make sense to
> do a == first to avoid the std::toupper calls in certain cases?
>
Well, this is a more complicated point. Small optimization you are proposing
does not really make any difference. I have read a paper (I don't remember where),
where author proposes to cache the results of tolower during the comparison.
This approch is complex and it effectively disables the possibility to
use user-defined comparison predicates. So I decided to go for a simple solution.
Best regards,
Pavol
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net