diff --git a/include/boost/gil/image.hpp b/include/boost/gil/image.hpp index 86675b97d5..8c2f40535b 100644 --- a/include/boost/gil/image.hpp +++ b/include/boost/gil/image.hpp @@ -121,9 +121,8 @@ class image allocate_and_copy(view.dimensions(),view); } - // TODO Optimization: use noexcept (requires _view to be nothrow copy constructible) - image(image&& img) : - _view(img._view), + image(image&& img) noexcept : + _view(std::move(img._view)), _memory(img._memory), _align_in_bytes(img._align_in_bytes), _alloc(std::move(img._alloc)), diff --git a/include/boost/gil/image_view.hpp b/include/boost/gil/image_view.hpp index 048b285913..a51580759d 100644 --- a/include/boost/gil/image_view.hpp +++ b/include/boost/gil/image_view.hpp @@ -91,10 +91,7 @@ class image_view } }; - image_view() : _dimensions(0,0) {} - image_view(image_view const& img_view) - : _dimensions(img_view.dimensions()), _pixels(img_view.pixels()) - {} + image_view() noexcept : _dimensions(0,0) {} template image_view(View const& view) : _dimensions(view.dimensions()), _pixels(view.pixels()) {} @@ -115,14 +112,6 @@ class image_view return *this; } - image_view& operator=(image_view const& view) - { - // TODO: Self-assignment protection? - _pixels = view.pixels(); - _dimensions = view.dimensions(); - return *this; - } - template bool operator==(View const &view) const { diff --git a/include/boost/gil/locator.hpp b/include/boost/gil/locator.hpp index 776eedd336..fdb8b45bf1 100644 --- a/include/boost/gil/locator.hpp +++ b/include/boost/gil/locator.hpp @@ -260,8 +260,6 @@ class memory_based_2d_locator : public pixel_2d_locator_base memory_based_2d_locator(const memory_based_2d_locator& pl) : _p(pl._p) {} - memory_based_2d_locator(const memory_based_2d_locator& pl) : _p(pl._p) {} - memory_based_2d_locator& operator=(memory_based_2d_locator const& other) = default; bool operator==(const this_t& p) const { return _p==p._p; } diff --git a/include/boost/gil/point.hpp b/include/boost/gil/point.hpp index 5b9ffacf79..644578abc1 100644 --- a/include/boost/gil/point.hpp +++ b/include/boost/gil/point.hpp @@ -46,7 +46,7 @@ class point static constexpr std::size_t num_dimensions = 2; point() = default; - point(T px, T py) : x(px), y(py) {} + point(T px, T py) noexcept(std::is_nothrow_copy_constructible::value) : x(px), y(py) {} point operator<<(std::ptrdiff_t shift) const { diff --git a/test/core/image/test_fixture.hpp b/test/core/image/test_fixture.hpp index a7c95617ad..2df19aba77 100644 --- a/test/core/image/test_fixture.hpp +++ b/test/core/image/test_fixture.hpp @@ -78,6 +78,19 @@ using bit_aligned_image_types = std::tuple gil::bit_aligned_image3_type<6, 6, 6, gil::rgb_layout_t>::type >; +using rgb_planar_image_types = std::tuple +< + gil::image, + gil::image, + gil::image, + gil::image, + gil::image, + gil::image, + gil::image, + gil::image, + gil::image +>; + template auto generate_image(std::ptrdiff_t size_x, std::ptrdiff_t size_y, Generator&& generate) -> Image { diff --git a/test/core/image_view/Jamfile b/test/core/image_view/Jamfile index 03aecea5a7..6d5a9b2328 100644 --- a/test/core/image_view/Jamfile +++ b/test/core/image_view/Jamfile @@ -25,6 +25,7 @@ run iterator.cpp ; run planar_rgba_view.cpp ; run reverse_iterator.cpp ; run subimage_view.cpp ; +run view_type_is_nothrow_moveable.cpp ; run x_iterator.cpp ; run xy_locator.cpp ; run y_iterator.cpp ; diff --git a/test/core/image_view/view_type_is_nothrow_moveable.cpp b/test/core/image_view/view_type_is_nothrow_moveable.cpp new file mode 100644 index 0000000000..9dd7d53f14 --- /dev/null +++ b/test/core/image_view/view_type_is_nothrow_moveable.cpp @@ -0,0 +1,45 @@ +// +// Copyright 2022 Marco Langer +// +// 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 "core/image/test_fixture.hpp" + +#include + +#include +#include + +#include + +namespace gil = boost::gil; +namespace mp11 = boost::mp11; +namespace fixture = boost::gil::test::fixture; + +struct test_move_nothrow +{ + template + void operator()(Image const&) + { + using view_t = typename Image::view_t; + + BOOST_ASSERT(std::is_nothrow_move_constructible::value); + BOOST_ASSERT(std::is_nothrow_move_assignable::value); + } + + static void run() + { + mp11::mp_for_each(test_move_nothrow{}); + mp11::mp_for_each(test_move_nothrow{}); + mp11::mp_for_each(test_move_nothrow{}); + } +}; + +int main() +{ + test_move_nothrow::run(); + + return ::boost::report_errors(); +}