Skip to content

Replace Boost.Variant with Boost.Variant2 - #474

Merged
mloskot merged 7 commits into
boostorg:developfrom
sdebionne:boost-variant2
Apr 17, 2020
Merged

Replace Boost.Variant with Boost.Variant2#474
mloskot merged 7 commits into
boostorg:developfrom
sdebionne:boost-variant2

Conversation

@sdebionne

@sdebionne sdebionne commented Apr 6, 2020

Copy link
Copy Markdown
Contributor

Description

Implements dynamic extension with Boost.Variant2 instead of Boost.Variant.

References

Fixes #232

Tasklist

  • Update/Add test case(s)
  • Update doc(s)
  • Update extension usage in I/O
  • Ensure all CI builds pass
  • Review and approve

@sdebionne sdebionne changed the title WIP, just for discussion Use Boost.Variant2 Apr 6, 2020
Comment thread include/boost/gil/extension/dynamic_image/any_image_view.hpp Outdated
@mloskot mloskot added the cat/enhancement Improvements, but not fixes addressing identified bugs label Apr 8, 2020
@mloskot

mloskot commented Apr 8, 2020

Copy link
Copy Markdown
Member

Thanks, I'm very much in favour of switching to the Boost.Variant2

@sdebionne
sdebionne marked this pull request as ready for review April 9, 2020 14:24
@sdebionne

Copy link
Copy Markdown
Contributor Author

Builds fine with MSVC 2019.

@sdebionne

Copy link
Copy Markdown
Contributor Author

@pdimov Any chance that this issue that seems to be specific to MSVC 2017 rings a bell?

boost\mp11\list.hpp(202): error C3200: 'B': invalid template argument for template parameter 'B', expected a class template

@pdimov

pdimov commented Apr 9, 2020

Copy link
Copy Markdown
Member

My guess is that it doesn't like

using view_t = mp11::mp_rename<detail::images_get_views_t<any_image>, any_image_view>;

either because it doesn't like any_image or any_image_view. I'll look into why.

@pdimov

pdimov commented Apr 9, 2020

Copy link
Copy Markdown
Member

Hm no, it's actually this line:

template <typename ...Views>
class any_image_view : public variant2::variant<Views...>
{
    using parent_t = variant2::variant<Views...>;

public:    
    using const_t = mp11::mp_rename<detail::views_get_const_t<any_image_view>, any_image_view>;

The second any_image_view is interpreted as referring to the class (same as the first one).

@pdimov

pdimov commented Apr 9, 2020

Copy link
Copy Markdown
Member

Since the result of detail::view_get_const_t<any_image_view> is already any_image_view, just drop the rename.

And maybe use b2 instead of cmake in order to see the errors.

compile-c-c++ ..\..\bin.v2\libs\gil\test\extension\toolbox\get_num_bits.test\msv
c-14.1\debug\asynch-exceptions-on\threading-multi\get_num_bits.obj
cl : Command line warning D9025 : overriding '/W3' with '/W4'
get_num_bits.cpp
C:\boost-git\develop\boost/mp11/list.hpp(202): error C3200: 'B': invalid templat
e argument for template parameter 'B', expected a class template
        with
        [
            B=boost::gil::any_image_view<Views...>
        ]
C:\boost-git\develop\boost/gil/extension/dynamic_image/any_image_view.hpp(79): n
ote: see reference to alias template instantiation 'boost::mp11::mp_rename<boost
::gil::detail::views_get_const_t<boost::gil::any_image_view<Views...>>,boost::gi
l::any_image_view<Views...>>' being compiled
C:\boost-git\develop\boost/gil/extension/dynamic_image/any_image_view.hpp(122):
note: see reference to class template instantiation 'boost::gil::any_image_view<
Views...>' being compiled

@pdimov

pdimov commented Apr 9, 2020

Copy link
Copy Markdown
Member
C:\boost-git\develop\libs\gil>git diff
diff --git a/include/boost/gil/extension/dynamic_image/any_image_view.hpp b/include/boost/gil/extension/dynamic_image/any_image_view.hpp
index 1119b2f7f..f4a2f7351 100644
--- a/include/boost/gil/extension/dynamic_image/any_image_view.hpp
+++ b/include/boost/gil/extension/dynamic_image/any_image_view.hpp
@@ -76,7 +76,7 @@ class any_image_view : public variant2::variant<Views...>
     using parent_t = variant2::variant<Views...>;

