1 // Boost string_algo library compare.hpp header file -------------------------//
3 // Copyright Pavol Droba 2002-2006.
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/ for updates, documentation, and revision history.
11 #ifndef BOOST_STRING_COMPARE_HPP
12 #define BOOST_STRING_COMPARE_HPP
14 #include <boost/algorithm/string/config.hpp>
18 Defines element comparison predicates. Many algorithms in this library can
19 take an additional argument with a predicate used to compare elements.
20 This makes it possible, for instance, to have case insensitive versions
27 // is_equal functor -----------------------------------------------//
31 Standard STL equal_to only handle comparison between arguments
32 of the same type. This is a less restrictive version which wraps operator ==.
38 Compare two operands for equality
40 template< typename T1, typename T2 >
41 bool operator()( const T1& Arg1, const T2& Arg2 ) const
47 //! case insensitive version of is_equal
49 Case insensitive comparison predicate. Comparison is done using
56 \param Loc locales used for comparison
58 is_iequal( const std::locale& Loc=std::locale() ) :
63 Compare two operands. Case is ignored.
65 template< typename T1, typename T2 >
66 bool operator()( const T1& Arg1, const T2& Arg2 ) const
68 #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
69 return std::toupper(Arg1)==std::toupper(Arg2);
71 return std::toupper<T1>(Arg1,m_Loc)==std::toupper<T2>(Arg2,m_Loc);
79 // is_less functor -----------------------------------------------//
83 Convenient version of standard std::less. Operation is templated, therefore it is
84 not required to specify the exact types upon the construction
90 Compare two operands using > operator
92 template< typename T1, typename T2 >
93 bool operator()( const T1& Arg1, const T2& Arg2 ) const
100 //! case insensitive version of is_less
102 Case insensitive comparison predicate. Comparison is done using
109 \param Loc locales used for comparison
111 is_iless( const std::locale& Loc=std::locale() ) :
114 //! Function operator
116 Compare two operands. Case is ignored.
118 template< typename T1, typename T2 >
119 bool operator()( const T1& Arg1, const T2& Arg2 ) const
121 #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
122 return std::toupper(Arg1)<std::toupper(Arg2);
124 return std::toupper<T1>(Arg1,m_Loc)<std::toupper<T2>(Arg2,m_Loc);
132 // is_not_greater functor -----------------------------------------------//
134 //! is_not_greater functor
136 Convenient version of standard std::not_greater_to. Operation is templated, therefore it is
137 not required to specify the exact types upon the construction
139 struct is_not_greater
141 //! Functor operation
143 Compare two operands using > operator
145 template< typename T1, typename T2 >
146 bool operator()( const T1& Arg1, const T2& Arg2 ) const
153 //! case insensitive version of is_not_greater
155 Case insensitive comparison predicate. Comparison is done using
158 struct is_not_igreater
162 \param Loc locales used for comparison
164 is_not_igreater( const std::locale& Loc=std::locale() ) :
167 //! Function operator
169 Compare two operands. Case is ignored.
171 template< typename T1, typename T2 >
172 bool operator()( const T1& Arg1, const T2& Arg2 ) const
174 #if defined(__BORLANDC__) && (__BORLANDC__ >= 0x560) && (__BORLANDC__ <= 0x564) && !defined(_USE_OLD_RW_STL)
175 return std::toupper(Arg1)<=std::toupper(Arg2);
177 return std::toupper<T1>(Arg1,m_Loc)<=std::toupper<T2>(Arg2,m_Loc);
186 } // namespace algorithm
188 // pull names to the boost namespace
189 using algorithm::is_equal;
190 using algorithm::is_iequal;
191 using algorithm::is_less;
192 using algorithm::is_iless;
193 using algorithm::is_not_greater;
194 using algorithm::is_not_igreater;
199 #endif // BOOST_STRING_COMPARE_HPP