Compare commits

...

34 Commits

Author SHA1 Message Date
e572ab4d8f This commit was manufactured by cvs2svn to create tag
'Version_1_32_0'.

[SVN r26264]
2004-11-19 19:19:18 +00:00
eaa5a47847 fix www.boost.org links
[SVN r26093]
2004-11-02 23:30:52 +00:00
af2d4c487d fix broken links
[SVN r25955]
2004-10-30 04:34:07 +00:00
f2fa1d3b7a forgotten "using" added
regex_finder and regex_formatter pulled to the boost namespace


[SVN r25878]
2004-10-26 21:45:49 +00:00
322c1f2900 This commit was manufactured by cvs2svn to create branch 'RC_1_32_0'.
[SVN r25797]
2004-10-20 08:26:43 +00:00
77ae41a18a Invalid include fixed
[SVN r25672]
2004-10-11 18:30:21 +00:00
5d1448f3ac unused parameter warning removal
[SVN r25671]
2004-10-11 18:28:21 +00:00
0a0facd7c7 c++boost.gif -> boost.png replacement
[SVN r25573]
2004-10-05 15:45:52 +00:00
053cc53eea workaround for a problem of GCC 2.95 with local scope using directives
[SVN r25077]
2004-09-14 07:15:51 +00:00
54ac5bebd3 Fix stylesheet link
[SVN r25048]
2004-09-13 15:44:23 +00:00
3542f868a0 Problematic std::distance removed
[SVN r25008]
2004-09-10 13:23:32 +00:00
4d346d43ad Explicit namespace qualification added to std::distance calls
(hoping to resolve vc7 problem)


[SVN r24953]
2004-09-07 10:30:41 +00:00
56862b0bcc merge new MPL version from 'mplbook' branch
[SVN r24874]
2004-09-02 15:41:37 +00:00
108365abe7 Attempt to fix "Empty sequence after erase problem" reported by vc8.0
[SVN r24835]
2004-08-31 07:43:02 +00:00
fa09dddc75 More general fix for vc8.0
[SVN r24765]
2004-08-26 16:03:48 +00:00
6fb58192d7 Fix fix
[SVN r24678]
2004-08-23 18:52:36 +00:00
792b4eae88 Attempt to fix iterator problem detected by VC8.0
[SVN r24677]
2004-08-23 18:46:28 +00:00
a23ae6316f Licence from authors of previous versions changed to BSL (according to blanket-permission.txt)
[SVN r24479]
2004-08-14 23:02:20 +00:00
5063e96367 Work around problems with the CW8 preprocessor by not using BOOST_PP.
[SVN r24326]
2004-08-06 15:50:35 +00:00
5221839b71 tabs removed
[SVN r24272]
2004-08-03 17:28:02 +00:00
ba00033cbf Addtional credits
[SVN r24271]
2004-08-03 17:23:43 +00:00
047a42934d Incorrect examples fixed
[SVN r24270]
2004-08-03 17:09:28 +00:00
747b4e17cc Small fix to make vacpp happy
[SVN r24245]
2004-08-02 10:32:37 +00:00
4c0efd3d1a Small optimization of equal() functions.
[SVN r24185]
2004-07-30 07:46:11 +00:00
67f7273ab3 replace_test() function splitted to smaller chuncks.
[SVN r24184]
2004-07-30 07:44:43 +00:00
ce6a647dd0 Work-around for CW8 problems with static_cast of references to templates.
[SVN r24178]
2004-07-30 04:32:43 +00:00
246794db2a Added copyright notices.
[SVN r24171]
2004-07-29 20:27:38 +00:00
325fa64dc3 Licence fixed
[SVN r24152]
2004-07-29 07:38:27 +00:00
33122fefa7 Fix tabs in file.
[SVN r24039]
2004-07-25 15:09:51 +00:00
4b3118ed2b Added BOOST_EXPLICIT_TEMPLATE_TYPE(Value) to fix MSVC (thanks to Joaquin
Munoz)


[SVN r23998]
2004-07-23 17:17:37 +00:00
85e0e920bf Removed char* name and dependence on iostream, not appropriate for test
suite (relic of example and debugging).


[SVN r23996]
2004-07-23 16:13:43 +00:00
483bc9e231 replaced tuple::get memfun with equivalent global function so as to cover MSVC
[SVN r23956]
2004-07-22 13:43:01 +00:00
643c793f3b added a fix for compilers without PTS
[SVN r23955]
2004-07-22 13:39:25 +00:00
825468bc42 added an #include for Boost.Ref
[SVN r23954]
2004-07-22 13:37:47 +00:00
25 changed files with 334 additions and 257 deletions

View File

@ -26,6 +26,7 @@
*/
#include <boost/tuple/tuple.hpp> // for using pairs with boost::cref
#include <boost/ref.hpp>
namespace boost {

View File

@ -64,52 +64,52 @@ namespace boost {
// if only one element
ForwardIter second = first; ++second;
if (second == last)
return std::make_pair(min_result, max_result);
return std::make_pair(min_result, max_result);
// treat first pair separately (only one comparison for first two elements)
ForwardIter potential_min_result = last;
if (comp(first, second))
max_result = second;
max_result = second;
else {
min_result = second;
potential_min_result = first;
min_result = second;
potential_min_result = first;
}
// then each element by pairs, with at most 3 comparisons per pair
first = ++second; if (first != last) ++second;
while (second != last) {
if (comp(first, second)) {
if (comp(first, min_result)) {
min_result = first;
potential_min_result = last;
}
if (comp(max_result, second))
max_result = second;
} else {
if (comp(second, min_result)) {
min_result = second;
potential_min_result = first;
}
if (comp(max_result, first))
max_result = first;
}
first = ++second;
if (first != last) ++second;
if (comp(first, second)) {
if (comp(first, min_result)) {
min_result = first;
potential_min_result = last;
}
if (comp(max_result, second))
max_result = second;
} else {
if (comp(second, min_result)) {
min_result = second;
potential_min_result = first;
}
if (comp(max_result, first))
max_result = first;
}
first = ++second;
if (first != last) ++second;
}
// if odd number of elements, treat last element
if (first != last) { // odd number of elements
if (comp(first, min_result))
min_result = first, potential_min_result = last;
else if (comp(max_result, first))
max_result = first;
if (comp(first, min_result))
min_result = first, potential_min_result = last;
else if (comp(max_result, first))
max_result = first;
}
// resolve min_result being incorrect with one extra comparison
// (in which case potential_min_result is necessarily the correct result)
if (potential_min_result != last
&& !comp(min_result, potential_min_result))
min_result = potential_min_result;
&& !comp(min_result, potential_min_result))
min_result = potential_min_result;
return std::make_pair(min_result,max_result);
}
@ -352,23 +352,23 @@ namespace boost {
while (second != last) {
if (!comp(second, first)) {
if (comp(first, min_result))
min_result = first;
min_result = first;
if (!comp(second, max_result))
max_result = second;
max_result = second;
} else {
if (comp(second, min_result))
min_result = second;
min_result = second;
if (!comp(first, max_result))
max_result = first;
max_result = first;
}
first = ++second; if (first != last) ++second;
}
if (first != last) {
if (comp(first, min_result))
min_result = first;
min_result = first;
else if (!comp(first, max_result))
max_result = first;
max_result = first;
}
return std::make_pair(min_result, max_result);
@ -448,15 +448,15 @@ namespace boost {
min_result = first;
if (!comp(second, max_result)) {
max_result = second;
potential_max_result = last;
}
potential_max_result = last;
}
} else {
if (!comp(min_result, second))
min_result = second;
if (!comp(first, max_result)) {
max_result = first;
potential_max_result = second;
}
potential_max_result = second;
}
}
first = ++second;
if (first != last) ++second;
@ -467,7 +467,7 @@ namespace boost {
min_result = first;
if (!comp(first, max_result)) {
max_result = first;
potential_max_result = last;
potential_max_result = last;
}
}