 public:
-    using const_t = mp11::mp_rename<detail::views_get_const_t<any_image_view>, any_image_view>;
+    using const_t = detail::views_get_const_t<any_image_view>;
     //using const_t = detail::views_get_const_t<any_image_view>;
     using x_coord_t = std::ptrdiff_t;
     using y_coord_t = std::ptrdiff_t;

@pdimov

pdimov commented Apr 9, 2020

Copy link
Copy Markdown
Member

I see that you already had the right thing there but commented out. :-)

@sdebionne

sdebionne commented Apr 10, 2020

Copy link
Copy Markdown
Contributor Author

Thank you so much for your help, I am always amazed by the support you get from this community.

Why on earth did I add this mp_rename ? :-)

If I understand correctly, mp_rename<A<T...>, A> fails on MSVC 2017 or is it just with any_image_view?

@pdimov

pdimov commented Apr 10, 2020

Copy link
Copy Markdown
Member

It only fails when you're inside the definition of template<class... T> class A, because there A can refer to both the class itself (A<T...>, "class name injection") and the class template (A), and 2017 doesn't consider the second possibility. You were basically doing something similar to mp_rename<A, A>, where the two As mean different things.

@mloskot mloskot added this to the Boost 1.74+ milestone Apr 10, 2020
@sdebionne

Copy link
Copy Markdown
Contributor Author

One of the Azure jobs failed with:

Cloning into 'boost-root'...
C:/Program Files/Git/mingw64/libexec/git-core\git-submodule: line 457:  1643 Segmentation fault      git submodule--helper ensure-core-worktree "$sm_path"

Any chance that it could be restarted?

@mloskot

mloskot commented Apr 14, 2020

Copy link
Copy Markdown
Member

@sdebionne Restarted

@mloskot mloskot changed the title Use Boost.Variant2 Replace Boost.Variant with Boost.Variant2 Apr 15, 2020

@mloskot mloskot left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you for contributions! For me, it's ready to merge. Let's give others a day or two to review.

I think we could also get rid of this bridge now

#include <boost/mp11/mpl.hpp> // required by dynamic_image and boost::variant (?)

Comment thread include/boost/gil/extension/dynamic_image/apply_operation.hpp

@stefanseefeld stefanseefeld left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a great improvement to the dynamic_image extension.
I'm a bit wary, though, seeing that all our I/O extensions (and more !) depend on that. Wouldn't there be a way to split this, so someone can use the PNG reader without having to drag in boost/variant2.hpp, say ?

@mloskot

mloskot commented Apr 15, 2020

Copy link
Copy Markdown
Member

@stefanseefeld

Wouldn't there be a way to split this, so someone can use the PNG reader without having to drag in boost/variant2.hpp

Currently, those all drag in boost/variant.hpp, so it's NOT adding a new dependency, but replacing an old A with new B. And, as the new B has less dependencies than the old A, it means removing some transitive dependencies. Unless I'm missing something.

@stefanseefeld

Copy link
Copy Markdown
Member

OK, that's a fair point. So let's move forward with this PR, and try to separate the dynamic_image extension dependency from the other extensions separately.

@mloskot

mloskot commented Apr 15, 2020

Copy link
Copy Markdown
Member

@stefanseefeld Yes, I think this PR is completed now and feasibility of decoupling the dynamic_image and io extensions should be a matter of separate discussion and PR.
So, unless you have any other requests for changes, let's mark this as approved.

@mloskot
mloskot merged commit 601790f into boostorg:develop Apr 17, 2020
@sdebionne
sdebionne deleted the boost-variant2 branch April 20, 2020 15:55
mloskot added a commit that referenced this pull request Jul 11, 2020
* develop:
  Collect release notes for Boost 1.74
  Fix missing header in numeric/kernel.hpp to make it self-contained (#502)
  Use perfect forwading from apply_operation to visit (#491)
  Fix typos and replace mpl with mp11 in tutorial (#494)
  Implemented mechanism to reverse kernel_2d (#489)
  added missing const& in extend_boundary parameters (#490)
  Add initializing image constructor (#486)
  Fix interleaved_view factory using point<std::ptrdiff_t> for dimension (#487)
  RELEASES.md: Remove beta tag [ci skip]
  Replace Boost.Variant with Boost.Variant2 (#474)
  Fix error plane_view_t is not a class or namespace name (#481)
  Fix image constructor from other image (#477)
  Fix overflow in RGB to CMYK32 conversion (#470)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cat/enhancement Improvements, but not fixes addressing identified bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Try variant2 as Boost.Variant replacement for C++11

5 participants