Boost logo

Boost Users :

Subject: Re: [Boost-users] mpl vector of pair access
From: Olaf Peter (ope-devel_at_[hidden])
Date: 2013-04-19 14:51:45


Am 19.04.2013 19:59, schrieb Jeffrey Lee Hellrung, Jr.:
> On Fri, Apr 19, 2013 at 10:49 AM, Olaf Peter <ope-devel_at_[hidden]
> <mailto:ope-devel_at_[hidden]>> wrote:
>
> must be mpl::vector<
> mpl::vector< ...
>
>
> Right :)
>
>
> Thanks, now I want to find the maximum over all, but I've got lost.
> I got it working for
>
> typedef mpl::vector_c<std::size_t,
> 0, // undefined,
> 4, // foo,
> 7 // bar,
> > arity_info;
>
> struct max_arity
> : mpl::deref<
> mpl::max_element<arity_info>::__type
> >::type
> { };
>
> but not here with the vector<vector<>> :(
>
>
> Sorry, you might have to be more specific? I'll give it a shot though. I
> would think some combination of mpl::max_element (as you have above)
> with mpl::transform (which transforms your vector<vector<...>> to a
> vector<...> of the at_c<1>'s of the inner vector<...>s) might be what
> you want, but not sure.
>
> Alternatively, you can call mpl::max_element on the original
> vector<vector<...>> nested sequence directly, using a custom comparator,
> then extract at_c<1> of the (deref'ed) result.
>
> If this is what want but you can't get either or both of the above to
> work, holler back.

You got it, thanks a lot. Here my solution:

struct arity_maximum // find the max value over all arities
        : mpl::deref<
                mpl::max_element<
                        mpl::transform<
                                  arity_info, mpl::at<mpl::_1, mpl::size_t<1> >
>::type
>::type
>::type
{ };


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