[range] refactor use of examples in documentation to avoid redundancy

[SVN r82344]
This commit is contained in:
Nathan Ridge
2013-01-03 23:44:30 +00:00
parent 86b169dab3
commit 4a44cc75c9
49 changed files with 432 additions and 1226 deletions

View File

@ -8,6 +8,7 @@
//
// For more information, see http://www.boost.org/libs/range/
//
//[indexed_example
#include <boost/range/adaptor/indexed.hpp>
#include <boost/range/algorithm/copy.hpp>
#include <boost/assign.hpp>
@ -15,6 +16,7 @@
#include <iostream>
#include <vector>
//<-
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test.hpp>
@ -22,65 +24,72 @@
namespace
{
template<class Iterator>
void display_element_and_index(Iterator first, Iterator last)
template<class Iterator1, class Iterator2>
void check_element_and_index(
Iterator1 test_first,
Iterator1 test_last,
Iterator2 reference_first,
Iterator2 reference_last)
{
BOOST_CHECK_EQUAL( std::distance(test_first, test_last),
std::distance(reference_first, reference_last) );
int reference_index = 0;
Iterator1 test_it = test_first;
Iterator2 reference_it = reference_first;
for (; test_it != test_last; ++test_it, ++reference_it, ++reference_index)
{
for (Iterator it = first; it != last; ++it)
{
std::cout << "Element = " << *it << " Index = " << it.index() << std::endl;
}
BOOST_CHECK_EQUAL( *test_it, *reference_it );
BOOST_CHECK_EQUAL( test_it.index(), reference_index );
}
}
template<class SinglePassRange>
void display_element_and_index(const SinglePassRange& rng)
template<class SinglePassRange1, class SinglePassRange2>
void check_element_and_index(
const SinglePassRange1& test_rng,
const SinglePassRange2& reference_rng)
{
check_element_and_index(boost::begin(test_rng), boost::end(test_rng),
boost::begin(reference_rng), boost::end(reference_rng));
}
//->
template<class Iterator>
void display_element_and_index(Iterator first, Iterator last)
{
for (Iterator it = first; it != last; ++it)
{
display_element_and_index(boost::begin(rng), boost::end(rng));
std::cout << "Element = " << *it << " Index = " << it.index() << std::endl;
}
}
template<class Iterator1, class Iterator2>
void check_element_and_index(
Iterator1 test_first,
Iterator1 test_last,
Iterator2 reference_first,
Iterator2 reference_last)
{
BOOST_CHECK_EQUAL( std::distance(test_first, test_last),
std::distance(reference_first, reference_last) );
template<class SinglePassRange>
void display_element_and_index(const SinglePassRange& rng)
{
display_element_and_index(boost::begin(rng), boost::end(rng));
}
int reference_index = 0;
//<-
void indexed_example_test()
//->
//=int main(int argc, const char* argv[])
{
using namespace boost::assign;
using namespace boost::adaptors;
Iterator1 test_it = test_first;
Iterator2 reference_it = reference_first;
for (; test_it != test_last; ++test_it, ++reference_it, ++reference_index)
{
BOOST_CHECK_EQUAL( *test_it, *reference_it );
BOOST_CHECK_EQUAL( test_it.index(), reference_index );
}
}
std::vector<int> input;
input += 10,20,30,40,50,60,70,80,90;
template<class SinglePassRange1, class SinglePassRange2>
void check_element_and_index(
const SinglePassRange1& test_rng,
const SinglePassRange2& reference_rng)
{
check_element_and_index(boost::begin(test_rng), boost::end(test_rng),
boost::begin(reference_rng), boost::end(reference_rng));
}
display_element_and_index( input | indexed(0) );
void indexed_example_test()
{
using namespace boost::assign;
using namespace boost::adaptors;
std::vector<int> input;
input += 10,20,30,40,50,60,70,80,90;
display_element_and_index( input | indexed(0) );
check_element_and_index(
input | indexed(0),
input);
}
//= return 0;
//=}
//]
check_element_and_index(
input | indexed(0),
input);
}
}
boost::unit_test::test_suite*