2010-03-28 16:08:35 +00:00
|
|
|
// Boost.Range library
|
|
|
|
//
|
|
|
|
// Copyright Thorsten Ottosen 2006. 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)
|
|
|
|
//
|
|
|
|
// For more information, see http://www.boost.org/libs/range/
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <boost/range/combine.hpp>
|
|
|
|
#include <boost/test/test_tools.hpp>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
2010-04-05 14:12:24 +00:00
|
|
|
#include <boost/tuple/tuple.hpp>
|
2010-03-28 16:08:35 +00:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
struct add
|
|
|
|
{
|
|
|
|
template< class T >
|
|
|
|
int operator()( const T& tuple ) const
|
|
|
|
{
|
|
|
|
return boost::get<0>(tuple) + boost::get<1>(tuple);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template< class CombinedRng >
|
2010-04-05 14:12:24 +00:00
|
|
|
void apply( const CombinedRng& r )
|
2010-03-28 16:08:35 +00:00
|
|
|
{
|
|
|
|
std::vector<int> v;
|
2010-04-05 14:12:24 +00:00
|
|
|
typedef BOOST_DEDUCED_TYPENAME boost::range_iterator<const CombinedRng>::type iterator_t;
|
|
|
|
|
|
|
|
iterator_t e = boost::end(r);
|
|
|
|
for (iterator_t i = boost::begin(r); i != e; ++i)
|
2010-03-28 16:08:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_combine()
|
|
|
|
{
|
|
|
|
std::vector<int> v1, v2, v3;
|
2010-04-05 14:12:24 +00:00
|
|
|
for (int i = 1; i <= 4; ++i)
|
|
|
|
{
|
|
|
|
v1.push_back(i);
|
|
|
|
v2.push_back(i);
|
|
|
|
}
|
2010-03-28 16:08:35 +00:00
|
|
|
|
|
|
|
int i1, i2;
|
|
|
|
BOOST_FOREACH( boost::tie( i1, i2 ), boost::combine(v1,v2) )
|
|
|
|
{
|
|
|
|
v3.push_back( i1 + i2 );
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOST_CHECK_EQUAL( v3.size(), v1.size() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using boost::unit_test::test_suite;
|
|
|
|
|
|
|
|
test_suite* init_unit_test_suite( int argc, char* argv[] )
|
|
|
|
{
|
|
|
|
test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
|
|
|
|
|
|
|
|
test->add( BOOST_TEST_CASE( &test_combine ) );
|
|
|
|
|
|
|
|
return test;
|
|
|
|
}
|
|
|
|
|
|
|
|
|