From: Maksim Shabunin Date: Thu, 7 Sep 2017 08:35:14 +0000 (+0300) Subject: Enabled forEach for const Mats X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~646^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c92c99ed0b8c176bf19e82e1ba84c21de7e706b4;p=platform%2Fupstream%2Fopencv.git Enabled forEach for const Mats --- diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index 8445288..2ef7aec 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 7067512..6c2ab85 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