View File

@ -1,9 +1,9 @@
// Boost string_algo library string_algo.hpp header file ---------------------------//
// (C) Copyright Pavol Droba 2002-2003. Permission to copy, use, modify, sell and
// distribute this software is granted provided this copyright notice appears
// in all copies. This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Copyright Pavol Droba 2002-2004. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.

View File

@ -235,9 +235,12 @@ namespace boost {
const predicate_facade<Pred1T>& Pred1,
const predicate_facade<Pred2T>& Pred2 )
{
// Doing the static_cast with the pointer instead of the reference
// is a workaround for some compilers which have problems with
// static_cast's of template references, i.e. CW8. /grafik/
return detail::pred_andF<Pred1T,Pred2T>(
static_cast<const Pred1T&>(Pred1),
static_cast<const Pred2T&>(Pred2) );
*static_cast<const Pred1T*>(&Pred1),
*static_cast<const Pred2T*>(&Pred2) );
}
//! predicate 'or' composition predicate
@ -256,9 +259,12 @@ namespace boost {
const predicate_facade<Pred1T>& Pred1,
const predicate_facade<Pred2T>& Pred2 )
{
// Doing the static_cast with the pointer instead of the reference
// is a workaround for some compilers which have problems with
// static_cast's of template references, i.e. CW8. /grafik/
return detail::pred_orF<Pred1T,Pred2T>(
static_cast<const Pred1T&>(Pred1),
static_cast<const Pred2T&>(Pred2));
*static_cast<const Pred1T*>(&Pred1),
*static_cast<const Pred2T*>(&Pred2));
}
//! predicate negation operator
@ -273,7 +279,10 @@ namespace boost {
inline detail::pred_notF<PredT>
operator!( const predicate_facade<PredT>& Pred )
{
return detail::pred_notF<PredT>(static_cast<const PredT&>(Pred));
// Doing the static_cast with the pointer instead of the reference
// is a workaround for some compilers which have problems with
// static_cast's of template references, i.e. CW8. /grafik/
return detail::pred_notF<PredT>(*static_cast<const PredT*>(&Pred));
}
} // namespace algorithm

View File

