Boost logo

Boost Users :

Subject: Re: [Boost-users] trac ticket 4697 submitted (was Re: [Fusion] How to join more than two sequences
From: Larry Evans (cppljevans_at_[hidden])
Date: 2010-10-06 13:22:03


On 10/06/10 10:53, Christopher Schmidt wrote:
[snip]
> You can fix your example by removing the references to Lhs and Rhs
> before passing down to Fusion:
>
> namespace fold_join{struct join_ftor
> {
> template<typename Sig>
> struct result;
>
> template<typename Self, typename Lhs, typename Rhs>
> struct result<Self(Lhs,Rhs)>
> {
> typedef boost::fusion::joint_view<
> typename boost::remove_reference<
> Lhs
> >::type,
> typename boost::remove_reference<
> Rhs
> >::type
> > type;
> };
>
> template<typename Lhs, typename Rhs>
> typename result<join_ftor const(Lhs&,Rhs&)>::type
> operator()(Lhs& lhs, Rhs& rhs)const
> {
> return boost::fusion::joint_view<
> Lhs, Rhs
> >(lhs,rhs);
> }
> };}
>

Thanks. I made the changes you suggest above; however, it still
fails to compile without variadic fusion. The changed source
is attached.

> A few remarks:
>
> You cannot use the function(!) fusion::join as it only accepts
> const-qualified sequences. See
>
> https://svn.boost.org/trac/boost/ticket/3954
>
> for more information. The port has this 'fixed'. In your code you should
> use fusion::joint_view directly.

Thanks.

>
> It is definitely not a good idea to specialize boost::result_of with the
> signature of your functor. You should stick to the official protocol,
> that is defining a nested type 'result_type' or a nested template type
> 'result'.

The fusion html reference mentioned the in source comments
after @brief the result_of specialization explain why I thought
I had to specialize boost::result_of. IOW, the Table 1.37 here:

http://www.boost.org/doc/libs/1_44_0/libs/fusion/doc/html/fusion/algorithm/iteration/functions/fold.html

lead me to this conclusion. If that's wrong, then maybe the fold.html
should provide further clarification.

> You should consider that the functor may be const- and/or even
> reference-qualified (in c++11) when passed to the result metafunction.
> See FCD 20.7.6.6 for more information.
>
> template<typename LhSequence, typename RhSequence>
> typename boost::result_of<join_ftor(LhSequence,RhSequence)>::type
> operator()(LhSequence& lhs, RhSequence& rhs)const
>
> is not a good idea as well, as LhSequence and RhSequence in
> join_ftor(LhSequence,RhSequence) loose cv-qualification.
>
> -Christopher

Thanks very much for the explanation Christopher.

-Larry




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