/*
* Author:
* Stjepan Rajko
* Arts, Media and Engineering Program
* Arizona State University
*
* Copyright 2008 Arizona Board of Regents.
*
* This file is part of the Arts, Media and Engineering Library Assortment (AMELiA).
*
* AMELiA is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* AMELiA is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AMELiA.
* If not, see .
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define BOOST_TEST_MAIN
#include
struct deep_copy
{
template
void operator()(Element &element, const Slice &slice) const
{
element.resize(slice[0].size());
std::copy(boost::begin(slice[0]), boost::end(slice[0]), boost::begin(element));
}
};
struct copy
{
template
void operator()(Element &element, const Slice &slice) const
{
element.resize(slice.size());
std::copy(boost::begin(slice), boost::end(slice), boost::begin(element));
}
};
//------------------------------------------------------------
//------------------------------------------------------------
struct weird_warning
{
template
void operator()(Element &element, const Slice &slice) const
{
*boost::begin(slice[0]); // no warning
slice[0][0]; // warning: operator[](outer) returning reference to temporary
}
};
//------------------------------------------------------------
//------------------------------------------------------------
BOOST_AUTO_TEST_CASE( test )
{
typedef boost::fusion::vector element;
std::vector range_of_sequence;
boost::fusion::vector, std::vector > sequence_of_range;
range_of_sequence.push_back(element(1, 5.5));
range_of_sequence.push_back(element(2, 6.5));
ame::utility::for_each_element_and_slice<0>(sequence_of_range, range_of_sequence, copy());
BOOST_CHECK_EQUAL(
boost::fusion::at_c<0>(range_of_sequence[0]),
boost::fusion::at_c<0>(sequence_of_range)[0]);
BOOST_CHECK_EQUAL(
boost::fusion::at_c<0>(range_of_sequence[1]),
boost::fusion::at_c<0>(sequence_of_range)[1]);
BOOST_CHECK_EQUAL(
boost::fusion::at_c<1>(range_of_sequence[0]),
boost::fusion::at_c<1>(sequence_of_range)[0]);
BOOST_CHECK_EQUAL(
boost::fusion::at_c<1>(range_of_sequence[1]),
boost::fusion::at_c<1>(sequence_of_range)[1]);
//------------------------------------------------------------
//------------------------------------------------------------
std::vector > range_range_of_sequence;
//------------------------------------------------------------
//------------------------------------------------------------
range_range_of_sequence.push_back(range_of_sequence);
boost::fusion::at_c<0>(sequence_of_range).clear();
boost::fusion::at_c<1>(sequence_of_range).clear();
ame::utility::for_each_element_and_slice<1>(sequence_of_range, range_range_of_sequence, deep_copy());
BOOST_CHECK_EQUAL(
boost::fusion::at_c<0>(range_of_sequence[0]),
boost::fusion::at_c<0>(sequence_of_range)[0]);
BOOST_CHECK_EQUAL(
boost::fusion::at_c<0>(range_of_sequence[1]),
boost::fusion::at_c<0>(sequence_of_range)[1]);
BOOST_CHECK_EQUAL(
boost::fusion::at_c<1>(range_of_sequence[0]),
boost::fusion::at_c<1>(sequence_of_range)[0]);
BOOST_CHECK_EQUAL(
boost::fusion::at_c<1>(range_of_sequence[1]),
boost::fusion::at_c<1>(sequence_of_range)[1]);
//------------------------------------------------------------
//------------------------------------------------------------
ame::utility::for_each_element_and_slice<1>(sequence_of_range, range_range_of_sequence, weird_warning());
//------------------------------------------------------------
//------------------------------------------------------------
} // int main(int, char* [])
//]