From 875136885a560c52e4a8953a2046f494bbac8922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Fri, 12 Oct 2018 17:44:58 +0200 Subject: [PATCH] Fix conflict with std::fill_n and boost::range::fill_n (Trac 7189) Add minimal test for the std::fill and boost::array or std::array as pixel type. --- include/boost/gil/algorithm.hpp | 2 +- test/Jamfile | 1 + test/algorithm/Jamfile | 1 + test/algorithm/std_fill.cpp | 37 +++++++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test/algorithm/std_fill.cpp diff --git a/include/boost/gil/algorithm.hpp b/include/boost/gil/algorithm.hpp index dd21ec5953..4857aa2df6 100644 --- a/include/boost/gil/algorithm.hpp +++ b/include/boost/gil/algorithm.hpp @@ -355,7 +355,7 @@ void fill(boost::gil::iterator_from_2d first, boost::gil::iterator_from_2d0) { std::ptrdiff_t numToDo=std::min(n,(std::ptrdiff_t)(first.width()-first.x_pos())); - fill_n(first.x(), numToDo, val); + std::fill_n(first.x(), numToDo, val); first+=numToDo; n-=numToDo; } diff --git a/test/Jamfile b/test/Jamfile index 59a6f2c06e..3e7945ef7a 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -71,6 +71,7 @@ run image.cpp sample_image.cpp error_if.cpp : : gil_reference_checksums.txt ; run channel.cpp error_if.cpp ; run pixel.cpp error_if.cpp ; run pixel_iterator.cpp error_if.cpp ; +build-project algorithm ; build-project channel ; build-project image_view ; diff --git a/test/algorithm/Jamfile b/test/algorithm/Jamfile index f477d572d9..0155db584c 100644 --- a/test/algorithm/Jamfile +++ b/test/algorithm/Jamfile @@ -15,3 +15,4 @@ project ; run for_each_pixel.cpp ; +run std_fill.cpp ; diff --git a/test/algorithm/std_fill.cpp b/test/algorithm/std_fill.cpp new file mode 100644 index 0000000000..4bd8cee184 --- /dev/null +++ b/test/algorithm/std_fill.cpp @@ -0,0 +1,37 @@ +// +// 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 + +#include +#include +#include + +#include +#include + +namespace gil = boost::gil; + +template +void test_array_as_range() +{ + static_assert(ArrayPixel().size() == 2, "two-element array expected"); + + gil::image img(1, 1); + std::fill(gil::view(img).begin(), gil::view(img).end(), ArrayPixel{0, 1}); + BOOST_TEST(*gil::view(img).at(0,0) == (ArrayPixel{0, 1})); +} + +int main() +{ + test_array_as_range>(); + test_array_as_range>(); + + return boost::report_errors(); +}