@ -5,17 +5,15 @@
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// (C) Copyright Thorsten Ottosen 2002-2003. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
// (C) Copyright Thorsten Ottosen 2002-2003. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// (C) Copyright Jeremy Siek 2001. Permission to copy, use, modify,
// sell and distribute this software is granted provided this
// copyright notice appears in all copies. This software is provided
// "as is" without express or implied warranty, and with no claim as
// to its suitability for any purpose.
// (C) Copyright Jeremy Siek 2001. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Original idea of container traits was proposed by Jeremy Siek and
// Thorsten Ottosen. This implementation is lightweighted version
@ -27,7 +25,7 @@
#include <boost/algorithm/string/config.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/is_pointer.hpp>
#include <boost/mpl/apply_if.hpp>
#include <boost/mpl/eval_if.hpp>
// Implementation
#include <boost/algorithm/string/detail/collection_traits.hpp>
@ -76,13 +74,13 @@ namespace boost {
struct collection_traits
{
private:
typedef BOOST_STRING_TYPENAME ::boost::mpl::apply_if<
typedef BOOST_STRING_TYPENAME ::boost::mpl::eval_if<
::boost::algorithm::detail::is_pair<T>,
detail::pair_container_traits_selector<T>,
BOOST_STRING_TYPENAME ::boost::mpl::apply_if<
BOOST_STRING_TYPENAME ::boost::mpl::eval_if<
::boost::is_array<T>,
detail::array_container_traits_selector<T>,
BOOST_STRING_TYPENAME ::boost::mpl::apply_if<
BOOST_STRING_TYPENAME ::boost::mpl::eval_if<
::boost::is_pointer<T>,
detail::pointer_container_traits_selector<T>,
detail::default_container_traits_selector<T>

View File

@ -19,7 +19,7 @@
#include <boost/type_traits/is_convertible.hpp>
#include <boost/type_traits/remove_pointer.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/mpl/apply_if.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/fold.hpp>
@ -241,13 +241,13 @@ namespace boost {
struct array_traits_cv_selector
{
typedef BOOST_STRING_TYPENAME
::boost::mpl::apply_if<
::boost::mpl::eval_if<
::boost::is_convertible<T,BaseT*>,
array_traits_impl_selector<T,BaseT>,
::boost::mpl::apply_if<
::boost::mpl::eval_if<
::boost::is_convertible<T,const BaseT*>,
array_traits_impl_selector<T, const BaseT>,
::boost::mpl::apply_if<
::boost::mpl::eval_if<
::boost::is_convertible<T, volatile BaseT*>,
array_traits_impl_selector<T, volatile BaseT>,
array_traits_impl_selector<T, const volatile BaseT>
@ -263,7 +263,7 @@ namespace boost {
struct apply
{
typedef BOOST_STRING_TYPENAME
::boost::mpl::apply_if<
::boost::mpl::eval_if<
::boost::is_convertible<T,const volatile T2*>,
array_traits_cv_selector<T,T2>,
::boost::mpl::identity<T1> >::type type;

View File

@ -174,7 +174,7 @@ namespace boost {
typename FormatResultT >
inline void find_format_impl2(
InputT& Input,
FinderT Finder,
FinderT,
FormatterT Formatter,
const FindResultT& FindResult,
const FormatResultT& FormatResult)

View File

@ -123,6 +123,7 @@ namespace boost {
ForwardIteratorT InsertIt,
ForwardIteratorT SegmentBegin,
ForwardIteratorT SegmentEnd )
{
// Call replace to do the job
replace( Input, InsertIt, SegmentBegin, Storage );

View File

@ -110,7 +110,14 @@ namespace boost {
BOOST_STRING_TYPENAME InputT::iterator At=Input.erase( From, To );
if ( Begin!=End )
{
Input.insert( At, Begin, End );
if(!Input.empty())
{
Input.insert( At, Begin, End );
}
else
{
Input.insert( Input.begin(), Begin, End );
}
}
}
};
@ -172,7 +179,14 @@ namespace boost {
BOOST_STRING_TYPENAME InputT::iterator To,
const InsertT& Insert )
{
replace( Input, From, To, begin(Insert), end(Insert) );
if(From!=To)
{
replace( Input, From, To, begin(Insert), end(Insert) );
}
else
{
insert( Input, From, begin(Insert), end(Insert) );
}
}
} // namespace detail

View File

@ -136,7 +136,10 @@ namespace boost {
// comparison
bool equal( const find_iterator& Other ) const
{
return eof() || Other.eof() ? eof() == Other.eof() :
bool bEof=eof();
bool bOtherEof=Other.eof();
return bEof || bOtherEof ? bEof==bOtherEof :
(
m_Match==Other.m_Match &&
m_End==Other.m_End
@ -297,7 +300,10 @@ namespace boost {
// comparison
bool equal( const split_iterator& Other ) const
{
return eof() || Other.eof() ? eof() == Other.eof() :
bool bEof=eof();
bool bOtherEof=Other.eof();
return bEof || bOtherEof ? bEof==bOtherEof :
(
m_Match==Other.m_Match &&
m_Next==Other.m_Next &&

View File

@ -72,7 +72,7 @@ namespace boost {
template<typename CollectionT>
inline detail::empty_formatF<
BOOST_STRING_TYPENAME value_type_of<CollectionT>::type>
empty_formatter(const CollectionT& Input)
empty_formatter(const CollectionT&)
{
return detail::empty_formatF<
BOOST_STRING_TYPENAME value_type_of<CollectionT>::type>();

View File

@ -208,7 +208,9 @@ namespace boost {
return true;
}
return (first_finder(Test,Comp)(begin(Input), end(Input)));
// Use the temporary variable to make VACPP happy
bool bResult=(first_finder(Test,Comp)(begin(Input), end(Input)));
return bResult;
}
//! 'Contains' predicate

View File

@ -78,6 +78,11 @@ namespace boost {
}
} // namespace algorithm
// pull the names to the boost namespace
using algorithm::regex_finder;
using algorithm::regex_formatter;
} // namespace boost

View File

@ -1,9 +1,9 @@
// Boost string_algo library string_algo.hpp header file ---------------------------//
// Boost string_algo library string_regex.hpp header file ---------------------------//
// (C) Copyright Pavol Droba 2002-2003. Permission to copy, use, modify, sell and
// distribute this software is granted provided this copyright notice appears
// in all copies. This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
// Copyright Pavol Droba 2002-2004. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// See http://www.boost.org for updates, documentation, and revision history.
@ -16,7 +16,7 @@
*/
#include <boost/regex.hpp>
#include <boost/string_algo.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/regex.hpp>
#endif // BOOST_STRING_ALGO_REGEX_HPP

View File

@ -1,3 +1,8 @@
// (C) Copyright Herve Bronnimann 2004.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <list>
#include <algorithm>
#include <cstdlib>

View File

@ -1,3 +1,8 @@
// (C) Copyright Herve Bronnimann 2004.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <utility>
#include <functional>
#include <algorithm>
@ -55,14 +60,14 @@ int repeats = 10;
for (int i=0; i<repeats; ++i) { cmd ; } \
std::cout << " " << std::setprecision(4) \
<< (double)n*repeats/t.elapsed()/1.0E6 \
<< "M items/sec " << cmdname << "\n"
<< "M items/sec " << cmdname << "\n"
#define CTIMER( n, cmd , cmdname, count, opt ) \
t.restart(); lc.reset(); \
for (int i=0; i<repeats; ++i) { cmd ; } \
std::cout << " " << std::setprecision(4) \
<< (double)n*repeats/t.elapsed()/1.0E6 \
<< "M items/sec " << cmdname \
<< "M items/sec " << cmdname \
<< " ("<< (count)/repeats << " vs " << opt << ")\n"
template <class CIterator>
@ -99,10 +104,10 @@ void test_minmax_element(CIterator first, CIterator last, int n, char* name)
TIMER( n, boost::max_element_if(first, last, pred),
"boost::max_element_if" << name << "");
TIMER( n, std::min_element(boost::make_filter_iterator(first, last, pred),
boost::make_filter_iterator(last, last, pred)),
boost::make_filter_iterator(last, last, pred)),
"std::min_element_with_filter_iterator" << name << "");
TIMER( n, std::max_element(boost::make_filter_iterator(first, last, pred),
boost::make_filter_iterator(last, last, pred)),
boost::make_filter_iterator(last, last, pred)),
"std::max_element_if_with_filter_iterator" << name << "");
#undef pred

View File

@ -1,7 +1,7 @@
<!DOCTYPE html public "-//w3c//dtd html 4.0 transitional//en">
<HTML>
<HEAD>
<LINK REL="stylesheet" TYPE="text/css" HREF="../../../../boost.css">
<LINK REL="stylesheet" TYPE="text/css" HREF="../../../boost.css">
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META name="GENERATOR" content="Mozilla/4.77 [en] (X11; U; Linux 2.2.19 i686) [Netscape]">
<META name="Author" content="Herve Bronnimann">
@ -10,8 +10,8 @@
</HEAD>
<body text="#000000" bgcolor="#FFFFFF" link="#0000EE" vlink="#551A8B" alink="#FF0000">
<h2><img src="../../../c++boost.gif" WIDTH="276" HEIGHT="86">Header &lt;<A
HREF="../../../../boost/minmax.hpp">boost/algorithm/minmax.hpp</A>&gt; </H2>
<h2><img src="../../../boost.png" WIDTH="276" HEIGHT="86">Header &lt;<A
HREF="../../../boost/algorithm/minmax.hpp">boost/algorithm/minmax.hpp</A>&gt; </H2>
<quote>
<b>
@ -71,7 +71,7 @@ but I ruled against that (see <a href="#no-policy">rationale</a>).
</p>
<p>If you are interested about
<a href="minmax_benchs.html">performance</a>,
<a href="doc/minmax_benchs.html">performance</a>,
you will see that <tt>minmax_element</tt> is just slightly less efficient
than a single <tt>min_element</tt> or <tt>max_element</tt>, and thus
twice as efficient as two separate calls to <tt>min_element</tt> and
@ -301,8 +301,8 @@ the library under
<a name="notes">
<h3>
Notes</h3>
<a NAME="Note1"></a><a href="#Note1">[1]</a>We do not support
idioms such as <tt><a href="http://www.boost.org/libs/tuple/doc/tuple_users_guide.html#tiers">tie</a>(a,b)=minmax(a,b)</tt>
<a NAME="Note1"></a><a href="#Note1">[1]</a> We do not support
idioms such as <tt><a href="../../tuple/doc/tuple_users_guide.html#tiers">tie</a>(a,b)=minmax(a,b)</tt>
to order two elements <tt>a</tt>, <tt>b</tt>, although this would have
the desired effect if we returned a reference instead of a constant
reference. The reason is that two unnecessary assignments are

View File

@ -1,3 +1,8 @@
// (C) Copyright Herve Bronnimann 2004.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <utility>
#include <functional>
#include <algorithm>
@ -6,8 +11,8 @@
#include <vector>
#include <list>
#include <set>
#include <iostream>
#include <boost/config.hpp> /* prevents some nasty warns in MSVC */
#include <boost/algorithm/minmax_element.hpp>
#include <boost/test/included/test_exec_monitor.hpp>
#include <boost/iterator/reverse_iterator.hpp>
@ -15,7 +20,6 @@
class custom {
int m_x;
friend bool operator<(custom const& x, custom const& y);
friend std::ostream& operator<<(std::ostream& str, custom const& x);
public:
explicit custom(int x = 0) : m_x(x) {}
custom(custom const& y) : m_x(y.m_x) {}
@ -28,11 +32,7 @@ bool operator< (custom const& x, custom const& y)
return x.m_x < y.m_x;
}
std::ostream& operator<<(std::ostream& str, custom const& x)
{
str << x.m_x;
return str;
}
BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION(custom)
namespace std {
@ -179,56 +179,49 @@ void test_minmax(CIterator first, CIterator last, int n)
}
template <class Container, class Iterator, class Value>
void test_container(Iterator first, Iterator last, int n, Container* dummy = 0 )
void test_container(Iterator first, Iterator last, int n,
Container* dummy = 0
BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Value) )
{
Container c(first, last);
test_minmax(c.begin(), c.end(), n);
}
template <class Iterator>
void test_range(Iterator first, Iterator last, int n, char* /* name */)
void test_range(Iterator first, Iterator last, int n)
{
typedef typename std::iterator_traits<Iterator>::value_type Value;
// Test various containers with these values
// std::cout << " vector<" << name << ">...";
test_container< std::vector<Value>, Iterator, Value >(first, last, n);
// std::cout << " list<" << name << ">...";
test_container< std::list<Value>, Iterator, Value >(first, last, n);
// std::cout << " set<" << name << ">...";
test_container< std::set<Value>, Iterator, Value >(first, last, n);
// std::cout << "\n";
}
template <class Value>
void test(int n, char* name)
void test(int n BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Value))
{
// Populate test vector with identical values
// std::cout << " Identical values... ";
std::vector<Value> test_vector(n, Value(1));
typename std::vector<Value>::iterator first( test_vector.begin() );
typename std::vector<Value>::iterator last( test_vector.end() );
test_range(first, last, n, name);
test_range(first, last, n);
// Populate test vector with two values
// std::cout << " Two distinct values...";
typename std::vector<Value>::iterator middle( first + n/2 );
std::fill(middle, last, Value(2));
test_range(first, last, n, name);
test_range(first, last, n);
// Populate test vector with increasing values
// std::cout << " Increasing values... ";
std::accumulate(first, last, Value(0));
test_range(first, last, n, name);
test_range(first, last, n);
// Populate test vector with decreasing values
// std::cout << " Decreasing values... ";
std::reverse(first, last);
test_range(first, last, n, name);
test_range(first, last, n);
// Populate test vector with random values
// std::cout << " Random values... ";
std::random_shuffle(first, last);
test_range(first, last, n, name);
test_range(first, last, n);
}
int test_main( int argc, char* argv[] )
@ -236,8 +229,8 @@ int test_main( int argc, char* argv[] )
int n = 100;
if (argc > 1) n = atoi(argv[1]);
test<int>(n, "builtin");
test<custom>(n, "custom ");
test<int>(n);
test<custom>(n);
return 0;
}

View File

@ -1,7 +1,12 @@
// (C) Copyright Herve Bronnimann 2004.
// Use, modification and distribution are subject to the
// Boost Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <utility>
#include <functional>
#include <iostream>
#include <boost/config.hpp>
#include <boost/algorithm/minmax.hpp>
#include <boost/test/included/test_exec_monitor.hpp>
@ -39,41 +44,42 @@ private:
int& m_counter;
};
using namespace boost;
template <class Value>
void test(char*)
void test(BOOST_EXPLICIT_TEMPLATE_TYPE(Value))
{
using namespace boost;
Value zero(0), one(1);
int counter = 0;
less_count<Value> lc(counter);
// Test functionality
tuple<Value const&, Value const&> result1 = minmax(zero, one);
BOOST_CHECK_EQUAL( result1.get<0>(), zero );
BOOST_CHECK_EQUAL( result1.get<1>(), one );
BOOST_CHECK_EQUAL( get<0>(result1), zero );
BOOST_CHECK_EQUAL( get<1>(result1), one );
tuple<Value const&, Value const&> result2 = minmax(one, zero);
BOOST_CHECK_EQUAL( result2.get<0>(), zero );
BOOST_CHECK_EQUAL( result2.get<1>(), one );
BOOST_CHECK_EQUAL( get<0>(result2), zero );
BOOST_CHECK_EQUAL( get<1>(result2), one );
// Test functionality and number of comparisons
lc.reset();
tuple<Value const&, Value const&> result3 = minmax(zero, one, lc );
BOOST_CHECK_EQUAL( result3.get<0>(), zero );
BOOST_CHECK_EQUAL( result3.get<1>(), one );
BOOST_CHECK_EQUAL( get<0>(result3), zero );
BOOST_CHECK_EQUAL( get<1>(result3), one );
BOOST_CHECK_EQUAL( counter, 1 );
lc.reset();
tuple<Value const&, Value const&> result4 = minmax(one, zero, lc );
BOOST_CHECK_EQUAL( result4.get<0>(), zero );
BOOST_CHECK_EQUAL( result4.get<1>(), one );
BOOST_CHECK_EQUAL( get<0>(result4), zero );
BOOST_CHECK_EQUAL( get<1>(result4), one );
BOOST_CHECK_EQUAL( counter, 1);
}
int test_main( int , char* [] )
{
test<int>("builtin");
test<custom>("custom ");
test<int>(); // ("builtin");
test<custom>(); // ("custom ");
return 0;
}

View File

@ -11,5 +11,9 @@
in the review process, namely David Abrahams, Daniel Frey, Beman Dawes, John Maddock, David B.Held, Pavel Vozenilek
and many other.
</para>
<para>
Additional thanks go to Stefan Slapeta and Toon Knapen, who have been very resourceful in solving various
portability issues.
</para>
</section>
</section>

View File

@ -1,4 +1,4 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title> Concepts and External Concepts </title><meta http-equiv="Content-Type"content="text/html; charset=iso-8859-1"></head> <body><table ><tr ><td ><img src="cboost.gif" width="100%" border="0"></td><td ><h1 >Concepts and External Concepts</h1></td></tr></table><p >Generic programming in C++ is characterized by the use of function and class templates where
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title> Concepts and External Concepts </title><meta http-equiv="Content-Type"content="text/html; charset=iso-8859-1"></head> <body><table ><tr ><td ><img src="../../../../boost.png" width="100%" border="0"></td><td ><h1 >Concepts and External Concepts</h1></td></tr></table><p >Generic programming in C++ is characterized by the use of function and class templates where
the template parameter(s) must satisfy certain requirements.Often these
requirements are so important that we give them a name: we call
such a set of type requirements a <b>concept</b>. We say that a type <i>

View File

@ -15,7 +15,7 @@
Using the algorithms is straightforward. Let us have a look at the first example:
</para>
<programlisting>
#include &lt;boost/string_algo.hpp&gt;
#include &lt;boost/algorithm/string.hpp&gt;
using namespace std;
using namespace boost;
@ -331,7 +331,7 @@
typedef vector&lt; string &gt; split_vector_type;
split_vector_type SplitVec; // #2: Search for tokens
split( SplitVec, str1, is_any_of&lt;char&gt;("-*") ); // SplitVec == { "hello abc","ABC","aBc goodbye" }
split( SplitVec, str1, is_any_of("-*") ); // SplitVec == { "hello abc","ABC","aBc goodbye" }
</programlisting>
<para>
<code>[hello]</code> designates an <code>iterator_range</code> delimiting this substring.

View File

@ -48,18 +48,18 @@ void find_test()
nc_result=find_first( str1, string("abc") );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),nc_result.begin()) == 3) &&
(distance<string::const_iterator>( str1.begin(),nc_result.end()) == 6) );
( (nc_result.begin()-str1.begin()) == 3) &&
( (nc_result.end()-str1.begin()) == 6) );
cv_result=find_first( const_cast<const string&>(str1), str2 );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),cv_result.begin()) == 3) &&
(distance<string::const_iterator>( str1.begin(),cv_result.end()) == 6) );
( (cv_result.begin()-str1.begin()) == 3) &&
( (cv_result.end()-str1.begin()) == 6) );
cv_result=ifind_first( const_cast<const string&>(str1), "xXX" );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),cv_result.begin()) == 6) &&
(distance<string::const_iterator>( str1.begin(),cv_result.end()) == 9) );
( (cv_result.begin()-str1.begin()) == 6) &&
( (cv_result.end()-str1.begin()) == 9) );
ch_result=find_first( pch1, "abc" );
BOOST_CHECK(( (ch_result.begin() - pch1 ) == 3) && ( (ch_result.end() - pch1 ) == 6 ) );
@ -69,18 +69,18 @@ void find_test()
nc_result=find_last( str1, string("abc") );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),nc_result.begin()) == 15) &&
(distance<string::const_iterator>( str1.begin(),nc_result.end()) == 18) );
( (nc_result.begin()-str1.begin()) == 15) &&
( (nc_result.end()-str1.begin()) == 18) );
cv_result=find_last( const_cast<const string&>(str1), str2 );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),cv_result.begin()) == 15) &&
(distance<string::const_iterator>( str1.begin(),cv_result.end()) == 18) );
( (cv_result.begin()-str1.begin()) == 15) &&
( (cv_result.end()-str1.begin()) == 18) );
cv_result=ifind_last( const_cast<const string&>(str1), "XXx" );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),cv_result.begin()) == 12) &&
(distance<string::const_iterator>( str1.begin(),cv_result.end()) == 15) );
( (cv_result.begin()-str1.begin()) == 12) &&
( (cv_result.end()-str1.begin()) == 15) );
ch_result=find_last( pch1, "abc" );
BOOST_CHECK(( (ch_result.begin() - pch1 ) == 15) && ( (ch_result.end() - pch1 ) == 18 ) );
@ -90,18 +90,18 @@ void find_test()
nc_result=find_nth( str1, string("abc"), 1 );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),nc_result.begin()) == 9) &&
(distance<string::const_iterator>( str1.begin(),nc_result.end()) == 12) );
( (nc_result.begin()-str1.begin()) == 9) &&
( (nc_result.end()-str1.begin()) == 12) );
cv_result=find_nth( const_cast<const string&>(str1), str2, 1 );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),cv_result.begin()) == 9) &&
(distance<string::const_iterator>( str1.begin(),cv_result.end()) == 12) );
( (cv_result.begin()-str1.begin()) == 9) &&
( (cv_result.end()-str1.begin()) == 12) );
cv_result=ifind_nth( const_cast<const string&>(str1), "xxx", 1 );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),cv_result.begin()) == 12) &&
(distance<string::const_iterator>( str1.begin(),cv_result.end()) == 15) );
( (cv_result.begin()-str1.begin()) == 12) &&
( (cv_result.end()-str1.begin()) == 15) );
ch_result=find_nth( pch1, "abc", 1 );
BOOST_CHECK(( (ch_result.begin() - pch1 ) == 9) && ( (ch_result.end() - pch1 ) == 12 ) );
@ -111,13 +111,13 @@ void find_test()
nc_result=find_head( str1, 6 );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),nc_result.begin()) == 0) &&
(distance<string::const_iterator>( str1.begin(),nc_result.end()) == 6) );
( (nc_result.begin()-str1.begin()) == 0) &&
( (nc_result.end()-str1.begin()) == 6) );
cv_result=find_head( const_cast<const string&>(str1), 6 );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),cv_result.begin()) == 0) &&
(distance<string::const_iterator>( str1.begin(),cv_result.end()) == 6) );
( (cv_result.begin()-str1.begin()) == 0) &&
( (cv_result.end()-str1.begin()) == 6) );
ch_result=find_head( pch1, 6 );
BOOST_CHECK( ( (ch_result.begin() - pch1 ) == 0 ) && ( (ch_result.end() - pch1 ) == 6 ) );
@ -127,13 +127,13 @@ void find_test()
nc_result=find_tail( str1, 6 );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),nc_result.begin()) == 15) &&
(distance<string::const_iterator>( str1.begin(),nc_result.end()) == 21) );
( (nc_result.begin()-str1.begin()) == 15) &&
( (nc_result.end()-str1.begin()) == 21) );
cv_result=find_tail( const_cast<const string&>(str1), 6 );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),cv_result.begin()) == 15) &&
(distance<string::const_iterator>( str1.begin(),cv_result.end()) == 21) );
( (cv_result.begin()-str1.begin()) == 15) &&
( (cv_result.end()-str1.begin()) == 21) );
ch_result=find_tail( pch1, 6 );
BOOST_CHECK( ( (ch_result.begin() - pch1 ) == 15 ) && ( (ch_result.end() - pch1 ) == 21 ) );
@ -143,23 +143,23 @@ void find_test()
nc_result=find_token( str1, is_any_of("abc"), token_compress_on );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),nc_result.begin()) == 3) &&
(distance<string::const_iterator>( str1.begin(),nc_result.end()) == 6) );
( (nc_result.begin()-str1.begin()) == 3) &&
( (nc_result.end()-str1.begin()) == 6) );
cv_result=find_token( const_cast<const string&>(str1), is_any_of("abc"), token_compress_on );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),cv_result.begin()) == 3) &&
(distance<string::const_iterator>( str1.begin(),cv_result.end()) == 6) );
( (cv_result.begin()-str1.begin()) == 3) &&
( (cv_result.end()-str1.begin()) == 6) );
nc_result=find_token( str1, is_any_of("abc"), token_compress_off );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),nc_result.begin()) == 3) &&
(distance<string::const_iterator>( str1.begin(),nc_result.end()) == 4) );
( (nc_result.begin()-str1.begin()) == 3) &&
( (nc_result.end()-str1.begin()) == 4) );
cv_result=find_token( const_cast<const string&>(str1), is_any_of("abc"), token_compress_off );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),cv_result.begin()) == 3) &&
(distance<string::const_iterator>( str1.begin(),cv_result.end()) == 4) );
( (cv_result.begin()-str1.begin()) == 3) &&
( (cv_result.end()-str1.begin()) == 4) );
ch_result=find_token( pch1, is_any_of("abc"), token_compress_off );
BOOST_CHECK( ( (ch_result.begin() - pch1 ) == 3 ) && ( (ch_result.end() - pch1 ) == 4 ) );
@ -169,26 +169,26 @@ void find_test()
nc_result=find(str1, first_finder(string("abc")));
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),nc_result.begin()) == 3) &&
(distance<string::const_iterator>( str1.begin(),nc_result.end()) == 6) );
( (nc_result.begin()-str1.begin()) == 3) &&
( (nc_result.end()-str1.begin()) == 6) );
cv_result=find(const_cast<const string&>(str1), first_finder(str2) );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),cv_result.begin()) == 3) &&
(distance<string::const_iterator>( str1.begin(),cv_result.end()) == 6) );
( (cv_result.begin()-str1.begin()) == 3) &&
( (cv_result.end()-str1.begin()) == 6) );
// multi-type comparison test
BOOST_CHECKPOINT( "multi-type" );
nc_vresult=find_first( vec1, string("abc") );
BOOST_CHECK(
(distance<vector<int>::const_iterator>( vec1.begin(),nc_vresult.begin()) == 3) &&
(distance<vector<int>::const_iterator>( vec1.begin(),nc_vresult.end()) == 6) );
( (nc_result.begin()-str1.begin()) == 3) &&
( (nc_result.end()-str1.begin()) == 6) );
cv_vresult=find_first( const_cast<const vector<int>&>(vec1), str2 );
BOOST_CHECK(
(distance<vector<int>::const_iterator>( vec1.begin(),cv_vresult.begin()) == 3) &&
(distance<vector<int>::const_iterator>( vec1.begin(),cv_vresult.end()) == 6) );
( (cv_result.begin()-str1.begin()) == 3) &&
( (cv_result.end()-str1.begin()) == 6) );
// overflow test
BOOST_CHECKPOINT( "overflow" );

