Boost logo

Boost Users :

Subject: [Boost-users] mpl vector of pair access
From: Olaf Peter (ope-devel_at_[hidden])
Date: 2013-04-18 14:47:53


Hello,

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>«

Is there a better way and how to get it to compile?

Thanks,
Olaf

---8<---
#include <boost/mpl/vector.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/max_element.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/integral_c.hpp>
#include <boost/mpl/size_t.hpp>
#include <boost/mpl/placeholders.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::pair< mpl::size_t<0>, mpl::size_t<0> >, // undefined
         mpl::pair< mpl::size_t<1>, mpl::size_t<3> >, // foo
         mpl::pair< mpl::size_t<2>, mpl::size_t<5> > // bar
> arity_info;

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

// same for max_arity at index 1 (pair::second)

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

--->8---


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