|
Boost Users : |
Subject: Re: [Boost-users] [fusion] more trouble with transform
From: Christopher Schmidt (mr.chr.schmidt_at_[hidden])
Date: 2011-11-12 06:18:57
Gennadiy Rozental <rogeeff_at_[hidden]> writes:
> Hi,
>
> Now I am trying to perform transform which mutates:
>
> ------
> #include <boost/fusion/container/list/list.hpp>
> #include <boost/fusion/container/list/convert.hpp>
> #include <boost/fusion/container/generation/make_list.hpp>
> #include <boost/fusion/algorithm/transformation/transform.hpp>
> namespace fusion=boost::fusion;
>
> struct C {};
>
> struct B {
> C make_c() { return C(); }
> };
>
> struct make_c {
> template<typename Sig> struct result;
>
> template <typename T>
> struct result<make_c(T&)>
> {
> typedef C type;
> };
> template <typename T>
> struct result<make_c(T)>
> {
> typedef C type;
> };
>
> template <typename T>
> C
> operator()(T& t) const { return t.make_c(); }
> };
>
> int
> main()
> {
> B b1, b2;
> auto z1 = fusion::make_list( b1, b2 );
>
> auto z2 = fusion::as_list( fusion::transform( z1, make_c() ) );
>
> return 0;
> }
> ----
>
> Both gcc and msvc complain like this:
>
> test.cpp:29:46: error: passing âconst Bâ as âthisâ argument of âC B::make_c()â
> discards qualifiers.
>
> What am I missing now?
>
> Gennadiy
fusion::transform only accepts cref-qualified sequences. That is why
the resulting transform view will be store a reference to z1 const and
thus the arguments passed to make_c are const-qualified.
https://svn.boost.org/trac/boost/ticket/3446
Construct the transform view by hand and your example should work fine.
Christopher
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net