View File

@ -42,13 +42,13 @@ static void find_test()
// basic tests
nc_result=find_regex( str1, rx );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),nc_result.begin()) == 3) &&
(distance<string::const_iterator>( str1.begin(),nc_result.end()) == 6) );
( (nc_result.begin()-str1.begin()) == 3) &&
( (nc_result.end()-str1.begin()) == 6) );
cv_result=find_regex( str1, rx );
BOOST_CHECK(
(distance<string::const_iterator>( str1.begin(),cv_result.begin()) == 3) &&
(distance<string::const_iterator>( str1.begin(),cv_result.end()) == 6) );
( (cv_result.begin()-str1.begin()) == 3) &&
( (cv_result.end()-str1.begin()) == 6) );
ch_result=find_regex( pch1, rx );
BOOST_CHECK(( (ch_result.begin() - pch1 ) == 3) && ( (ch_result.end() - pch1 ) == 6 ) );
@ -56,13 +56,13 @@ static void find_test()
// multi-type comparison test
nc_vresult=find_regex( vec1, rx );
BOOST_CHECK(
(distance<vector<int>::const_iterator>( vec1.begin(),nc_vresult.begin()) == 3) &&
(distance<vector<int>::const_iterator>( vec1.begin(),nc_vresult.end()) == 6) );
( (nc_result.begin()-str1.begin()) == 3) &&
( (nc_result.end()-str1.begin()) == 6) );
cv_vresult=find_regex( vec1, rx );
BOOST_CHECK(
(distance<vector<int>::const_iterator>( vec1.begin(),cv_vresult.begin()) == 3) &&
(distance<vector<int>::const_iterator>( vec1.begin(),cv_vresult.end()) == 6) );
( (cv_result.begin()-str1.begin()) == 3) &&
( (cv_result.end()-str1.begin()) == 6) );
// find_all_regex test
find_all_regex( tokens, str1, rx );

