diff --git a/doc/changelog.dox b/doc/changelog.dox index 046e828f8..1249ceab7 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -220,6 +220,11 @@ See also: - With @ref Corrade/Utility/DebugStl.h not being included, @ref std::string instances could get accidentally printed as @ref ResourceKey instances. Added and explicit header dependency to avoid such cases. +- The @ref Magnum/Image.h, @ref Magnum/ImageView.h and + @ref Magnum/Trade/ImageData.h headers required + @ref Corrade/Containers/StridedArrayView.h to be included *before* in order + to use the @ref ImageView::pixels() "pixels()" function. Now it's enough + to just include it at any point, with no order dependency anymore. @subsection changelog-latest-deprecated Deprecated APIs diff --git a/src/Magnum/Image.h b/src/Magnum/Image.h index eab6aa2e5..75b4e526b 100644 --- a/src/Magnum/Image.h +++ b/src/Magnum/Image.h @@ -34,6 +34,17 @@ #include "Magnum/DimensionTraits.h" #include "Magnum/PixelStorage.h" +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Corrade { namespace Containers { + +/* Forward declaration of an utility used in pixels() to avoid forcing users to + include the relatively large StridedArrayView header *before* the Image + class definition. */ +template StridedArrayView arrayCast(const StridedArrayView& view); + +}} +#endif + namespace Magnum { #ifndef DOXYGEN_GENERATING_OUTPUT @@ -437,7 +448,8 @@ template class Image { */ template Containers::StridedArrayView pixels() { /* Deliberately not adding a StridedArrayView include, it should - work without since this is a templated function */ + work without since this is a templated function and we declare + arrayCast() above to satisfy two-phase lookup. */ return Containers::arrayCast(pixels()); } diff --git a/src/Magnum/ImageView.h b/src/Magnum/ImageView.h index 701f768b1..f27120d55 100644 --- a/src/Magnum/ImageView.h +++ b/src/Magnum/ImageView.h @@ -35,6 +35,17 @@ #include "Magnum/PixelStorage.h" #include "Magnum/Math/Vector3.h" +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Corrade { namespace Containers { + +/* Forward declaration of an utility used in pixels() to avoid forcing users to + include the relatively large StridedArrayView header *before* the Image + class definition. */ +template StridedArrayView arrayCast(const StridedArrayView& view); + +}} +#endif + namespace Magnum { /** @@ -460,7 +471,8 @@ template class ImageView { template Containers::StridedArrayView::value, typename std::add_const::type, U>::type> pixels() const { if(!_data && !_data.size()) return {}; /* Deliberately not adding a StridedArrayView include, it should - work without since this is a templated function */ + work without since this is a templated function and we declare + arrayCast() above to satisfy two-phase lookup. */ return Containers::arrayCast::value, typename std::add_const::type, U>::type>(pixels()); } diff --git a/src/Magnum/Test/ImageTest.cpp b/src/Magnum/Test/ImageTest.cpp index 640f9951a..64256f6dc 100644 --- a/src/Magnum/Test/ImageTest.cpp +++ b/src/Magnum/Test/ImageTest.cpp @@ -24,7 +24,8 @@ */ /* Included as first to check that we *really* don't need the StridedArrayView - header for definition of pixels() */ + header for definition of pixels(). We actually need, but just for the + arrayCast() template, which is forward-declared. */ #include "Magnum/Image.h" #include diff --git a/src/Magnum/Test/ImageViewTest.cpp b/src/Magnum/Test/ImageViewTest.cpp index e9a7880de..d835439f0 100644 --- a/src/Magnum/Test/ImageViewTest.cpp +++ b/src/Magnum/Test/ImageViewTest.cpp @@ -24,7 +24,8 @@ */ /* Included as first to check that we *really* don't need the StridedArrayView - header for definition of pixels() */ + header for definition of pixels(). We actually need, but just for the + arrayCast() template, which is forward-declared. */ #include "Magnum/ImageView.h" #include diff --git a/src/Magnum/Trade/ImageData.h b/src/Magnum/Trade/ImageData.h index b5cbc471b..ea025c0bd 100644 --- a/src/Magnum/Trade/ImageData.h +++ b/src/Magnum/Trade/ImageData.h @@ -36,6 +36,17 @@ #include "Magnum/Trade/Trade.h" #include "Magnum/Trade/visibility.h" +#ifndef DOXYGEN_GENERATING_OUTPUT +namespace Corrade { namespace Containers { + +/* Forward declaration of an utility used in pixels() to avoid forcing users to + include the relatively large StridedArrayView header *before* the Image + class definition. */ +template StridedArrayView arrayCast(const StridedArrayView& view); + +}} +#endif + namespace Magnum { namespace Trade { /** @@ -417,7 +428,8 @@ template class ImageData { */ template Containers::StridedArrayView pixels() { /* Deliberately not adding a StridedArrayView include, it should - work without since this is a templated function */ + work without since this is a templated function and we declare + arrayCast() above to satisfy two-phase lookup. */ return Containers::arrayCast(pixels()); } diff --git a/src/Magnum/Trade/Test/ImageDataTest.cpp b/src/Magnum/Trade/Test/ImageDataTest.cpp index 4662288e0..d68a895bc 100644 --- a/src/Magnum/Trade/Test/ImageDataTest.cpp +++ b/src/Magnum/Trade/Test/ImageDataTest.cpp @@ -24,7 +24,8 @@ */ /* Included as first to check that we *really* don't need the StridedArrayView - header for definition of pixels() */ + header for definition of pixels(). We actually need, but just for the + arrayCast() template, which is forward-declared. */ #include "Magnum/Trade/ImageData.h" #include