From beab2e74ca4295c70c830b176a990c708080f524 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 5 Jun 2014 02:19:58 +0300 Subject: [PATCH] Added test for generator_iterator.hpp. --- generator_iterator_test.cpp | 63 +++++++++++++++++++++++++++++++++++++ test/Jamfile.v2 | 2 ++ 2 files changed, 65 insertions(+) create mode 100644 generator_iterator_test.cpp diff --git a/generator_iterator_test.cpp b/generator_iterator_test.cpp new file mode 100644 index 0000000..1c7a110 --- /dev/null +++ b/generator_iterator_test.cpp @@ -0,0 +1,63 @@ +// +// Copyright 2014 Peter Dimov +// +// 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 + +class X +{ +private: + + int v; + +public: + + typedef int result_type; + + X(): v( 0 ) + { + } + + int operator()() + { + return ++v; + } +}; + +template OutputIterator copy_n( InputIterator first, Size n, OutputIterator result ) +{ + while( n-- > 0 ) + { + *result++ = *first++; + } + + return result; +} + +void copy_test() +{ + X x; + boost::generator_iterator in( &x ); + + int const N = 4; + int v[ N ] = { 0 }; + + ::copy_n( in, 4, v ); + + BOOST_TEST_EQ( v[0], 1 ); + BOOST_TEST_EQ( v[1], 2 ); + BOOST_TEST_EQ( v[2], 3 ); + BOOST_TEST_EQ( v[3], 4 ); +} + +int main() +{ + copy_test(); + return boost::report_errors(); +} diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index cedc25e..3b7b9a1 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -45,5 +45,7 @@ test-suite utility [ compile-fail ../value_init_test_fail3.cpp ] [ compile-fail ../initialized_test_fail1.cpp ] [ compile-fail ../initialized_test_fail2.cpp ] + + [ run ../generator_iterator_test.cpp ] ;