View File

@ -24,7 +24,6 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/preprocessor/seq/enum.hpp>
using namespace std;
using namespace boost;
@ -51,6 +50,7 @@ void sequence_traits_test()
}
// Combine tests for all variants of the algorithm
#define C_ ,
#define TEST_ALGO( Algo, Input, Params, Output ) \
{\
BOOST_CHECKPOINT( #Algo " - Copy" );\
@ -58,12 +58,12 @@ void sequence_traits_test()
string str1(Input);\
\
/* Copy test */ \
BOOST_CHECK( Algo##_copy( str1, BOOST_PP_SEQ_ENUM( Params ) )==Output );\
BOOST_CHECK( Algo##_copy( str1, Params )==Output );\
\
BOOST_CHECKPOINT( #Algo " - Iterator" );\
/* Iterator test */\
string strout;\
Algo##_copy( back_inserter(strout), str1, BOOST_PP_SEQ_ENUM( Params ) );\
Algo##_copy( back_inserter(strout), str1, Params );\
BOOST_CHECK( strout==Output ); \
\
/* In-place test */\
@ -71,98 +71,116 @@ void sequence_traits_test()
list<char> list1( str1.begin(), str1.end() );\
\
BOOST_CHECKPOINT( #Algo " - Inplace(string)" );\
Algo( str1, BOOST_PP_SEQ_ENUM( Params ) ); \
Algo( str1, Params ); \
BOOST_CHECK( equals( str1, Output ) ); \
\
BOOST_CHECKPOINT( #Algo " - Inplace(vector)" );\
Algo( vec1, BOOST_PP_SEQ_ENUM( Params ) ); \
Algo( vec1, Params ); \
BOOST_CHECK( equals( vec1, Output ) );\
\
BOOST_CHECKPOINT( #Algo " - Inplace(list)" );\
Algo( list1, BOOST_PP_SEQ_ENUM( Params ) ); \
Algo( list1, Params ); \
BOOST_CHECK( equals( list1, Output ) );\
}
void replace_test()
void replace_first_test()
{
// replace first
TEST_ALGO( replace_first, "1abc3abc2", (string("abc"))(string("YYY")), string("1YYY3abc2") );
TEST_ALGO( ireplace_first, "1AbC3abc2", ("aBc")("YYY"), string("1YYY3abc2") );
TEST_ALGO( replace_first, "1abc3abc2", (string("abc"))(string("Z")), string("1Z3abc2") );
TEST_ALGO( replace_first, "1abc3abc2", (string("abc"))(string("XXXX")), string("1XXXX3abc2") );
TEST_ALGO( replace_first, "1abc3abc2", (string(""))(string("XXXX")), string("1abc3abc2") );
TEST_ALGO( replace_first, "1abc3abc2", ("")("XXXX"), string("1abc3abc2") );
TEST_ALGO( replace_first, "", (string(""))(string("XXXX")), string("") );
TEST_ALGO( erase_first, "1abc3abc2", (string("abc")), string("13abc2") );
TEST_ALGO( ierase_first, "1aBc3abc2", ("abC"), "13abc2" );
TEST_ALGO( erase_first, "1abc3abc2", ("abc"), "13abc2" );
TEST_ALGO( erase_first, "1abc3abc2", (string("")), string("1abc3abc2") );
TEST_ALGO( erase_first, "", (string("abc")), string("") );
TEST_ALGO( replace_first, "1abc3abc2", string("abc") C_ string("YYY"), string("1YYY3abc2") );
TEST_ALGO( ireplace_first, "1AbC3abc2", "aBc" C_ "YYY", string("1YYY3abc2") );
TEST_ALGO( replace_first, "1abc3abc2", string("abc") C_ string("Z"), string("1Z3abc2") );
TEST_ALGO( replace_first, "1abc3abc2", string("abc") C_ string("XXXX"), string("1XXXX3abc2") );
TEST_ALGO( replace_first, "1abc3abc2", string("") C_ string("XXXX"), string("1abc3abc2") );
TEST_ALGO( replace_first, "1abc3abc2", "" C_ "XXXX", string("1abc3abc2") );
TEST_ALGO( replace_first, "", string("") C_ string("XXXX"), string("") );
TEST_ALGO( erase_first, "1abc3abc2", string("abc"), string("13abc2") );
TEST_ALGO( ierase_first, "1aBc3abc2", "abC", "13abc2" );
TEST_ALGO( erase_first, "1abc3abc2", "abc", "13abc2" );
TEST_ALGO( erase_first, "1abc3abc2", string(""), string("1abc3abc2") );
TEST_ALGO( erase_first, "", string("abc"), string("") );
}
void replace_last_test()
{
// replace last
TEST_ALGO( replace_last, "1abc3abc2", (string("abc"))(string("YYY")), string("1abc3YYY2") );
TEST_ALGO( ireplace_last, "1abc3AbC2", ("aBc")("YYY"), string("1abc3YYY2") );
TEST_ALGO( replace_last, "1abc3abc2", (string("abc"))(string("Z")), string("1abc3Z2") );
TEST_ALGO( replace_last, "1abc3abc2", (string("abc"))(string("XXXX")), string("1abc3XXXX2") );
TEST_ALGO( replace_last, "1abc3abc2", ("abc")("XXXX"), string("1abc3XXXX2") );
TEST_ALGO( replace_last, "", (string(""))(string("XXXX")), string("") );
TEST_ALGO( erase_last, "1abc3abc2", (string("abc")), string("1abc32") );
TEST_ALGO( ierase_last, "1aBc3aBc2", ("ABC"), string("1aBc32") );
TEST_ALGO( erase_last, "1abc3abc2", ("abc"), string("1abc32") );
TEST_ALGO( erase_last, "1abc3abc2", (string("")), string("1abc3abc2") );
TEST_ALGO( erase_last, "", (string("abc")), string("") );
TEST_ALGO( replace_last, "1abc3abc2", string("abc") C_ string("YYY"), string("1abc3YYY2") );
TEST_ALGO( ireplace_last, "1abc3AbC2", "aBc" C_ "YYY", string("1abc3YYY2") );
TEST_ALGO( replace_last, "1abc3abc2", string("abc") C_ string("Z"), string("1abc3Z2") );
TEST_ALGO( replace_last, "1abc3abc2", string("abc") C_ string("XXXX"), string("1abc3XXXX2") );
TEST_ALGO( replace_last, "1abc3abc2", "abc" C_ "XXXX", string("1abc3XXXX2") );
TEST_ALGO( replace_last, "", string("") C_ string("XXXX"), string("") );
TEST_ALGO( erase_last, "1abc3abc2", string("abc"), string("1abc32") );
TEST_ALGO( ierase_last, "1aBc3aBc2", "ABC", string("1aBc32") );
TEST_ALGO( erase_last, "1abc3abc2", "abc", string("1abc32") );
TEST_ALGO( erase_last, "1abc3abc2", string(""), string("1abc3abc2") );
TEST_ALGO( erase_last, "", string("abc"), string("") );
}
void replace_all_test()
{
// replace all
TEST_ALGO( replace_all, "1abc3abc2", (string("abc"))(string("YYY")), string("1YYY3YYY2") );
TEST_ALGO( ireplace_all, "1aBc3AbC2", ("abC")("YYY"), string("1YYY3YYY2") );
TEST_ALGO( replace_all, "1abc3abc2", (string("abc"))(string("Z")), string("1Z3Z2") );
TEST_ALGO( replace_all, "1abc3abc2", (string("abc"))(string("XXXX")), string("1XXXX3XXXX2") );
TEST_ALGO( replace_all, "1abc3abc2", ("abc")("XXXX"), string("1XXXX3XXXX2") );
TEST_ALGO( replace_all, "", (string(""))(string("XXXX")), string("") );
TEST_ALGO( erase_all, "1abc3abc2", (string("abc")), string("132") );
TEST_ALGO( ierase_all, "1aBc3aBc2", ("aBC"), string("132") );
TEST_ALGO( erase_all, "1abc3abc2", ("abc"), string("132") );
TEST_ALGO( erase_all, "1abc3abc2", (string("")), string("1abc3abc2") );
TEST_ALGO( erase_all, "", (string("abc")), string("") );
TEST_ALGO( replace_all, "1abc3abc2", string("abc") C_ string("YYY"), string("1YYY3YYY2") );
TEST_ALGO( ireplace_all, "1aBc3AbC2", "abC" C_ "YYY", string("1YYY3YYY2") );
TEST_ALGO( replace_all, "1abc3abc2", string("abc") C_ string("Z"), string("1Z3Z2") );
TEST_ALGO( replace_all, "1abc3abc2", string("abc") C_ string("XXXX"), string("1XXXX3XXXX2") );
TEST_ALGO( replace_all, "1abc3abc2", "abc" C_ "XXXX", string("1XXXX3XXXX2") );
TEST_ALGO( replace_all, "", string("") C_ string("XXXX"), string("") );
TEST_ALGO( erase_all, "1abc3abc2", string("abc"), string("132") );
TEST_ALGO( ierase_all, "1aBc3aBc2", "aBC", string("132") );
TEST_ALGO( erase_all, "1abc3abc2", "abc", string("132") );
TEST_ALGO( erase_all, "1abc3abc2", string(""), string("1abc3abc2") );
TEST_ALGO( erase_all, "", string("abc"), string("") );
}
void replace_nth_test()
{
// replace nth
TEST_ALGO( replace_nth, "1abc3abc2", (string("abc"))(0)(string("YYY")), string("1YYY3abc2") );
TEST_ALGO( ireplace_nth, "1AbC3abc2", ("aBc")(0)("YYY"), string("1YYY3abc2") );
TEST_ALGO( replace_nth, "1abc3abc2", (string("abc"))(0)(string("Z")), string("1Z3abc2") );
TEST_ALGO( replace_nth, "1abc3abc2", (string("abc"))(0)(string("XXXX")), string("1XXXX3abc2") );
TEST_ALGO( replace_nth, "1abc3abc2", ("abc")(0)("XXXX"), string("1XXXX3abc2") );
TEST_ALGO( replace_nth, "1abc3abc2", (string(""))(0)(string("XXXX")), string("1abc3abc2") );
TEST_ALGO( replace_nth, "", (string(""))(0)(string("XXXX")), string("") );
TEST_ALGO( erase_nth, "1abc3abc2", (string("abc"))(0), string("13abc2") );
TEST_ALGO( ierase_nth, "1aBc3aBc2", ("ABC")(0), string("13aBc2") );
TEST_ALGO( erase_nth, "1abc3abc2", ("abc")(0), string("13abc2") );
TEST_ALGO( erase_nth, "1abc3abc2", (string(""))(0), string("1abc3abc2") );
TEST_ALGO( erase_nth, "", (string("abc"))(0), string("") );
TEST_ALGO( replace_nth, "1abc3abc2", (string("abc"))(1)(string("YYY")), string("1abc3YYY2") );
TEST_ALGO( replace_nth, "1abc3abc2", (string("abc"))(2)(string("YYY")), string("1abc3abc2") );
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 0 C_ string("YYY"), string("1YYY3abc2") );
TEST_ALGO( ireplace_nth, "1AbC3abc2", "aBc" C_ 0 C_ "YYY", string("1YYY3abc2") );
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 0 C_ string("Z"), string("1Z3abc2") );
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 0 C_ string("XXXX"), string("1XXXX3abc2") );
TEST_ALGO( replace_nth, "1abc3abc2", "abc" C_ 0 C_ "XXXX", string("1XXXX3abc2") );
TEST_ALGO( replace_nth, "1abc3abc2", string("") C_ 0 C_ string("XXXX"), string("1abc3abc2") );
TEST_ALGO( replace_nth, "", string("") C_ 0 C_ string("XXXX"), string("") );
TEST_ALGO( erase_nth, "1abc3abc2", string("abc") C_ 0, string("13abc2") );
TEST_ALGO( ierase_nth, "1aBc3aBc2", "ABC" C_ 0, string("13aBc2") );
TEST_ALGO( erase_nth, "1abc3abc2", "abc" C_ 0, string("13abc2") );
TEST_ALGO( erase_nth, "1abc3abc2", string("") C_ 0, string("1abc3abc2") );
TEST_ALGO( erase_nth, "", string("abc") C_ 0, string("") );
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 1 C_ string("YYY"), string("1abc3YYY2") );
TEST_ALGO( replace_nth, "1abc3abc2", string("abc") C_ 2 C_ string("YYY"), string("1abc3abc2") );
}
void replace_head_test()
{
// replace head
TEST_ALGO( replace_head, "abc3abc2", (3)(string("YYY")), string("YYY3abc2") );
TEST_ALGO( replace_head, "abc3abc2", (3)("YYY"), string("YYY3abc2") );
TEST_ALGO( replace_head, "abc", (3)(string("Z")), string("Z") );
TEST_ALGO( replace_head, "abc", (6)(string("XXXX")), string("XXXX") );
TEST_ALGO( replace_head, "abc3abc2", (0)(string("XXXX")), string("abc3abc2") );
TEST_ALGO( replace_head, "", (4)(string("XXXX")), string("") );
TEST_ALGO( erase_head, "abc3abc2", (3), string("3abc2") );
TEST_ALGO( erase_head, "abc3abc2", (0), string("abc3abc2") );
TEST_ALGO( erase_head, "", (4), string("") );
TEST_ALGO( replace_head, "abc3abc2", 3 C_ string("YYY"), string("YYY3abc2") );
TEST_ALGO( replace_head, "abc3abc2", 3 C_ "YYY", string("YYY3abc2") );
TEST_ALGO( replace_head, "abc", 3 C_ string("Z"), string("Z") );
TEST_ALGO( replace_head, "abc", 6 C_ string("XXXX"), string("XXXX") );
TEST_ALGO( replace_head, "abc3abc2", 0 C_ string("XXXX"), string("abc3abc2") );
TEST_ALGO( replace_head, "", 4 C_ string("XXXX"), string("") );
TEST_ALGO( erase_head, "abc3abc2", 3, string("3abc2") );
TEST_ALGO( erase_head, "abc3abc2", 0, string("abc3abc2") );
TEST_ALGO( erase_head, "", 4, string("") );
}
void replace_tail_test()
{
// replace tail
TEST_ALGO( replace_tail, "abc3abc", (3)(string("YYY")), string("abc3YYY") );
TEST_ALGO( replace_tail, "abc3abc", (3)("YYY"), string("abc3YYY") );
TEST_ALGO( replace_tail, "abc", (3)(string("Z")), string("Z") );
TEST_ALGO( replace_tail, "abc", (6)(string("XXXX")), string("XXXX") );
TEST_ALGO( replace_tail, "abc3abc", (0)(string("XXXX")), string("abc3abc") );
TEST_ALGO( replace_tail, "", (4)(string("XXXX")), string("") );
TEST_ALGO( erase_tail, "abc3abc", (3), string("abc3") );
TEST_ALGO( erase_tail, "abc3abc", (0), string("abc3abc") );
TEST_ALGO( erase_tail, "", (4), string("") );
TEST_ALGO( replace_tail, "abc3abc", 3 C_ string("YYY"), string("abc3YYY") );
TEST_ALGO( replace_tail, "abc3abc", 3 C_ "YYY", string("abc3YYY") );
TEST_ALGO( replace_tail, "abc", 3 C_ string("Z"), string("Z") );
TEST_ALGO( replace_tail, "abc", 6 C_ string("XXXX"), string("XXXX") );
TEST_ALGO( replace_tail, "abc3abc", 0 C_ string("XXXX"), string("abc3abc") );
TEST_ALGO( replace_tail, "", 4 C_ string("XXXX"), string("") );
TEST_ALGO( erase_tail, "abc3abc", 3, string("abc3") );
TEST_ALGO( erase_tail, "abc3abc", 0, string("abc3abc") );
TEST_ALGO( erase_tail, "", 4, string("") );
}
void replace_range_test()
{
// replace_range
{
BOOST_CHECKPOINT( "replace_range" );
@ -210,8 +228,11 @@ void replace_test()
make_iterator_range(str1.begin()+1, str1.begin()+4));
BOOST_CHECK( str1==string("13abc2") );
}
}
// container traits complatibility tests
void collection_comp_test()
{
// container traits compatibility tests
{
string strout;
replace_first_copy( back_inserter(strout), "1abc3abc2", "abc", "YYY" );
@ -248,7 +269,14 @@ void replace_test()
int test_main( int, char*[] )
{
sequence_traits_test();
replace_test();
replace_first_test();
replace_last_test();
replace_all_test();
replace_nth_test();
replace_head_test();
replace_tail_test();
replace_range_test();
collection_comp_test();
return 0;
}