Boost logo

Boost Users :

Subject: Re: [Boost-users] Comparing two mpl::vector types
From: Rodrigo Madera (rodrigo.madera_at_[hidden])
Date: 2013-02-23 09:35:40


Jeffrey,

Of course! It all comes down to zip_filter them...

Thank you for your help,
Rodrigo

On Sat, Feb 23, 2013 at 4:10 AM, Jeffrey Lee Hellrung, Jr. <
jeffrey.hellrung_at_[hidden]> wrote:

> On Fri, Feb 22, 2013 at 4:32 PM, Rodrigo Madera <rodrigo.madera_at_[hidden]>wrote:
>
>> Hello all,
>>
>> Can anyone give me a hint on how to call a functor on the differences of
>> two same size mpl::vector types?
>>
>> For example, given:
>>
>> typedef boost::mpl::vector<int, char, short, double> v0_type;
>> typedef boost::mpl::vector<int, int, short, std::string> v1_type;
>>
>> We can see that the second and third elements don't match, so I wish to
>> call a functor twice, with the following signature:
>>
>> struct SomeFunctor {
>> template <typename T, typename U>
>> void operator()(T t, U u) const {
>> // do something nice here
>> }
>> };
>>
>> In this example, functor would be called twice: once with [T=char, U=int]
>> and another with [T=short, U=std::string], along with their values.
>>
>
> Looks like using a zip_view [1] followed by a filter_view [2] followed by
> a for_each [3] will get you what you want. E.g., (untested)
>
> typedef mpl::zip_view< mpl::vector2< v0_type, v1_type > > zip_view_type;
> typedef mpl::filter_view< zip_view_type, mpl::not_< boost::is_same<
> mpl::_1, mpl::_2 > > > filter_view_type;
> mpl::for_each< filter_view_type >(SomeFunctor());
>
> HTH,
>
> - Jeff
>
> [1]
> http://www.boost.org/doc/libs/1_53_0/libs/mpl/doc/refmanual/zip-view.html
> [2]
> http://www.boost.org/doc/libs/1_53_0/libs/mpl/doc/refmanual/filter-view.html
> [3]
> http://www.boost.org/doc/libs/1_53_0/libs/mpl/doc/refmanual/for-each.html
>
>
> _______________________________________________
> 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