From c92c99ed0b8c176bf19e82e1ba84c21de7e706b4 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Thu, 7 Sep 2017 11:35:14 +0300 Subject: [PATCH] Enabled forEach for const Mats --- modules/core/include/opencv2/core/mat.inl.hpp | 2 +- modules/core/test/test_mat.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index 84452881e9..2ef7aec3c6 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -1214,7 +1214,7 @@ void Mat::forEach(const Functor& operation) { template inline void Mat::forEach(const Functor& operation) const { // call as not const - (const_cast(this))->forEach(operation); + (const_cast(this))->forEach<_Tp>(operation); } template inline diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 70675127ba..6c2ab85c3c 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -671,6 +671,13 @@ struct InitializerFunctor5D{ } }; +template +struct EmptyFunctor +{ + void operator()(const Pixel &, const int *) const {} +}; + + void Core_ArrayOpTest::run( int /* start_from */) { int errcount = 0; @@ -799,6 +806,17 @@ void Core_ArrayOpTest::run( int /* start_from */) } } + // test const cv::Mat::forEach + { + const Mat a(10, 10, CV_32SC3); + Mat b(10, 10, CV_32SC3); + const Mat & c = b; + a.forEach(EmptyFunctor()); + b.forEach(EmptyFunctor()); + c.forEach(EmptyFunctor()); + // tests compilation, no runtime check is needed + } + RNG rng; const int MAX_DIM = 5, MAX_DIM_SZ = 10; // sparse matrix operations