Commit 41d1cbb8 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Fix tests and algorithms with new style iterators.

parent e7f83c67
......@@ -64,12 +64,15 @@ namespace mln {
namespace impl
{
template <typename I, typename OutputIterator>
template <typename I, typename J>
inline
OutputIterator
copy(const I& input, OutputIterator it)
void
copy(const I& input, J&& output)
{
return boost::copy(input.values(), it);
mln_viter(vin, vout, input, output);
mln_forall(vin, vout)
*vout = *vin;
}
}
......@@ -79,7 +82,7 @@ namespace mln {
OutputImage&
copy(const Image<InputImage>& input, Image<OutputImage>& output)
{
impl::copy(exact(input), std::begin(exact(output).values()));
impl::copy(exact(input), exact(output));
return exact(output);
}
......@@ -87,8 +90,8 @@ namespace mln {
OutputImage&&
copy(const Image<InputImage>& input, Image<OutputImage>&& output)
{
impl::copy(exact(input), std::begin(fwd_exact(output).values()));
return fwd_exact(output);
impl::copy(exact(input), exact(output));
return move_exact(output);
}
......
......@@ -36,9 +36,10 @@ namespace mln
{
// FIXME: add test for domain comparison
for (auto x: imzip(exact(ima1), exact(ima2)).values())
if (boost::get<0>(x) != boost::get<1>(x))
return false;
mln_viter(v1, v2, exact(ima1), exact(ima2));
mln_forall(v1, v2)
if (*v1 != *v2)
return false;
return true;
};
......
......@@ -36,15 +36,26 @@ namespace mln {
/**** Implementation ****/
/******************************************/
namespace impl
{
template <typename I, typename V>
void iota(I& ima, V v)
{
mln_viter(vout, ima);
mln_forall(vout)
*vout = v++;
}
}
template <typename I, typename Value>
inline
I&&
iota(Image<I>&& output_, Value val)
{
I&& output = fwd_exact(output_);
boost::iota(output.values(), val);
return std::forward<I>(output);
iota(output_, val);
return move_exact(output_);
}
template <typename I, typename Value>
......@@ -53,7 +64,7 @@ namespace mln {
iota(Image<I>& output_, Value val)
{
I& output = exact(output_);
boost::iota(output.values(), val);
impl::iota(output, val);
return output;
}
......
......@@ -45,14 +45,14 @@ namespace mln {
template <typename E>
inline
E&& fwd_exact(Object<E>& object)
E&& move_exact(Object<E>& object)
{
return static_cast<E&&>(object);
}
template <typename E>
inline
E&& fwd_exact(const Object<E>& object)
const E&& move_exact(const Object<E>& object)
{
return static_cast<E&&>(object);
}
......
......@@ -7,8 +7,8 @@
#include <mln/core/neighb2d.hpp>
#include <mln/core/wrt_offset.hpp>
#include <mln/core/forall.hpp>
#include <mln/core/pix_range_iterator_proxy.hpp>
//#include <mln/core/forall.hpp>
//#include <mln/core/pix_range_iterator_proxy.hpp>
#include <boost/range/numeric.hpp>
#include <boost/timer.hpp>
......
......@@ -2,12 +2,12 @@
#include <mln/core/grays.hpp>
#include <mln/core/algorithm/copy.hpp>
#include <mln/core/algorithm/equal.hpp>
#include <mln/core/algorithm/iota.hpp>
#define BOOST_TEST_MODULE Algorithm
#include <boost/test/unit_test.hpp>
#include <boost/range/algorithm/equal.hpp>
#include <boost/range/algorithm_ext/iota.hpp>
BOOST_AUTO_TEST_CASE(Copy)
......@@ -17,7 +17,8 @@ BOOST_AUTO_TEST_CASE(Copy)
image2d<uint8> ima(10, 10);
image2d<uint8> out(10, 10);
boost::iota(ima.values(), 0);
iota(ima, 0);
copy(ima, out);
BOOST_CHECK( boost::equal(ima.values(), out.values()) );
BOOST_CHECK( equal(ima, out) );
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment