Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Make image nothrow move constructible #715

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions include/boost/gil/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
13 changes: 1 addition & 12 deletions include/boost/gil/image_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename View>
image_view(View const& view) : _dimensions(view.dimensions()), _pixels(view.pixels()) {}
Expand All @@ -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 <typename View>
bool operator==(View const &view) const
{
Expand Down
2 changes: 0 additions & 2 deletions include/boost/gil/locator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ class memory_based_2d_locator : public pixel_2d_locator_base<memory_based_2d_loc

memory_based_2d_locator(x_iterator xit, std::ptrdiff_t row_bytes) : _p(xit,row_bytes) {}
template <typename X> memory_based_2d_locator(const memory_based_2d_locator<X>& 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; }

Expand Down
2 changes: 1 addition & 1 deletion include/boost/gil/point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>::value) : x(px), y(py) {}

point operator<<(std::ptrdiff_t shift) const
{
Expand Down
13 changes: 13 additions & 0 deletions test/core/image/test_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::bgr8_pixel_t, true>,
gil::image<gil::bgr16_pixel_t, true>,
gil::image<gil::bgr32_pixel_t, true>,
gil::image<gil::rgb8_pixel_t, true>,
gil::image<gil::rgb16_pixel_t, true>,
gil::image<gil::rgb32_pixel_t, true>,
gil::image<gil::rgba8_pixel_t, true>,
gil::image<gil::rgba16_pixel_t, true>,
gil::image<gil::rgba32_pixel_t, true>
>;

template <typename Image, typename Generator>
auto generate_image(std::ptrdiff_t size_x, std::ptrdiff_t size_y, Generator&& generate) -> Image
{
Expand Down
1 change: 1 addition & 0 deletions test/core/image_view/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
45 changes: 45 additions & 0 deletions test/core/image_view/view_type_is_nothrow_moveable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// Copyright 2022 Marco Langer <langer.m86 at gmail dot com>
//
// 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 <boost/gil.hpp>

#include <boost/core/lightweight_test.hpp>
#include <boost/mp11.hpp>

#include <type_traits>

namespace gil = boost::gil;
namespace mp11 = boost::mp11;
namespace fixture = boost::gil::test::fixture;

struct test_move_nothrow
{
template <typename Image>
void operator()(Image const&)
{
using view_t = typename Image::view_t;

BOOST_ASSERT(std::is_nothrow_move_constructible<view_t>::value);
BOOST_ASSERT(std::is_nothrow_move_assignable<view_t>::value);
}

static void run()
{
mp11::mp_for_each<fixture::image_types>(test_move_nothrow{});
mp11::mp_for_each<fixture::rgb_planar_image_types>(test_move_nothrow{});
mp11::mp_for_each<fixture::rgb_interleaved_image_types>(test_move_nothrow{});
}
};

int main()
{
test_move_nothrow::run();

return ::boost::report_errors();
}