From 5e9b10ca734a568cb30ec63c78a8f4f71dd57b23 Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Sun, 31 Oct 2004 09:57:19 +0000 Subject: [PATCH] remove duplicate examples/move missing bits to the example directory [SVN r26004] --- example/Jamfile | 4 +- example/counting_iterator_example.cpp | 7 ++ .../projection_iterator_example.cpp | 2 +- test/Jamfile | 8 -- test/Jamfile.v2 | 10 --- test/counting_iterator_example.cpp | 60 --------------- test/filter_iterator_example.cpp | 61 --------------- test/fun_out_iter_example.cpp | 46 ----------- test/iterator_adaptor_examples.cpp | 46 ----------- test/reverse_iterator_example.cpp | 47 ------------ test/transform_iterator_example.cpp | 76 ------------------- 11 files changed, 11 insertions(+), 356 deletions(-) rename {test => example}/projection_iterator_example.cpp (98%) delete mode 100644 test/counting_iterator_example.cpp delete mode 100644 test/filter_iterator_example.cpp delete mode 100644 test/fun_out_iter_example.cpp delete mode 100644 test/iterator_adaptor_examples.cpp delete mode 100644 test/reverse_iterator_example.cpp delete mode 100644 test/transform_iterator_example.cpp diff --git a/example/Jamfile b/example/Jamfile index 71301a5..7f5eaa8 100644 --- a/example/Jamfile +++ b/example/Jamfile @@ -16,5 +16,7 @@ test-suite iterator_examples [ run indirect_iterator_example.cpp ] [ run permutation_iter_example.cpp ] [ run reverse_iterator_example.cpp ] + [ run projection_iterator_example.cpp ] [ run transform_iterator_example.cpp ] - ; + +; diff --git a/example/counting_iterator_example.cpp b/example/counting_iterator_example.cpp index c7d8add..80c66de 100644 --- a/example/counting_iterator_example.cpp +++ b/example/counting_iterator_example.cpp @@ -21,6 +21,13 @@ int main(int, char*[]) std::copy(first, last, std::ostream_iterator(std::cout, " ")); std::cout << std::endl; + // Example of using make_counting_iterator() + std::cout << "counting from -5 to 4:" << std::endl; + std::copy(boost::make_counting_iterator(-5), + boost::make_counting_iterator(5), + std::ostream_iterator(std::cout, " ")); + std::cout << std::endl; + // Example of using counting iterator to create an array of pointers. int N = 7; std::vector numbers; diff --git a/test/projection_iterator_example.cpp b/example/projection_iterator_example.cpp similarity index 98% rename from test/projection_iterator_example.cpp rename to example/projection_iterator_example.cpp index 3440fbf..0f51425 100644 --- a/test/projection_iterator_example.cpp +++ b/example/projection_iterator_example.cpp @@ -91,7 +91,7 @@ int main(int, char*[]) std::cout << std::endl; #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION - // Example of using make_const_projection_iterator() + // Example of using make_transform_iterator() // to print out the names in the personnel list again. std::copy( boost::make_transform_iterator(personnel_list.begin()) diff --git a/test/Jamfile b/test/Jamfile index fa1d6e1..9ca6870 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -50,12 +50,4 @@ test-suite iterator [ run permutation_iterator_test.cpp : : : # on ] - [ run iterator_adaptor_examples.cpp ] - [ run counting_iterator_example.cpp ] - [ run filter_iterator_example.cpp ] - [ run fun_out_iter_example.cpp ] - [ run indirect_iterator_example.cpp ] - [ run projection_iterator_example.cpp ] - [ run reverse_iterator_example.cpp ] - [ run transform_iterator_example.cpp ] ; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index b8e388b..e99bada 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -44,14 +44,4 @@ test-suite iterator [ run permutation_iterator_test.cpp : : : # on ] - [ run ../../utility/iterator_adaptor_examples.cpp ] - [ run ../../utility/counting_iterator_example.cpp ] - [ run ../../utility/filter_iterator_example.cpp ] - [ run ../../utility/fun_out_iter_example.cpp ] - [ run ../../utility/indirect_iterator_example.cpp ] - [ run ../../utility/projection_iterator_example.cpp ] - [ run ../../utility/reverse_iterator_example.cpp ] - [ run ../../utility/transform_iterator_example.cpp ] - [ run ../../utility/iterator_traits_test.cpp ] - [ run ../../utility/shared_iterator_test.cpp ] ; diff --git a/test/counting_iterator_example.cpp b/test/counting_iterator_example.cpp deleted file mode 100644 index 6bc341a..0000000 --- a/test/counting_iterator_example.cpp +++ /dev/null @@ -1,60 +0,0 @@ -// (C) Copyright Jeremy Siek 2000. -// 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) - - -#include -#include -#include -#include -#include -#include -#include - -int main(int, char*[]) -{ - // Example of using counting_iterator_generator - std::cout << "counting from 0 to 4:" << std::endl; - boost::counting_iterator first(0), last(4); - std::copy(first, last, std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Example of using make_counting_iterator() - std::cout << "counting from -5 to 4:" << std::endl; - std::copy(boost::make_counting_iterator(-5), - boost::make_counting_iterator(5), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Example of using counting iterator to create an array of pointers. -#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551)) - const -#endif - int N = 7; - std::vector numbers; - // Fill "numbers" array with [0,N) - std::copy( - boost::make_counting_iterator(0) - , boost::make_counting_iterator(N) - , std::back_inserter(numbers)); - - std::vector::iterator> pointers; - - // Use counting iterator to fill in the array of pointers. - // causes an ICE with MSVC6 - std::copy(boost::make_counting_iterator(numbers.begin()), - boost::make_counting_iterator(numbers.end()), - std::back_inserter(pointers)); - - // Use indirect iterator to print out numbers by accessing - // them through the array of pointers. - std::cout << "indirectly printing out the numbers from 0 to " - << N << std::endl; - std::copy(boost::make_indirect_iterator(pointers.begin()), - boost::make_indirect_iterator(pointers.end()), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - return 0; -} diff --git a/test/filter_iterator_example.cpp b/test/filter_iterator_example.cpp deleted file mode 100644 index 35e806f..0000000 --- a/test/filter_iterator_example.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// Example of using the filter iterator adaptor from -// boost/iterator_adaptors.hpp. - -// (C) Copyright Jeremy Siek 1999. -// 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) - -#include -#include -#include -#include -#include - -struct is_positive_number { - bool operator()(int x) { return 0 < x; } -}; - -int main() -{ - int numbers_[] = { 0, -1, 4, -3, 5, 8, -2 }; - const int N = sizeof(numbers_)/sizeof(int); - - typedef int* base_iterator; - base_iterator numbers(numbers_); - - // Example using make_filter_iterator() - std::copy(boost::make_filter_iterator(numbers, numbers + N), - boost::make_filter_iterator(numbers + N, numbers + N), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Example using filter_iterator - typedef boost::filter_iterator - FilterIter; - - is_positive_number predicate; - FilterIter filter_iter_first(predicate, numbers, numbers + N); - FilterIter filter_iter_last(predicate, numbers + N, numbers + N); - - std::copy(filter_iter_first, filter_iter_last, std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - // Another example using make_filter_iterator() - std::copy( - boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) - , numbers, numbers + N) - - , boost::make_filter_iterator( - std::bind2nd(std::greater(), -2) - , numbers + N, numbers + N) - - , std::ostream_iterator(std::cout, " ") - ); - - std::cout << std::endl; - - - return 0; -} diff --git a/test/fun_out_iter_example.cpp b/test/fun_out_iter_example.cpp deleted file mode 100644 index 233fe9b..0000000 --- a/test/fun_out_iter_example.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// (C) Copyright Jeremy Siek 2001. -// 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) - -// Revision History: - -// 27 Feb 2001 Jeremy Siek -// Initial checkin. - -#include -#include -#include - -#include - -struct string_appender -{ - string_appender(std::string& s) - : m_str(&s) - {} - - void operator()(const std::string& x) const - { - *m_str += x; - } - - std::string* m_str; -}; - -int main(int, char*[]) -{ - std::vector x; - x.push_back("hello"); - x.push_back(" "); - x.push_back("world"); - x.push_back("!"); - - std::string s = ""; - std::copy(x.begin(), x.end(), - boost::make_function_output_iterator(string_appender(s))); - - std::cout << s << std::endl; - - return 0; -} diff --git a/test/iterator_adaptor_examples.cpp b/test/iterator_adaptor_examples.cpp deleted file mode 100644 index 3bf90d3..0000000 --- a/test/iterator_adaptor_examples.cpp +++ /dev/null @@ -1,46 +0,0 @@ -// (C) Copyright Jeremy Siek 2000. -// 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) - - -#include -#include -#include -#include -#include - -int -main(int, char*[]) -{ - // This is a simple example of using the transform_iterators class to - // generate iterators that multiply the value returned by dereferencing - // the iterator. In this case we are multiplying by 2. - // Would be cooler to use lambda library in this example. - - int x[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; - - typedef std::binder1st< std::multiplies > Function; - - typedef boost::transform_iterator doubling_iterator; - - doubling_iterator i(x, std::bind1st(std::multiplies(), 2)), - i_end(x + sizeof(x)/sizeof(int), std::bind1st(std::multiplies(), 2)); - - std::cout << "multiplying the array by 2:" << std::endl; - while (i != i_end) - std::cout << *i++ << " "; - std::cout << std::endl; - - // Here is an example of counting from 0 to 5 using the integer_range class. - - boost::integer_range r(0,5); - - std::cout << "counting to from 0 to 4:" << std::endl; - std::copy(r.begin(), r.end(), std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - return 0; -} - - diff --git a/test/reverse_iterator_example.cpp b/test/reverse_iterator_example.cpp deleted file mode 100644 index e77b9ac..0000000 --- a/test/reverse_iterator_example.cpp +++ /dev/null @@ -1,47 +0,0 @@ -// (C) Copyright Jeremy Siek 2000. -// 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) - -#include -#include -#include -#include -#include - -//boost::detail::iterator_traits -int main(int, char*[]) -{ - char letters_[] = "hello world!"; - const int N = sizeof(letters_)/sizeof(char) - 1; - typedef char* base_iterator; - base_iterator letters(letters_); - - std::cout << "original sequence of letters:\t" - << letters_ << std::endl; - - std::sort(letters, letters + N); - - // Use reverse_iterator_generator to print a sequence - // of letters in reverse order. - - boost::reverse_iterator - reverse_letters_first(letters + N), - reverse_letters_last(letters); - - std::cout << "letters in descending order:\t"; - std::copy(reverse_letters_first, reverse_letters_last, - std::ostream_iterator(std::cout)); - std::cout << std::endl; - - // Use make_reverse_iterator() to print the sequence - // of letters in reverse-reverse order. - - std::cout << "letters in ascending order:\t"; - std::copy(boost::make_reverse_iterator(reverse_letters_last), - boost::make_reverse_iterator(reverse_letters_first), - std::ostream_iterator(std::cout)); - std::cout << std::endl; - - return 0; -} diff --git a/test/transform_iterator_example.cpp b/test/transform_iterator_example.cpp deleted file mode 100644 index 71e09f0..0000000 --- a/test/transform_iterator_example.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// (C) Copyright Jeremy Siek 2000. -// 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) - - -#include -#include -#include -#include - -// What a bummer. We can't use std::binder1st with transform iterator -// because it does not have a default constructor. Here's a version -// that does. - -namespace boost { - - template - class binder1st - : public std::unary_function { - protected: - Operation op; - typename Operation::first_argument_type value; - public: - binder1st() { } // this had to be added! - binder1st(const Operation& x, - const typename Operation::first_argument_type& y) - : op(x), value(y) {} - typename Operation::result_type - operator()(const typename Operation::second_argument_type& x) const { - return op(value, x); - } - }; - - template - inline binder1st bind1st(const Operation& op, const T& x) { - typedef typename Operation::first_argument_type arg1_type; - return binder1st(op, arg1_type(x)); - } - -} // namespace boost - -int -main(int, char*[]) -{ - // This is a simple example of using the transform_iterators class to - // generate iterators that multiply the value returned by dereferencing - // the iterator. In this case we are multiplying by 2. - // Would be cooler to use lambda library in this example. - - int x[] = { 1, 2, 3, 4, 5, 6, 7, 8 }; - const int N = sizeof(x)/sizeof(int); - - typedef boost::binder1st< std::multiplies > Function; - typedef boost::transform_iterator doubling_iterator; - - doubling_iterator i(x, boost::bind1st(std::multiplies(), 2)), - i_end(x + N, boost::bind1st(std::multiplies(), 2)); - - std::cout << "multiplying the array by 2:" << std::endl; - while (i != i_end) - std::cout << *i++ << " "; - std::cout << std::endl; - - std::cout << "adding 4 to each element in the array:" << std::endl; - - std::copy(boost::make_transform_iterator(x, boost::bind1st(std::plus(), 4)), - boost::make_transform_iterator(x + N, boost::bind1st(std::plus(), 4)), - std::ostream_iterator(std::cout, " ")); - std::cout << std::endl; - - return 0; -} - -