diff options
Diffstat (limited to 'src/boost/libs/foreach')
29 files changed, 1441 insertions, 0 deletions
diff --git a/src/boost/libs/foreach/index.html b/src/boost/libs/foreach/index.html new file mode 100644 index 000000000..41d89a1d9 --- /dev/null +++ b/src/boost/libs/foreach/index.html @@ -0,0 +1,14 @@ +<html> +<head> + <meta http-equiv="refresh" content="0; URL=../../doc/html/foreach.html"> +</head> +<body> +Automatic redirection failed, please go to +<a href="../../doc/html/foreach.html">../../doc/html/foreach.html</a> +<p>Copyright Eric Niebler 2006</p> +<p>Distributed under the Boost Software License, Version 1.0. (See accompanying file +<a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at +<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>). +</p> +</body> +</html> diff --git a/src/boost/libs/foreach/meta/libraries.json b/src/boost/libs/foreach/meta/libraries.json new file mode 100644 index 000000000..0215781a1 --- /dev/null +++ b/src/boost/libs/foreach/meta/libraries.json @@ -0,0 +1,15 @@ +{ + "key": "foreach", + "name": "Foreach", + "authors": [ + "Eric Niebler" + ], + "description": "In C++, writing a loop that iterates over a sequence is tedious. We can either use iterators, which requires a considerable amount of boiler-plate, or we can use the std::for_each() algorithm and move our loop body into a predicate, which requires no less boiler-plate and forces us to move our logic far from where it will be used. In contrast, some other languages, like Perl, provide a dedicated \"foreach\" construct that automates this process. BOOST_FOREACH is just such a construct for C++. It iterates over sequences for us, freeing us from having to deal directly with iterators or write predicates.", + "category": [ + "Algorithms", + "Emulation" + ], + "maintainers": [ + "Eric Niebler <eric -at- boostpro.com>" + ] +} diff --git a/src/boost/libs/foreach/test/Jamfile.v2 b/src/boost/libs/foreach/test/Jamfile.v2 new file mode 100644 index 000000000..084c5c869 --- /dev/null +++ b/src/boost/libs/foreach/test/Jamfile.v2 @@ -0,0 +1,36 @@ +# (C) Copyright 2004: Eric Niebler +# Distributed under 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) + +# bring in rules for testing +import testing ; + +project : requirements <toolset>msvc:<asynch-exceptions>on ; + +test-suite "foreach" + : [ run stl_byval.cpp ] + [ run stl_byref.cpp ] + [ run stl_byval_r.cpp ] + [ run stl_byref_r.cpp ] + [ run array_byval.cpp ] + [ run array_byref.cpp ] + [ run array_byval_r.cpp ] + [ run array_byref_r.cpp ] + [ run cstr_byval.cpp ] + [ run cstr_byref.cpp ] + [ run cstr_byval_r.cpp ] + [ run cstr_byref_r.cpp ] + [ run pair_byval.cpp ] + [ run pair_byref.cpp ] + [ run pair_byval_r.cpp ] + [ run pair_byref_r.cpp ] + [ run user_defined.cpp ] + [ run call_once.cpp ] + [ run rvalue_const.cpp ] + [ run rvalue_nonconst.cpp ] + [ run rvalue_const_r.cpp ] + [ run rvalue_nonconst_r.cpp ] + [ run dependent_type.cpp ] + [ run misc.cpp ] + [ compile noncopyable.cpp ] + ; diff --git a/src/boost/libs/foreach/test/array_byref.cpp b/src/boost/libs/foreach/test/array_byref.cpp new file mode 100644 index 000000000..7fce4ca04 --- /dev/null +++ b/src/boost/libs/foreach/test/array_byref.cpp @@ -0,0 +1,48 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef int foreach_container_type[5]; +typedef int const foreach_const_container_type[5]; +typedef int foreach_value_type; +typedef int &foreach_reference_type; +typedef int const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +int my_array[5] = { 1,2,3,4,5 }; +int const (&my_const_array)[5] = my_array; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + // non-const containers by reference + BOOST_CHECK(sequence_equal_byref_n(my_array, "\1\2\3\4\5")); + + // const containers by reference + BOOST_CHECK(sequence_equal_byref_c(my_const_array, "\1\2\3\4\5")); + + // mutate the mutable collections + mutate_foreach_byref(my_array); + + // compare the mutated collections to the actual results + BOOST_CHECK(sequence_equal_byref_n(my_array, "\2\3\4\5\6")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/array_byref_r.cpp b/src/boost/libs/foreach/test/array_byref_r.cpp new file mode 100644 index 000000000..aed9f7e4f --- /dev/null +++ b/src/boost/libs/foreach/test/array_byref_r.cpp @@ -0,0 +1,48 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef int foreach_container_type[5]; +typedef int const foreach_const_container_type[5]; +typedef int foreach_value_type; +typedef int &foreach_reference_type; +typedef int const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +int my_array[5] = { 1,2,3,4,5 }; +int const (&my_const_array)[5] = my_array; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + // non-const containers by reference + BOOST_CHECK(sequence_equal_byref_n_r(my_array, "\5\4\3\2\1")); + + // const containers by reference + BOOST_CHECK(sequence_equal_byref_c_r(my_const_array, "\5\4\3\2\1")); + + // mutate the mutable collections + mutate_foreach_byref_r(my_array); + + // compare the mutated collections to the actual results + BOOST_CHECK(sequence_equal_byref_n_r(my_array, "\6\5\4\3\2")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/array_byval.cpp b/src/boost/libs/foreach/test/array_byval.cpp new file mode 100644 index 000000000..a35eb2531 --- /dev/null +++ b/src/boost/libs/foreach/test/array_byval.cpp @@ -0,0 +1,44 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef int foreach_container_type[5]; +typedef int const foreach_const_container_type[5]; +typedef int foreach_value_type; +typedef int &foreach_reference_type; +typedef int const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +int my_array[5] = { 1,2,3,4,5 }; +int const (&my_const_array)[5] = my_array; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + boost::mpl::false_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_array); + (void)p; + // non-const containers by value + BOOST_CHECK(sequence_equal_byval_n(my_array, "\1\2\3\4\5")); + + // const containers by value + BOOST_CHECK(sequence_equal_byval_c(my_const_array, "\1\2\3\4\5")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/array_byval_r.cpp b/src/boost/libs/foreach/test/array_byval_r.cpp new file mode 100644 index 000000000..96b907160 --- /dev/null +++ b/src/boost/libs/foreach/test/array_byval_r.cpp @@ -0,0 +1,45 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef int foreach_container_type[5]; +typedef int const foreach_const_container_type[5]; +typedef int foreach_value_type; +typedef int &foreach_reference_type; +typedef int const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +int my_array[5] = { 1,2,3,4,5 }; +int const (&my_const_array)[5] = my_array; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + boost::mpl::false_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_array); + (void)p; + + // non-const containers by value + BOOST_CHECK(sequence_equal_byval_n_r(my_array, "\5\4\3\2\1")); + + // const containers by value + BOOST_CHECK(sequence_equal_byval_c_r(my_const_array, "\5\4\3\2\1")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/call_once.cpp b/src/boost/libs/foreach/test/call_once.cpp new file mode 100644 index 000000000..e37f74c2f --- /dev/null +++ b/src/boost/libs/foreach/test/call_once.cpp @@ -0,0 +1,40 @@ +// (C) Copyright Eric Niebler 2005. +// 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <vector> +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +// counter +int counter = 0; + +std::vector<int> my_vector(4,4); + +std::vector<int> const &get_vector() +{ + ++counter; + return my_vector; +} + + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + BOOST_FOREACH(int i, get_vector()) + { + ((void)i); // no-op + } + + BOOST_CHECK(1 == counter); + + return 0; +} diff --git a/src/boost/libs/foreach/test/cstr_byref.cpp b/src/boost/libs/foreach/test/cstr_byref.cpp new file mode 100644 index 000000000..f25611e93 --- /dev/null +++ b/src/boost/libs/foreach/test/cstr_byref.cpp @@ -0,0 +1,49 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef char *foreach_container_type; +typedef char const *foreach_const_container_type; +typedef char foreach_value_type; +typedef char &foreach_reference_type; +typedef char const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +char my_ntcs_buffer[] = "\1\2\3\4\5"; +char *my_ntcs = my_ntcs_buffer; +char const *my_const_ntcs = my_ntcs; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + // non-const containers by reference + BOOST_CHECK(sequence_equal_byref_n(my_ntcs, "\1\2\3\4\5")); + + // const containers by reference + BOOST_CHECK(sequence_equal_byref_c(my_const_ntcs, "\1\2\3\4\5")); + + // mutate the mutable collections + mutate_foreach_byref(my_ntcs); + + // compare the mutated collections to the actual results + BOOST_CHECK(sequence_equal_byref_n(my_ntcs, "\2\3\4\5\6")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/cstr_byref_r.cpp b/src/boost/libs/foreach/test/cstr_byref_r.cpp new file mode 100644 index 000000000..79b46cf6d --- /dev/null +++ b/src/boost/libs/foreach/test/cstr_byref_r.cpp @@ -0,0 +1,49 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef char *foreach_container_type; +typedef char const *foreach_const_container_type; +typedef char foreach_value_type; +typedef char &foreach_reference_type; +typedef char const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +char my_ntcs_buffer[] = "\1\2\3\4\5"; +char *my_ntcs = my_ntcs_buffer; +char const *my_const_ntcs = my_ntcs; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + // non-const containers by reference + BOOST_CHECK(sequence_equal_byref_n_r(my_ntcs, "\5\4\3\2\1")); + + // const containers by reference + BOOST_CHECK(sequence_equal_byref_c_r(my_const_ntcs, "\5\4\3\2\1")); + + // mutate the mutable collections + mutate_foreach_byref_r(my_ntcs); + + // compare the mutated collections to the actual results + BOOST_CHECK(sequence_equal_byref_n_r(my_ntcs, "\6\5\4\3\2")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/cstr_byval.cpp b/src/boost/libs/foreach/test/cstr_byval.cpp new file mode 100644 index 000000000..4713d4f3f --- /dev/null +++ b/src/boost/libs/foreach/test/cstr_byval.cpp @@ -0,0 +1,46 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef char *foreach_container_type; +typedef char const *foreach_const_container_type; +typedef char foreach_value_type; +typedef char &foreach_reference_type; +typedef char const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +char my_ntcs_buffer[] = "\1\2\3\4\5"; +char *my_ntcs = my_ntcs_buffer; +char const *my_const_ntcs = my_ntcs; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + boost::mpl::true_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_ntcs); + (void)p; + + // non-const containers by value + BOOST_CHECK(sequence_equal_byval_n(my_ntcs, "\1\2\3\4\5")); + + // const containers by value + BOOST_CHECK(sequence_equal_byval_c(my_const_ntcs, "\1\2\3\4\5")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/cstr_byval_r.cpp b/src/boost/libs/foreach/test/cstr_byval_r.cpp new file mode 100644 index 000000000..00c6ca755 --- /dev/null +++ b/src/boost/libs/foreach/test/cstr_byval_r.cpp @@ -0,0 +1,46 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef char *foreach_container_type; +typedef char const *foreach_const_container_type; +typedef char foreach_value_type; +typedef char &foreach_reference_type; +typedef char const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +char my_ntcs_buffer[] = "\1\2\3\4\5"; +char *my_ntcs = my_ntcs_buffer; +char const *my_const_ntcs = my_ntcs; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + boost::mpl::true_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_ntcs); + (void)p; + + // non-const containers by value + BOOST_CHECK(sequence_equal_byval_n_r(my_ntcs, "\5\4\3\2\1")); + + // const containers by value + BOOST_CHECK(sequence_equal_byval_c_r(my_const_ntcs, "\5\4\3\2\1")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/dependent_type.cpp b/src/boost/libs/foreach/test/dependent_type.cpp new file mode 100644 index 000000000..85a7af40b --- /dev/null +++ b/src/boost/libs/foreach/test/dependent_type.cpp @@ -0,0 +1,37 @@ +// (C) Copyright Eric Niebler 2005. +// 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) + +/* + Revision history: + 26 August 2005 : Initial version. +*/ + +#include <vector> +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// use FOREACH to iterate over a sequence with a dependent type +template<typename Vector> +void do_test(Vector const & vect) +{ + typedef BOOST_DEDUCED_TYPENAME Vector::value_type value_type; + BOOST_FOREACH(value_type i, vect) + { + // no-op, just make sure this compiles + ((void)i); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + std::vector<int> vect; + do_test(vect); + + return 0; +} diff --git a/src/boost/libs/foreach/test/misc.cpp b/src/boost/libs/foreach/test/misc.cpp new file mode 100644 index 000000000..2a25acabb --- /dev/null +++ b/src/boost/libs/foreach/test/misc.cpp @@ -0,0 +1,47 @@ +// misc.cpp +// +// (C) Copyright Eric Niebler 2008. +// 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) + +/* + Revision history: + 4 March 2008 : Initial version. +*/ + +#include <vector> +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +struct xxx : std::vector<int> +{ + virtual ~xxx() = 0; +}; + +void test_abstract(xxx& rng) +{ + BOOST_FOREACH (int x, rng) + { + (void)x; + } +} + +struct yyy : std::vector<int> +{ + void test() + { + BOOST_FOREACH(int x, *this) + { + (void)x; + } + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + return 0; +} diff --git a/src/boost/libs/foreach/test/noncopyable.cpp b/src/boost/libs/foreach/test/noncopyable.cpp new file mode 100644 index 000000000..60a2eebd2 --- /dev/null +++ b/src/boost/libs/foreach/test/noncopyable.cpp @@ -0,0 +1,72 @@ +// noncopyable.cpp +/// +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 21 December 2005 : Initial version. +*/ + +#include <vector> +#include <boost/foreach.hpp> +#include <boost/noncopyable.hpp> +#include <boost/range/iterator_range.hpp> + +struct noncopy_vector + : std::vector<int> + , private boost::noncopyable +{ + noncopy_vector() { } +}; + +struct noncopy_range + : boost::iterator_range<noncopy_vector::iterator> + , private boost::noncopyable +{ + noncopy_range() { } +}; + +// Tell FOREACH that noncopy_vector and noncopy_range are non-copyable. +// NOTE: this is only necessary if +// a) your type does not inherit from boost::noncopyable, OR +// b) Boost.Config defines BOOST_BROKEN_IS_BASE_AND_DERIVED for your compiler +#ifdef BOOST_BROKEN_IS_BASE_AND_DERIVED +inline boost::mpl::true_ *boost_foreach_is_noncopyable(noncopy_vector *&, boost::foreach::tag) +{ + return 0; +} + +inline boost::mpl::true_ *boost_foreach_is_noncopyable(noncopy_range *&, boost::foreach::tag) +{ + return 0; +} +#endif + +// tell FOREACH that noncopy_range is a lightweight proxy object +inline boost::mpl::true_ *boost_foreach_is_lightweight_proxy(noncopy_range *&, boost::foreach::tag) +{ + return 0; +} + +/////////////////////////////////////////////////////////////////////////////// +// main +// +int main( int, char*[] ) +{ + noncopy_vector v1; + BOOST_FOREACH( int & i, v1 ) { (void)i; } + + noncopy_vector const v2; + BOOST_FOREACH( int const & j, v2 ) { (void)j; } + + noncopy_range rng1; + BOOST_FOREACH( int & k, rng1 ) { (void)k; } + + noncopy_range const rng2; + BOOST_FOREACH( int & l, rng2 ) { (void)l; } + + return 0; +} diff --git a/src/boost/libs/foreach/test/pair_byref.cpp b/src/boost/libs/foreach/test/pair_byref.cpp new file mode 100644 index 000000000..5df375278 --- /dev/null +++ b/src/boost/libs/foreach/test/pair_byref.cpp @@ -0,0 +1,50 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 13 December 2004 : Initial version. + 25 August 2005 : Initial version. +*/ + +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef std::pair<int*,int*> foreach_container_type; +typedef std::pair<int const*,int const*> const foreach_const_container_type; +typedef int foreach_value_type; +typedef int &foreach_reference_type; +typedef int const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +int my_array[] = { 1,2,3,4,5 }; +std::pair<int*,int*> my_pair(my_array,my_array+5); +std::pair<int const*,int const*> const my_const_pair(my_array,my_array+5); + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + // non-const containers by reference + BOOST_CHECK(sequence_equal_byref_n(my_pair, "\1\2\3\4\5")); + + // const containers by reference + BOOST_CHECK(sequence_equal_byref_c(my_const_pair, "\1\2\3\4\5")); + + // mutate the mutable collections + mutate_foreach_byref(my_pair); + + // compare the mutated collections to the actual results + BOOST_CHECK(sequence_equal_byref_n(my_pair, "\2\3\4\5\6")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/pair_byref_r.cpp b/src/boost/libs/foreach/test/pair_byref_r.cpp new file mode 100644 index 000000000..562cbf4e1 --- /dev/null +++ b/src/boost/libs/foreach/test/pair_byref_r.cpp @@ -0,0 +1,50 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 13 December 2004 : Initial version. + 25 August 2005 : Initial version. +*/ + +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef std::pair<int*,int*> foreach_container_type; +typedef std::pair<int const*,int const*> const foreach_const_container_type; +typedef int foreach_value_type; +typedef int &foreach_reference_type; +typedef int const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +int my_array[] = { 1,2,3,4,5 }; +std::pair<int*,int*> my_pair(my_array,my_array+5); +std::pair<int const*,int const*> const my_const_pair(my_array,my_array+5); + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + // non-const containers by reference + BOOST_CHECK(sequence_equal_byref_n_r(my_pair, "\5\4\3\2\1")); + + // const containers by reference + BOOST_CHECK(sequence_equal_byref_c_r(my_const_pair, "\5\4\3\2\1")); + + // mutate the mutable collections + mutate_foreach_byref_r(my_pair); + + // compare the mutated collections to the actual results + BOOST_CHECK(sequence_equal_byref_n_r(my_pair, "\6\5\4\3\2")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/pair_byval.cpp b/src/boost/libs/foreach/test/pair_byval.cpp new file mode 100644 index 000000000..90db6cd79 --- /dev/null +++ b/src/boost/libs/foreach/test/pair_byval.cpp @@ -0,0 +1,46 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef std::pair<int*,int*> foreach_container_type; +typedef std::pair<int const*,int const*> const foreach_const_container_type; +typedef int foreach_value_type; +typedef int &foreach_reference_type; +typedef int const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +int my_array[] = { 1,2,3,4,5 }; +std::pair<int*,int*> my_pair(my_array,my_array+5); +std::pair<int const*,int const*> const my_const_pair(my_array,my_array+5); + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + boost::mpl::true_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_pair); + (void)p; + + // non-const containers by value + BOOST_CHECK(sequence_equal_byval_n(my_pair, "\1\2\3\4\5")); + + // const containers by value + BOOST_CHECK(sequence_equal_byval_c(my_const_pair, "\1\2\3\4\5")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/pair_byval_r.cpp b/src/boost/libs/foreach/test/pair_byval_r.cpp new file mode 100644 index 000000000..98b32f3c6 --- /dev/null +++ b/src/boost/libs/foreach/test/pair_byval_r.cpp @@ -0,0 +1,46 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef std::pair<int*,int*> foreach_container_type; +typedef std::pair<int const*,int const*> const foreach_const_container_type; +typedef int foreach_value_type; +typedef int &foreach_reference_type; +typedef int const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +int my_array[] = { 1,2,3,4,5 }; +std::pair<int*,int*> my_pair(my_array,my_array+5); +std::pair<int const*,int const*> const my_const_pair(my_array,my_array+5); + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + boost::mpl::true_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_pair); + (void)p; + + // non-const containers by value + BOOST_CHECK(sequence_equal_byval_n_r(my_pair, "\5\4\3\2\1")); + + // const containers by value + BOOST_CHECK(sequence_equal_byval_c_r(my_const_pair, "\5\4\3\2\1")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/rvalue_const.cpp b/src/boost/libs/foreach/test/rvalue_const.cpp new file mode 100644 index 000000000..eaa06281d --- /dev/null +++ b/src/boost/libs/foreach/test/rvalue_const.cpp @@ -0,0 +1,44 @@ +// (C) Copyright Eric Niebler 2005. +// 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <vector> +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +#ifdef BOOST_FOREACH_NO_CONST_RVALUE_DETECTION +// ignore error during Microsoft Code Analysis +#if !defined(_PREFAST_) +# error Expected failure : const rvalues disallowed +#endif +#else + +std::vector<int> const get_vector() +{ + return std::vector<int>(4, 4); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + int counter = 0; + + BOOST_FOREACH(int i, get_vector()) + { + counter += i; + } + + BOOST_CHECK(16 == counter); + + return 0; +} + +#endif diff --git a/src/boost/libs/foreach/test/rvalue_const_r.cpp b/src/boost/libs/foreach/test/rvalue_const_r.cpp new file mode 100644 index 000000000..fbc2762d3 --- /dev/null +++ b/src/boost/libs/foreach/test/rvalue_const_r.cpp @@ -0,0 +1,44 @@ +// (C) Copyright Eric Niebler 2005. +// 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <vector> +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +#ifdef BOOST_FOREACH_NO_CONST_RVALUE_DETECTION +// ignore error during Microsoft Code Analysis +#if !defined(_PREFAST_) +# error Expected failure : const rvalues disallowed +#endif +#else + +std::vector<int> const get_vector() +{ + return std::vector<int>(4, 4); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + int counter = 0; + + BOOST_REVERSE_FOREACH(int i, get_vector()) + { + counter += i; + } + + BOOST_CHECK(16 == counter); + + return 0; +} + +#endif diff --git a/src/boost/libs/foreach/test/rvalue_nonconst.cpp b/src/boost/libs/foreach/test/rvalue_nonconst.cpp new file mode 100644 index 000000000..02827c1ea --- /dev/null +++ b/src/boost/libs/foreach/test/rvalue_nonconst.cpp @@ -0,0 +1,41 @@ +// (C) Copyright Eric Niebler 2005. +// 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <vector> +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +#ifdef BOOST_FOREACH_NO_RVALUE_DETECTION +# error Expected failure : rvalues disallowed +#else + +std::vector<int> get_vector() +{ + return std::vector<int>(4, 4); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + int counter = 0; + + BOOST_FOREACH(int i, get_vector()) + { + counter += i; + } + + BOOST_CHECK(16 == counter); + + return 0; +} + +#endif diff --git a/src/boost/libs/foreach/test/rvalue_nonconst_r.cpp b/src/boost/libs/foreach/test/rvalue_nonconst_r.cpp new file mode 100644 index 000000000..991f8beac --- /dev/null +++ b/src/boost/libs/foreach/test/rvalue_nonconst_r.cpp @@ -0,0 +1,41 @@ +// (C) Copyright Eric Niebler 2005. +// 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <vector> +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +#ifdef BOOST_FOREACH_NO_RVALUE_DETECTION +# error Expected failure : rvalues disallowed +#else + +std::vector<int> get_vector() +{ + return std::vector<int>(4, 4); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + int counter = 0; + + BOOST_REVERSE_FOREACH(int i, get_vector()) + { + counter += i; + } + + BOOST_CHECK(16 == counter); + + return 0; +} + +#endif diff --git a/src/boost/libs/foreach/test/stl_byref.cpp b/src/boost/libs/foreach/test/stl_byref.cpp new file mode 100644 index 000000000..be9b004b7 --- /dev/null +++ b/src/boost/libs/foreach/test/stl_byref.cpp @@ -0,0 +1,62 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005: Initial version. +*/ + +#include <list> +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef std::list<int> foreach_container_type; +typedef std::list<int> const foreach_const_container_type; +typedef int foreach_value_type; +typedef int &foreach_reference_type; +typedef int const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// initialize a std::list<int> +std::list<int> make_list() +{ + std::list<int> l; + l.push_back(1); + l.push_back(2); + l.push_back(3); + l.push_back(4); + l.push_back(5); + return l; +} + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +std::list<int> my_list = make_list(); +std::list<int> const &my_const_list = my_list; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + // non-const containers by reference + BOOST_CHECK(sequence_equal_byref_n(my_list, "\1\2\3\4\5")); + + // const containers by reference + BOOST_CHECK(sequence_equal_byref_c(my_const_list, "\1\2\3\4\5")); + + // mutate the mutable collections + mutate_foreach_byref(my_list); + + // compare the mutated collections to the actual results + BOOST_CHECK(sequence_equal_byref_n(my_list, "\2\3\4\5\6")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/stl_byref_r.cpp b/src/boost/libs/foreach/test/stl_byref_r.cpp new file mode 100644 index 000000000..6febdfbf7 --- /dev/null +++ b/src/boost/libs/foreach/test/stl_byref_r.cpp @@ -0,0 +1,62 @@ +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005: Initial version. +*/ + +#include <list> +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef std::list<int> foreach_container_type; +typedef std::list<int> const foreach_const_container_type; +typedef int foreach_value_type; +typedef int &foreach_reference_type; +typedef int const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// initialize a std::list<int> +std::list<int> make_list() +{ + std::list<int> l; + l.push_back(1); + l.push_back(2); + l.push_back(3); + l.push_back(4); + l.push_back(5); + return l; +} + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +std::list<int> my_list = make_list(); +std::list<int> const &my_const_list = my_list; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + // non-const containers by reference + BOOST_CHECK(sequence_equal_byref_n_r(my_list, "\5\4\3\2\1")); + + // const containers by reference + BOOST_CHECK(sequence_equal_byref_c_r(my_const_list, "\5\4\3\2\1")); + + // mutate the mutable collections + mutate_foreach_byref_r(my_list); + + // compare the mutated collections to the actual results + BOOST_CHECK(sequence_equal_byref_n_r(my_list, "\6\5\4\3\2")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/stl_byval.cpp b/src/boost/libs/foreach/test/stl_byval.cpp new file mode 100644 index 000000000..699839e91 --- /dev/null +++ b/src/boost/libs/foreach/test/stl_byval.cpp @@ -0,0 +1,61 @@ +// stl_byval.cpp +/// +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <list> +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef std::list<int> foreach_container_type; +typedef std::list<int> const foreach_const_container_type; +typedef int foreach_value_type; +typedef int &foreach_reference_type; +typedef int const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// initialize a std::list<int> +std::list<int> make_list() +{ + std::list<int> l; + l.push_back(1); + l.push_back(2); + l.push_back(3); + l.push_back(4); + l.push_back(5); + return l; +} + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +std::list<int> my_list = make_list(); +std::list<int> const &my_const_list = my_list; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + boost::mpl::false_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_list); + (void)p; + + // non-const containers by value + BOOST_CHECK(sequence_equal_byval_n(my_list, "\1\2\3\4\5")); + + // const containers by value + BOOST_CHECK(sequence_equal_byval_c(my_const_list, "\1\2\3\4\5")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/stl_byval_r.cpp b/src/boost/libs/foreach/test/stl_byval_r.cpp new file mode 100644 index 000000000..c0208b488 --- /dev/null +++ b/src/boost/libs/foreach/test/stl_byval_r.cpp @@ -0,0 +1,61 @@ +// stl_byval.cpp +/// +// (C) Copyright Eric Niebler 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) + +/* + Revision history: + 25 August 2005 : Initial version. +*/ + +#include <list> +#include <boost/test/minimal.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define the container types, used by utility.hpp to generate the helper functions +typedef std::list<int> foreach_container_type; +typedef std::list<int> const foreach_const_container_type; +typedef int foreach_value_type; +typedef int &foreach_reference_type; +typedef int const &foreach_const_reference_type; + +#include "./utility.hpp" + +/////////////////////////////////////////////////////////////////////////////// +// initialize a std::list<int> +std::list<int> make_list() +{ + std::list<int> l; + l.push_back(1); + l.push_back(2); + l.push_back(3); + l.push_back(4); + l.push_back(5); + return l; +} + +/////////////////////////////////////////////////////////////////////////////// +// define some containers +// +std::list<int> my_list = make_list(); +std::list<int> const &my_const_list = my_list; + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + boost::mpl::false_ *p = BOOST_FOREACH_IS_LIGHTWEIGHT_PROXY(my_list); + (void)p; + + // non-const containers by value + BOOST_CHECK(sequence_equal_byval_n_r(my_list, "\5\4\3\2\1")); + + // const containers by value + BOOST_CHECK(sequence_equal_byval_c_r(my_const_list, "\5\4\3\2\1")); + + return 0; +} diff --git a/src/boost/libs/foreach/test/user_defined.cpp b/src/boost/libs/foreach/test/user_defined.cpp new file mode 100644 index 000000000..a05bf3a6a --- /dev/null +++ b/src/boost/libs/foreach/test/user_defined.cpp @@ -0,0 +1,54 @@ +// (C) Copyright Eric Niebler 2005. +// 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) + +/* +Revision history: +25 August 2005 : Initial version. +*/ + +#include <boost/test/minimal.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// define a user-defined collection type and teach BOOST_FOREACH how to enumerate it +// +namespace mine +{ + struct dummy {}; + char * range_begin(mine::dummy&) {return 0;} + char const * range_begin(mine::dummy const&) {return 0;} + char * range_end(mine::dummy&) {return 0;} + char const * range_end(mine::dummy const&) {return 0;} +} + +#include <boost/foreach.hpp> + +namespace boost +{ + template<> + struct range_mutable_iterator<mine::dummy> + { + typedef char * type; + }; + template<> + struct range_const_iterator<mine::dummy> + { + typedef char const * type; + }; +} + +/////////////////////////////////////////////////////////////////////////////// +// test_main +// +int test_main( int, char*[] ) +{ + // loop over a user-defined type (just make sure this compiles) + mine::dummy d; + BOOST_FOREACH( char c, d ) + { + ((void)c); // no-op + } + + return 0; +} diff --git a/src/boost/libs/foreach/test/utility.hpp b/src/boost/libs/foreach/test/utility.hpp new file mode 100644 index 000000000..40e64f81b --- /dev/null +++ b/src/boost/libs/foreach/test/utility.hpp @@ -0,0 +1,143 @@ +/////////////////////////////////////////////////////////////////////////////// +// utility.hpp header file +// +// Copyright 2005 Eric Niebler. +// Distributed under 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) +// + +#ifndef BOOST_FOREACH_TEST_UTILITY_HPP +#define BOOST_FOREACH_TEST_UTILITY_HPP + +#include <boost/config.hpp> +#include <boost/foreach.hpp> + +/////////////////////////////////////////////////////////////////////////////// +// sequence_equal_byval_n +inline bool sequence_equal_byval_n( foreach_container_type & rng, char const * result ) +{ + BOOST_FOREACH( foreach_value_type i, rng ) + { + if(0 == *result || i != *result) + return false; + ++result; + } + return 0 == *result; +} + +/////////////////////////////////////////////////////////////////////////////// +// sequence_equal_byval_c +inline bool sequence_equal_byval_c( foreach_const_container_type & rng, char const * result ) +{ + BOOST_FOREACH( foreach_value_type i, rng ) + { + if(0 == *result || i != *result) + return false; + ++result; + } + return 0 == *result; +} + +/////////////////////////////////////////////////////////////////////////////// +// sequence_equal_byref_n +inline bool sequence_equal_byref_n( foreach_container_type & rng, char const * result ) +{ + BOOST_FOREACH( foreach_reference_type i, rng ) + { + if(0 == *result || i != *result) + return false; + ++result; + } + return 0 == *result; +} + +/////////////////////////////////////////////////////////////////////////////// +// sequence_equal_byref_c +inline bool sequence_equal_byref_c( foreach_const_container_type & rng, char const * result ) +{ + BOOST_FOREACH( foreach_const_reference_type i, rng ) + { + if(0 == *result || i != *result) + return false; + ++result; + } + return 0 == *result; +} + +/////////////////////////////////////////////////////////////////////////////// +// mutate_foreach_byref +// +inline void mutate_foreach_byref( foreach_container_type & rng ) +{ + BOOST_FOREACH( foreach_reference_type i, rng ) + { + ++i; + } +} + + +/////////////////////////////////////////////////////////////////////////////// +// sequence_equal_byval_n_r +inline bool sequence_equal_byval_n_r( foreach_container_type & rng, char const * result ) +{ + BOOST_REVERSE_FOREACH( foreach_value_type i, rng ) + { + if(0 == *result || i != *result) + return false; + ++result; + } + return 0 == *result; +} + +/////////////////////////////////////////////////////////////////////////////// +// sequence_equal_byval_c_r +inline bool sequence_equal_byval_c_r( foreach_const_container_type & rng, char const * result ) +{ + BOOST_REVERSE_FOREACH( foreach_value_type i, rng ) + { + if(0 == *result || i != *result) + return false; + ++result; + } + return 0 == *result; +} + +/////////////////////////////////////////////////////////////////////////////// +// sequence_equal_byref_n_r +inline bool sequence_equal_byref_n_r( foreach_container_type & rng, char const * result ) +{ + BOOST_REVERSE_FOREACH( foreach_reference_type i, rng ) + { + if(0 == *result || i != *result) + return false; + ++result; + } + return 0 == *result; +} + +/////////////////////////////////////////////////////////////////////////////// +// sequence_equal_byref_c_r +inline bool sequence_equal_byref_c_r( foreach_const_container_type & rng, char const * result ) +{ + BOOST_REVERSE_FOREACH( foreach_const_reference_type i, rng ) + { + if(0 == *result || i != *result) + return false; + ++result; + } + return 0 == *result; +} + +/////////////////////////////////////////////////////////////////////////////// +// mutate_foreach_byref +// +inline void mutate_foreach_byref_r( foreach_container_type & rng ) +{ + BOOST_REVERSE_FOREACH( foreach_reference_type i, rng ) + { + ++i; + } +} + +#endif |