Boost logo

Boost :

Subject: Re: [boost] Basic boost::mpl::max_element question.
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2011-09-02 10:21:30


On Thu, Sep 1, 2011 at 7:40 PM, Yves Dolce <yves.dolce_at_[hidden]> wrote:
[...]

> template <unsigned char L>
>
> struct Level {
>
> static const unsigned char value = L;
>
> };
>
> template <class LEVEL>
>
> struct CTA {
>
> typedef LEVEL Level_t;
>
> };
>
>
>
> typedef boost::fusion::vector<CTA1, CTA2, CTA3, CTA4> CTAS;
>
>
>
> Now, using max_element, I'd like to pick the one CTAn for which
> CTn::Level_t::value is the biggest. Can you enlighten me? Thanks!
>

I presume each CTAn is an instantiation of CTA, in which case *I think*
something like

template< class T >
struct Get_Level_t
{ typedef typename T::Level_t type; };

// ...

boost::mpl::max_element<
    CTAS,
    boost::mpl::less<
        Get_Level_t< boost::mpl::_1 >,
        Get_Level_t< boost::mpl::_2 >
>
>::type

would get you an iterator into CTAS pointing to the CTAn the largest
Level_t::value. (WARNING: I haven't actually tried this code.)

HTH,

- Jeff


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk