Boost logo

Boost :

Subject: Re: [boost] [fusion] for_each on gcc 4.7
From: Joel de Guzman (joel_at_[hidden])
Date: 2012-06-21 02:33:26

On 6/21/2012 10:00 AM, Daniel Larimer wrote:
> On Jun 20, 2012, at 9:57 PM, Daniel Larimer wrote:
>> On Jun 20, 2012, at 7:36 PM, Joel de Guzman wrote:
>>> On 6/20/2012 1:37 PM, Daniel Larimer wrote:
>>>> I recently attempted to update to gcc 4.7 and code that compiled with 4.5.3 broke.
>>>> It appears that boost::fusion expects boost::fusion::random_access_traversal_tag to implicitly cast to mpl::bool_<false>.
>>>> Switching the 3rd argument from mpl::bool_<false> to an extra template arg (that was ignored), seems to fix the compilation errors.
>>>> Compiled with std=c++11
>>> Do you have a minimal test case?
>> #include<boost/fusion/container/vector.hpp>
>> #include<boost/fusion/algorithm.hpp>
>> #include<boost/fusion/include/make_vector.hpp>
>> struct visitor {
>> template<typename T>
>> void operator()( T t )const{}
>> };
>> int main() {
>> visitor v;
>> boost::fusion::for_each( boost::fusion::make_vector(5,6.6), v );
>> return 0;
>> }
> I could get things to compile by editing boost/fusion/algorithm/iteration/detail/for_each.hpp and changing the last parameter to Ty. It appears that parameter was ignored anyway and that we didn't care about the type.
> template<typename Sequence, typename F, typename Ty>
> inline void
> for_each(Sequence& seq, F const& f, Ty) // unsegmented implementation
> {
> detail::for_each_dispatch(seq, f, typename traits::category_of<Sequence>::type());
> }

No, that is not a proper fix. It just bypasses the problem, which seems to be
a gcc 4.7 problem. There is nothing wrong with Fusion code AFAICT. Fusion
does not expect boost::fusion::random_access_traversal_tag to be converted
to an mpl::bool_<false>. That function (detail::for_each) is called this way:

   detail::for_each(seq, f, typename traits::is_segmented<Sequence>::type());

And there is nothing wrong with that code AFAICT.

Sorry, I do not have gcc 4.7 ATM, but at any rate, what errors do you get
with the code above. Both VC10 and gcc-4.6 compiles it just fine.

Your previous error report is very suspicious:

   error: no matching function for call to 'for_each(boost::fusion::vector2<
   double, double>&, const mace::rpc::detail::unpack_sequence<mace::rpc::
   function_filter<mace::rpc::connection<mace::rpc::json::io> > >&,
   double, double> >::type)'

Fusion never calls for_each with fusion_category_of. It calls for_each_dispatch,
(not for_each) with fusion_category_of as third parameter. I don't know how that


Joel de Guzman

Boost list run by bdawes at, gregod at, cpdaniel at, john at