diff --git a/include/boost/gil/concepts/point.hpp b/include/boost/gil/concepts/point.hpp index fb0daed7e6..a1028a39b6 100644 --- a/include/boost/gil/concepts/point.hpp +++ b/include/boost/gil/concepts/point.hpp @@ -1,5 +1,6 @@ // // Copyright 2005-2007 Adobe Systems Incorporated +// Copyright 2026 Samuel Debionne // // Distributed under the Boost Software License, Version 1.0 // See accompanying file LICENSE_1_0.txt or copy at @@ -8,9 +9,13 @@ #ifndef BOOST_GIL_CONCEPTS_POINT_HPP #define BOOST_GIL_CONCEPTS_POINT_HPP -#include -#include +#include +#if !defined(BOOST_GIL_HAS_CONCEPTS) +# error C++ 20 standard required. +#endif + +#include #include #if defined(BOOST_CLANG) @@ -27,7 +32,7 @@ namespace boost { namespace gil { // Forward declarations -template +template class point; template @@ -58,33 +63,21 @@ T& axis_value(point& p); /// \ingroup PointConcept /// template -struct PointNDConcept +concept PointNDConcept = requires(P point, typename P::template axis<0>::coord_t ft, typename P::template axis::coord_t lt) { - void constraints() - { - gil_function_requires>(); - - using value_type = typename P::value_type; - ignore_unused_variable_warning(value_type{}); - - static const std::size_t N = P::num_dimensions; - ignore_unused_variable_warning(N); - using FT = typename P::template axis<0>::coord_t; - using LT = typename P::template axis::coord_t; - FT ft = gil::axis_value<0>(point); - axis_value<0>(point) = ft; - LT lt = axis_value(point); - axis_value(point) = lt; - - //value_type v=point[0]; - //ignore_unused_variable_warning(v); - } - P point; + typename P::value_type; + requires std::regular; + + P::num_dimensions; + ft = gil::axis_value<0>(point); + axis_value<0>(point) = ft; + lt = axis_value(point); + axis_value(point) = lt; }; /// \brief 2-dimensional point concept /// \code -/// concept Point2DConcept : PointNDConcept +/// concept Point2DConcept : PointNDConceptN /// { /// where num_dimensions == 2; /// where SameType::type, axis<1>::type>; @@ -100,16 +93,11 @@ struct PointNDConcept /// \ingroup PointConcept /// template -struct Point2DConcept +concept Point2DConcept = PointNDConcept

