From f613cc4088e3330e5feba40c68c929da3858cf36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Fri, 21 Sep 2018 18:42:27 +0200 Subject: [PATCH] Remove re-assignment of functor from for_each_pixel (Trac 7092) The assignment was superfluous in general case and incorrect in specific case when the algorithm was given a lambda expression. The copy assignment operator is defined as deleted for lambda expressions. Add minimal test for for_each_pixel algorithm to verify it compiles with lambda expression. --- include/boost/gil/algorithm.hpp | 2 +- test/algorithm/Jamfile | 17 ++++++++++++++++ test/algorithm/for_each_pixel.cpp | 32 +++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 test/algorithm/Jamfile create mode 100644 test/algorithm/for_each_pixel.cpp diff --git a/include/boost/gil/algorithm.hpp b/include/boost/gil/algorithm.hpp index 5c8159450..c7226fddf 100644 --- a/include/boost/gil/algorithm.hpp +++ b/include/boost/gil/algorithm.hpp @@ -765,7 +765,7 @@ F for_each_pixel(const V& img, F fun) { return std::for_each(img.begin().x(), img.end().x(), fun); } else { for (std::ptrdiff_t y=0; y +# +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or +# copy at http://www.boost.org/LICENSE_1_0.txt) + +import testing ; + +project + : requirements + $(BOOST_ROOT) + .. + ; + +run for_each_pixel.cpp ; diff --git a/test/algorithm/for_each_pixel.cpp b/test/algorithm/for_each_pixel.cpp new file mode 100644 index 000000000..28c5210ab --- /dev/null +++ b/test/algorithm/for_each_pixel.cpp @@ -0,0 +1,32 @@ +// +// Copyright 2018 Mateusz Loskot +// +// Distributed under the Boost Software License, Version 1.0 +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// +#include +#include + +#include + +namespace gil = boost::gil; + +void test_lambda_expression() +{ + gil::gray8_pixel_t const gray128(128); + gil::gray8_image_t image(2, 2, gray128); + + int sum{0}; + gil::for_each_pixel(gil::view(image), [&sum](gil::gray8_pixel_t& p) { + sum += gil::at_c<0>(p); + }); + BOOST_TEST(sum == 2 * 2 * 128); +} + +int main() +{ + test_lambda_expression(); + + return boost::report_errors(); +}