|
Boost Users : |
Subject: Re: [Boost-users] mpl::fold problems
From: sergey kostanbaev (sergey.kostanbaev_at_[hidden])
Date: 2010-08-23 10:24:13
Thanks! It really helps!
On Mon, Aug 23, 2010 at 5:47 PM, Stefan Strasser <strasser_at_[hidden]>wrote:
> Zitat von sergey kostanbaev <sergey.kostanbaev_at_[hidden]>:
>
> template <class T, unsigned space=1> struct tr_field2
>> {
>> static const unsigned count = space;
>> }
>>
>> typedef boost::mpl::vector4<
>> tr_field2<int, 4>,
>> tr_field2<int, 7>,
>> tr_field2<char, 1>,
>> tr_field2<char, 1>
>>
>>> Test_description;
>>>
>>
>>
>> I want to calculate a sum of all tr_field2::count
>> I've read in the docs mpl::fold is for the case.
>>
>> I tried to compose
>>
>> typedef boost::mpl::fold<Test_description,
>> boost::mpl::int_<0>,
>> boost::mpl::plus<boost::mpl::_, boost::mpl::_::count > >
>> >::type fcount;
>>
>> but it won't compile. It seems I misundestood something.
>>
>
> template<typename T>
> struct get_count{
> typedef mpl::int_<T::count> type;
>
> };
>
> typedef boost::mpl::fold<Test_description,
> boost::mpl::int_<0>,
> boost::mpl::plus<boost::mpl::_1, get_count<mpl::_2> >
>
>> ::type fcount;
>>
>
> the placeholders are not evaluated by mpl::_::count.
> and mpl::plus expects a mpl integral constant, not a value.
>
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
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