Boost logo

Boost Users :

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


> in these code I try to unpack the 1stand 2nd element, but it doesn't
> compile (here, it complains about »apply« in »struct
> boost::mpl::at_impl<boost::__mpl::non_sequence_tag>«
>
>
> This suggest mpl::pair's are not MPL sequences :(

ah thanks, now I can interpret this (probably RTFM)

> Try using mpl::vector2 instead of mpl::pair? Or patch Boost.MPL to make
> mpl::pair's be MPL sequences?

here my 2nd try:

---8<---
#include <boost/mpl/vector.hpp>
#include <boost/mpl/max_element.hpp>
#include <boost/mpl/size_t.hpp>
#include <boost/mpl/at.hpp>

#include <iostream>

namespace mpl = boost::mpl;

struct code {
         enum type {
                 undefined, foo, bar
         };
};

typedef mpl::vector<std::size_t,
                // min max
         mpl::vector< mpl::size_t<0>, mpl::size_t<0> >, // undefined
         mpl::vector< mpl::size_t<1>, mpl::size_t<3> >, // foo
         mpl::vector< mpl::size_t<2>, mpl::size_t<5> > // bar
> arity_info;

template <code::type code>
struct arity
        : mpl::at_c<arity_info, code>::type
{ };

template <code::type code>
struct min_arity
        : mpl::at_c<
                  typename arity<code>::type, 0
>::type
{ };

template <code::type code>
struct max_arity
        : mpl::at_c<
                  typename arity<code>::type, 1
>::type
{ };

int main()
{
     std::cout << "min arity<code::foo> = "
        << min_arity<code::foo>::value << '\n';
     std::cout << "max arity<code::foo> = "
        << max_arity<code::foo>::value << '\n';

     std::cout << "min arity<code::bar> = "
        << min_arity<code::bar>::value << '\n';
     std::cout << "max arity<code::bar> = "
        << max_arity<code::bar>::value << '\n';
}
--->8---

where the output is:

min arity<code::foo> = 0
max arity<code::foo> = 0
min arity<code::bar> = 1
max arity<code::bar> = 3

the code is shifted about 1, why? Expected is

min arity<code::foo> = 1
max arity<code::foo> = 3
min arity<code::bar> = 2
max arity<code::bar> = 5

Thanks,
Olaf


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