any_of.hpp 1.32 KB
Newer Older
Edwin Carlinet's avatar
Edwin Carlinet committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#pragma once

#include <mln/core/image/image.hpp>
#include <mln/core/rangev3/rows.hpp>
#include <range/v3/algorithm/any_of.hpp>
#include <range/v3/utility/functional.hpp>

namespace mln
{

  namespace experimental
  {
    template <class InputImage, class UnaryPredicate>
    bool any_of(InputImage input, UnaryPredicate p);

    template <class InputImage>
    bool any_of(InputImage input);
  }

  /******************/
  /* Implem         */
  /******************/

  namespace experimental
  {
    template <class InputImage, class UnaryPredicate>
    bool any_of(InputImage input, UnaryPredicate p)
    {
      static_assert(mln::is_a<InputImage, Image>());
      static_assert(::ranges::Predicate<UnaryPredicate, image_reference_t<InputImage>>());

32
33
      auto&& vals = input.new_values();
      for (auto r : ranges::rows(vals))
Edwin Carlinet's avatar
Edwin Carlinet committed
34
35
36
37
38
39
40
41
42
43
44
        if (::ranges::any_of(r, p))
          return true;
      return false;
    }

    template <class InputImage>
    bool any_of(InputImage input)
    {
      static_assert(mln::is_a<InputImage, Image>());
      static_assert(std::is_convertible_v<image_reference_t<InputImage>, bool>);

45
46
      auto&& vals = input.new_values();
      for (auto r : ranges::rows(vals))
Edwin Carlinet's avatar
Edwin Carlinet committed
47
48
49
50
51
52
53
54
55
        for (auto&& v : r)
          if (v)
            return true;
      return false;
    }

  } // namespace experimental
} // namespace mln