&& requires(P point) { - void constraints() - { - gil_function_requires>(); - static_assert(P::num_dimensions == 2, ""); - point.x = point.y; - point[0] = point[1]; - } - P point; + requires P::num_dimensions == 2; + point.x = point.y; + point[0] = point[1]; }; }} // namespace boost::gil diff --git a/include/boost/gil/detail/config.hpp b/include/boost/gil/detail/config.hpp new file mode 100644 index 0000000000..04bea63527 --- /dev/null +++ b/include/boost/gil/detail/config.hpp @@ -0,0 +1,23 @@ +// +// Copyright 2026 Samuel Debionne +// +// 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 +// +#ifndef BOOST_GIL_DETAIL_CONFIG_HPP +#define BOOST_GIL_DETAIL_CONFIG_HPP + +#include + +#if !defined(BOOST_NO_CXX20_HDR_CONCEPTS) && defined(__cpp_lib_concepts) +#define BOOST_GIL_HAS_CONCEPTS +#endif + +#ifdef BOOST_GIL_HAS_CONCEPTS +#define BOOST_GIL_CONSTRAINT(C) C +#else +#define BOOST_GIL_CONSTRAINT(C) typename +#endif + +#endif \ No newline at end of file diff --git a/include/boost/gil/detail/std_common_type.hpp b/include/boost/gil/detail/std_common_type.hpp index 305f095ad3..2ca15b2087 100644 --- a/include/boost/gil/detail/std_common_type.hpp +++ b/include/boost/gil/detail/std_common_type.hpp @@ -34,6 +34,9 @@ struct std_common_type >::type; }; +template +using std_common_type_t = std_common_type::type; + }}} // namespace boost::gil::detail #endif diff --git a/include/boost/gil/locator.hpp b/include/boost/gil/locator.hpp index f0e7c20366..f318ef25de 100644 --- a/include/boost/gil/locator.hpp +++ b/include/boost/gil/locator.hpp @@ -24,7 +24,7 @@ template std::ptrdiff_t memunit_step(const P*); template P* memunit_advanced(const P* p, std::ptrdiff_t diff); template P& memunit_advanced_ref(P* p, std::ptrdiff_t diff); template struct iterator_add_deref; -template class point; +template class point; namespace detail { // helper class specialized for each axis of pixel_2d_locator template class locator_axis; diff --git a/include/boost/gil/point.hpp b/include/boost/gil/point.hpp index 5b9ffacf79..5ba28da397 100644 --- a/include/boost/gil/point.hpp +++ b/include/boost/gil/point.hpp @@ -9,11 +9,11 @@ #define BOOST_GIL_POINT_HPP #include +#include #include -#include - #include +#include #include namespace boost { namespace gil { @@ -31,7 +31,7 @@ namespace boost { namespace gil { /// \brief 2D point both axes of which have the same dimension type /// \ingroup PointModel /// Models: Point2DConcept -template +template class point { public: @@ -109,14 +109,14 @@ class point }; /// Alias template for backward compatibility with Boost <=1.68. -template +template using point2 = point; /// Common type to represent 2D dimensions or in-memory size of image or view. /// @todo TODO: rename to dims_t or dimensions_t for purpose clarity? using point_t = point; -template +template T point::* const point::mem_array[point::num_dimensions] = { &point::x, @@ -124,7 +124,7 @@ T point::* const point::mem_array[point::num_dimensions] = }; /// \ingroup PointModel -template +template BOOST_FORCEINLINE bool operator==(const point& p1, const point& p2) { @@ -132,7 +132,7 @@ bool operator==(const point& p1, const point& p2) } /// \ingroup PointModel -template +template BOOST_FORCEINLINE bool operator!=(const point& p1, const point& p2) { @@ -140,7 +140,7 @@ bool operator!=(const point& p1, const point& p2) } /// \ingroup PointModel -template +template BOOST_FORCEINLINE point operator+(const point& p1, const point& p2) { @@ -148,7 +148,7 @@ point operator+(const point& p1, const point& p2) } /// \ingroup PointModel -template +template BOOST_FORCEINLINE point operator-(const point& p) { @@ -156,15 +156,18 @@ point operator-(const point& p) } /// \ingroup PointModel -template +template BOOST_FORCEINLINE point operator-(const point& p1, const point& p2) { return { p1.x - p2.x, p1.y - p2.y }; } +template +concept arithmetic = std::is_arithmetic_v; + /// \ingroup PointModel -template +template BOOST_FORCEINLINE auto operator/(point const& p, D d) -> typename std::enable_if diff --git a/include/boost/gil/typedefs.hpp b/include/boost/gil/typedefs.hpp index 44673954ce..2e0628e31a 100644 --- a/include/boost/gil/typedefs.hpp +++ b/include/boost/gil/typedefs.hpp @@ -9,6 +9,8 @@ #ifndef BOOST_GIL_TYPEDEFS_HPP #define BOOST_GIL_TYPEDEFS_HPP +#include + #include #include #include @@ -22,25 +24,49 @@ # include #endif //!defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE) +namespace boost { namespace gil { + +#if defined(BOOST_GIL_HAS_CONCEPTS) + template + struct pixel; + template + struct planar_pixel_reference; + template + struct planar_pixel_iterator; + template + class memory_based_step_iterator; + template + class point; + template + class memory_based_2d_locator; + template + class image_view; + template + class image; +#else + template + struct pixel; + template + struct planar_pixel_reference; + template + struct planar_pixel_iterator; + template + class memory_based_step_iterator; + template + class point; + template + class memory_based_2d_locator; + template + class image_view; + template + class image; +#endif //defined(BOOST_GIL_HAS_CONCEPTS) + +}} // namespace boost::gil + // B - bits size/signedness, CM - channel model, CS - colour space, LAYOUT - pixel layout // Example: B = '8', CM = 'uint8_t', CS = 'bgr, LAYOUT='bgr_layout_t' #define BOOST_GIL_DEFINE_BASE_TYPEDEFS_INTERNAL(B, CM, CS, LAYOUT) \ - template \ - struct pixel; \ - template \ - struct planar_pixel_reference; \ - template \ - struct planar_pixel_iterator; \ - template \ - class memory_based_step_iterator; \ - template \ - class point; \ - template \ - class memory_based_2d_locator; \ - template \ - class image_view; \ - template \ - class image; \ using CS##B##_pixel_t = pixel; \ using CS##B##c_pixel_t = pixel const; \ using CS##B##_ref_t = pixel&; \ diff --git a/test/core/point/concepts.cpp b/test/core/point/concepts.cpp index 09c04c524c..9ec1f2e355 100644 --- a/test/core/point/concepts.cpp +++ b/test/core/point/concepts.cpp @@ -33,19 +33,14 @@ void test_members() int main() { - boost::function_requires>>(); - boost::function_requires>(); + static_assert(gil::PointNDConcept>); + static_assert(gil::PointNDConcept); - boost::function_requires>>(); - boost::function_requires>(); + static_assert(gil::Point2DConcept>); + static_assert(gil::Point2DConcept); test_members>(); test_members(); - // NOTE: point2 is deprecated, available for backward compatibility - boost::function_requires>>(); - boost::function_requires>>(); - test_members>(); - return 0; }