Commit 125d1978 authored by Edwin Carlinet's avatar Edwin Carlinet
Browse files

Fix rows(...) to take only non-temporaries and fix algoithms.

parent 74c8b8cd
......@@ -66,7 +66,8 @@ namespace mln
static_assert(mln::is_a<InputImage, Image>());
auto a = accu::make_accumulator(exact(accu), image_value_t<InputImage>());
for (auto row : mln::ranges::rows(input.new_values()))
auto&& vals = input.new_values();
for (auto row : mln::ranges::rows(vals))
for (auto&& v : row)
a.take(v);
return ex(a);
......@@ -78,7 +79,8 @@ namespace mln
{
static_assert(mln::is_a<InputImage, Image>());
for (auto row : mln::ranges::rows(input.new_values()))
auto&& vals = input.new_values();
for (auto row : mln::ranges::rows(vals))
for (auto&& v : row)
init = op(init, v);
......
......@@ -29,7 +29,8 @@ namespace mln
static_assert(mln::is_a<InputImage, Image>());
static_assert(::ranges::Predicate<UnaryPredicate, image_reference_t<InputImage>>());
for (auto r : ranges::rows(input.new_values()))
auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
if (::ranges::any_of(r, p))
return true;
return false;
......@@ -41,7 +42,8 @@ namespace mln
static_assert(mln::is_a<InputImage, Image>());
static_assert(std::is_convertible_v<image_reference_t<InputImage>, bool>);
for (auto r : ranges::rows(input.new_values()))
auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
for (auto&& v : r)
if (v)
return true;
......
......@@ -113,10 +113,10 @@ namespace mln
static_assert(mln::is_a<OutputImage, Image>());
static_assert(std::is_convertible_v<image_value_t<InputImage>, image_value_t<OutputImage>>);
auto input_rows = ranges::rows(input.new_values());
auto output_rows = ranges::rows(output.new_values());
auto&& ivals = input.new_values();
auto&& ovals = output.new_values();
for (auto [r1, r2] : ranges::view::zip(input_rows, output_rows))
for (auto [r1, r2] : ranges::view::zip(ranges::rows(ivals), ranges::rows(ovals)))
::ranges::copy(r1, ::ranges::begin(r2));
}
} // namespace experimental
......
......@@ -29,7 +29,8 @@ namespace mln
static_assert(mln::is_a<InputImage, Image>());
static_assert(::ranges::Invocable<UnaryFunction, image_reference_t<InputImage>>());
for (auto r : ranges::rows(input.new_values()))
auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
::ranges::for_each(r, f);
}
} // namespace experimental
......
......@@ -23,7 +23,8 @@ namespace mln
static_assert(mln::is_a<OutputImage, Image>());
static_assert(std::is_convertible_v<std::invoke_result_t<Generator>, image_value_t<OutputImage>>);
for (auto row : mln::ranges::rows(output.new_values()))
auto&& vals = output.new_values();
for (auto row : mln::ranges::rows(vals))
for (auto& v : row)
v = g();
}
......
......@@ -73,7 +73,8 @@ namespace mln
static_assert(mln::is_a<OutputImage, Image>());
static_assert(std::is_convertible_v<Value, image_value_t<OutputImage>>);
for (auto row : mln::ranges::rows(output.new_values()))
auto&& vals = output.new_values();
for (auto row : mln::ranges::rows(vals))
for (auto& v : row)
v = val++;
}
......
......@@ -29,7 +29,8 @@ namespace mln
static_assert(mln::is_a<InputImage, Image>());
static_assert(::ranges::Predicate<UnaryPredicate, image_reference_t<InputImage>>());
for (auto r : ranges::rows(input.new_values()))
auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
if (!::ranges::none_of(r, p))
return false;
return true;
......@@ -41,7 +42,8 @@ namespace mln
static_assert(mln::is_a<InputImage, Image>());
static_assert(std::is_convertible_v<image_reference_t<InputImage>, bool>);
for (auto r : ranges::rows(input.new_values()))
auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
for (auto&& v : r)
if (v)
return false;
......
......@@ -82,10 +82,9 @@ namespace mln
static_assert(mln::is_a<OutputImage, Image>());
static_assert(std::is_convertible_v<image_value_t<InputImage>, image_value_t<OutputImage>>);
auto input_rows = ranges::rows(src.new_pixels());
for (auto r : input_rows)
for (auto px : r)
auto&& pixels = src.new_pixels();
for (auto row : ranges::rows(pixels))
for (auto px : row)
dest(px.point()) = px.val();
}
......
......@@ -122,9 +122,9 @@ namespace mln
mln_entering("mln::experimental::transform");
mln_precondition(in.domain() == out.domain());
auto input_rows = ranges::rows(in.new_values());
auto output_rows = ranges::rows(out.new_values());
for (auto [r1, r2] : ranges::view::zip(input_rows, output_rows))
auto&& ivals = in.new_values();
auto&& ovals = out.new_values();
for (auto [r1, r2] : ranges::view::zip(ranges::rows(ivals), ranges::rows(ovals)))
::ranges::transform(r1, ::ranges::begin(r2), f);
}
......
......@@ -15,6 +15,7 @@ namespace mln::ranges
template <class R, typename = std::enable_if_t<is_segmented_range_v<std::remove_reference_t<R>>>>
decltype(auto) rows(R&& rng) // decltype for perfect forwarding
{
static_assert(std::is_lvalue_reference<R>(), "Cannot apply on a temporary range.");
return rng.rows();
}
......
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