Commit ce707324 authored by Michaël Roynard's avatar Michaël Roynard
Browse files

Remove operators experimental::all experimental::any in favor of all_of

parent a11be2f2
......@@ -151,34 +151,6 @@ namespace mln::experimental
std::move(iffalse));
}
// FIXME: deprecated => replace with algorithm all_of
template <class I>
[[deprecated]] bool all(I ima) {
static_assert(mln::is_a<I, Image>());
static_assert(std::is_convertible<typename I::reference, bool>());
mln_foreach_new (auto&& val, ima.new_values())
if (!val)
return false;
return true;
}
template <class I>
[[deprecated]] bool any(I ima) {
static_assert(mln::is_a<I, Image>());
static_assert(std::is_convertible<typename I::reference, bool>());
mln_foreach_new (auto&& val, ima.new_values())
if (val)
return true;
return false;
}
#undef MLN_PRIVATE_DEFINE_UNARY_OPERATOR
#undef MLN_PRIVATE_DEFINE_BINARY_OPERATOR
......
#include <mln/core/algorithm/all_of.hpp>
#include <mln/core/algorithm/clone.hpp>
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/private/image_operators.hpp>
#include <mln/core/algorithm/clone.hpp>
#include <gtest/gtest.h>
......@@ -8,13 +9,13 @@ TEST(Core, Algorithm_Clone)
{
using namespace mln::experimental::ops;
const mln::image2d<uint8_t> ima = {{1,2,3}, {4,5,6}};
auto out = mln::experimental::clone(ima);
const mln::image2d<uint8_t> ima = {{1, 2, 3}, {4, 5, 6}};
auto out = mln::experimental::clone(ima);
// Writing does not affect ima
out({0,0}) = 69;
out({0, 0}) = 69;
const mln::image2d<uint8_t> ref = {{69,2,3}, {4,5,6}};
ASSERT_TRUE(mln::experimental::all(out == ref));
const mln::image2d<uint8_t> ref = {{69, 2, 3}, {4, 5, 6}};
ASSERT_TRUE(mln::all_of(out == ref));
}
#include <mln/core/algorithm/all_of.hpp>
#include <mln/core/algorithm/fill.hpp>
#include <mln/core/grays.hpp>
#include <mln/core/image/image2d.hpp>
......@@ -27,5 +28,5 @@ TEST(Core, Algorithm_Exp_Fill)
mln::image2d<std::uint8_t> ima(10, 10);
mln::fill(ima, 69);
ASSERT_TRUE(mln::experimental::all(ima == 69));
ASSERT_TRUE(mln::all_of(ima == 69));
}
#include <mln/core/algorithm/all_of.hpp>
#include <mln/core/algorithm/for_each.hpp>
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/private/image_operators.hpp>
#include <mln/core/algorithm/for_each.hpp>
#include <utility>
......@@ -10,16 +11,12 @@ TEST(Core, Algorithm_For_Each)
{
using namespace mln::experimental::ops;
mln::image2d<uint8_t> ima =
{ {1, 2, 3},
{4, 5, 6} };
mln::image2d<uint8_t> ima = {{1, 2, 3}, {4, 5, 6}};
mln::image2d<uint8_t> ref =
{ {2, 3, 4},
{5, 6, 7} };
mln::image2d<uint8_t> ref = {{2, 3, 4}, {5, 6, 7}};
mln::experimental::for_each(ima, [](uint8_t& x) { x += 1; });
ASSERT_TRUE(mln::experimental::all(ima == ref));
ASSERT_TRUE(mln::all_of(ima == ref));
}
......@@ -27,13 +24,11 @@ TEST(Core, Algorithm_For_Each_Side_Effects)
{
using namespace mln::experimental::ops;
mln::image2d<uint8_t> ima =
{ {1, 2, 3},
{4, 5, 6} };
mln::image2d<uint8_t> ima = {{1, 2, 3}, {4, 5, 6}};
int sum = 0;
auto g = [&sum](uint8_t v) { sum += v; };
int sum = 0;
auto g = [&sum](uint8_t v) { sum += v; };
mln::experimental::for_each(ima, g);
ASSERT_EQ(6 * 7 / 2, sum);
}
#include <mln/core/image/image2d.hpp>
#include <mln/core/algorithm/all_of.hpp>
#include <mln/core/algorithm/generate.hpp>
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/private/image_operators.hpp>
#include <gtest/gtest.h>
......@@ -9,13 +10,13 @@ TEST(Core, Algorithm_Generate)
using namespace mln::experimental::ops;
// Another impl of mln::iota
int i = 1;
auto gen = [&i](){ return i++; };
int i = 1;
auto gen = [&i]() { return i++; };
mln::image2d<uint8_t> out(3, 4);
mln::experimental::generate(out, gen);
mln::image2d<uint8_t> ref = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
ASSERT_TRUE(mln::experimental::all(ref == out));
ASSERT_TRUE(mln::all_of(ref == out));
}
#include <mln/core/image/image2d.hpp>
#include <mln/core/algorithm/all_of.hpp>
#include <mln/core/algorithm/iota.hpp>
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/private/image_operators.hpp>
......@@ -14,5 +15,5 @@ TEST(Core, Algorithm_Iota)
mln::image2d<uint8_t> ref = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
ASSERT_TRUE(mln::experimental::all(ref == out));
ASSERT_TRUE(mln::all_of(ref == out));
}
#include <mln/core/algorithm/all_of.hpp>
#include <mln/core/algorithm/transform.hpp>
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/private/image_operators.hpp>
#include <mln/core/algorithm/transform.hpp>
#include <utility>
......@@ -10,16 +11,12 @@ TEST(Core, Algorithm_Transform)
{
using namespace mln::experimental::ops;
mln::image2d<uint8_t> ima =
{ {1, 2, 3},
{4, 5, 6} };
mln::image2d<uint8_t> ima = {{1, 2, 3}, {4, 5, 6}};
mln::image2d<uint8_t> ref =
{ {2, 3, 4},
{5, 6, 7} };
mln::image2d<uint8_t> ref = {{2, 3, 4}, {5, 6, 7}};
auto out = mln::experimental::transform(ima, [](uint8_t x) -> uint8_t { return x + 1; });
ASSERT_TRUE(mln::experimental::all(out == ref));
ASSERT_TRUE(mln::all_of(out == ref));
}
......@@ -29,12 +26,10 @@ TEST(Core, Algorithm_Transform_LValue)
using V = std::pair<uint8_t, uint8_t>;
mln::image2d<V> ima = {{{1, 0}, {2, 0}, {3, 0}}, {{4, 0}, {5, 0}, {6, 0}}};
mln::image2d<V> ima = {{{1, 0}, {2, 0}, {3, 0}}, {{4, 0}, {5, 0}, {6, 0}}};
mln::image2d<uint8_t> ref = {{1, 2, 3}, {4, 5, 6}};
mln::image2d<uint8_t> out = mln::experimental::transform(ima, &V::first);
ASSERT_TRUE(mln::experimental::all(out == ref));
ASSERT_TRUE(mln::all_of(out == ref));
}
......@@ -113,7 +113,7 @@ TEST(Core, UnaryOperator)
image2d<int> ref = {{-1, -2, -3}, {-4, -5, -6}};
auto g = -ima;
ASSERT_TRUE(mln::experimental::all(g == ref));
ASSERT_TRUE(mln::all_of(g == ref));
}
TEST(Core, BinaryOperator_SameTypes)
......@@ -132,9 +132,9 @@ TEST(Core, BinaryOperator_SameTypes)
static_assert(std::is_same_v<decltype(g2)::value_type, uint8_t>);
static_assert(std::is_same_v<decltype(g3)::value_type, uint8_t>);
ASSERT_TRUE(mln::experimental::all(g1 == ref));
ASSERT_TRUE(mln::experimental::all(g2 == ref));
ASSERT_TRUE(mln::experimental::all(g3 == ref));
ASSERT_TRUE(mln::all_of(g1 == ref));
ASSERT_TRUE(mln::all_of(g2 == ref));
ASSERT_TRUE(mln::all_of(g3 == ref));
}
TEST(Core, BinaryOperators_MixedTypes)
......@@ -157,9 +157,9 @@ TEST(Core, BinaryOperators_MixedTypes)
static_assert(std::is_same_v<decltype(g2)::value_type, RType>);
static_assert(std::is_same_v<decltype(g3)::value_type, RType>);
ASSERT_TRUE(mln::experimental::all(g1 == ref));
ASSERT_TRUE(mln::experimental::all(g2 == ref));
ASSERT_TRUE(mln::experimental::all(g3 == ref));
ASSERT_TRUE(mln::all_of(g1 == ref));
ASSERT_TRUE(mln::all_of(g2 == ref));
ASSERT_TRUE(mln::all_of(g3 == ref));
}
......@@ -193,10 +193,10 @@ TEST(Core, IfElse)
static_assert(std::is_same_v<image_reference_t<decltype(f4)>, uint8_t>);
// FIXME: issue https://github.com/ericniebler/range-v3/issues/996 with gcc8.2
// ASSERT_TRUE(mln::experimental::all(f1 == ref_f1));
// ASSERT_TRUE(mln::experimental::all(f2 == ref_f2));
// ASSERT_TRUE(mln::experimental::all(f3 == ref_f3));
// ASSERT_TRUE(mln::experimental::all(f4 == ref_f4));
// ASSERT_TRUE(mln::all_of(f1 == ref_f1));
// ASSERT_TRUE(mln::all_of(f2 == ref_f2));
// ASSERT_TRUE(mln::all_of(f3 == ref_f3));
// ASSERT_TRUE(mln::all_of(f4 == ref_f4));
image2d<uint8_t> ref_x = {{1, 2, 3}, //
......@@ -207,8 +207,8 @@ TEST(Core, IfElse)
// FIXME: issue https://github.com/ericniebler/range-v3/issues/996 with gcc8.2
// mln::fill(f2, 42);
// ASSERT_TRUE(mln::experimental::all(x == ref_x));
// ASSERT_TRUE(mln::experimental::all(y == ref_y));
// ASSERT_TRUE(mln::all_of(x == ref_x));
// ASSERT_TRUE(mln::all_of(y == ref_y));
}
TEST(Core, Where)
......
#include <mln/core/algorithm/all_of.hpp>
#include <mln/core/algorithm/fill.hpp>
#include <mln/core/algorithm/iota.hpp>
#include <mln/core/concept/new/archetype/image.hpp>
......@@ -236,6 +237,6 @@ TEST(Core, Transformed2Image_transform_byval_chain)
[[maybe_unused]] auto out = view::transform(y, ima2, [](int a, int b) { return a + b; });
// FIXME: issue https://github.com/ericniebler/range-v3/issues/996 with gcc8.2
// [[maybe_unused]] auto z = mln::experimental::all(out);
// [[maybe_unused]] auto z = mln::all_of(out);
}
}
#include <mln/core/algorithm/all_of.hpp>
#include <mln/core/algorithm/fill.hpp>
#include <mln/core/algorithm/iota.hpp>
#include <mln/core/grays.hpp>
......@@ -43,8 +44,8 @@ TEST(Core, ZipImage_Mixed_writable)
fill(x, std::make_tuple(2, 4));
ASSERT_TRUE(mln::experimental::all(ima == 2));
ASSERT_TRUE(mln::experimental::all(ima2 == 4));
ASSERT_TRUE(mln::all_of(ima == 2));
ASSERT_TRUE(mln::all_of(ima2 == 4));
}
......@@ -71,8 +72,8 @@ TEST(Core, ZipImage_Value_Iteration_1)
::ranges::for_each(x.new_values(), [](std::tuple<int&, uint16&> w) { w = std::make_tuple(2, 4); });
ASSERT_TRUE(mln::experimental::all(a == 2));
ASSERT_TRUE(mln::experimental::all(b == 4));
ASSERT_TRUE(mln::all_of(a == 2));
ASSERT_TRUE(mln::all_of(b == 4));
}
TEST(Core, ZipImage_Pixel_Iteration_1)
......@@ -97,8 +98,8 @@ TEST(Core, ZipImage_Pixel_Iteration_1)
::ranges::for_each(x.new_pixels(), [](auto px) { px.val() = std::make_tuple(2, 4); });
ASSERT_TRUE(mln::experimental::all(a == 2));
ASSERT_TRUE(mln::experimental::all(b == 4));
ASSERT_TRUE(mln::all_of(a == 2));
ASSERT_TRUE(mln::all_of(b == 4));
}
TEST(Core, ZipImage_Value_Iteration_2)
......@@ -151,5 +152,5 @@ TEST(Core, ZipImage_Temporary_usage)
mln_foreach_new (auto w, x.new_values())
std::get<0>(w) = std::get<1>(w);
ASSERT_TRUE(mln::experimental::all(ima == make_image()));
ASSERT_TRUE(mln::all_of(ima == make_image()));
}
Supports Markdown
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