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---
On Thu, Apr 18, 2013 at 11:47 AM, Olaf Peter <ope-devel@gmx.de> wrote:
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>«
This suggest mpl::pair's are not MPL sequences :( Is there a better way and how to get it to compile?
Try using mpl::vector2 instead of mpl::pair? Or patch Boost.MPL to make mpl::pair's be MPL sequences? 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 mailing list Boost-users@lists.boost.org http://lists.boost.org/**mailman/listinfo.cgi/boost-**users<http://lists.boost.org/mailman/listinfo.cgi/boost-users>
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
On Fri, Apr 19, 2013 at 6:47 AM, Olaf Peter <ope-devel@gmx.de> wrote:
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;
must be mpl::vector< mpl::vector< ...
Right :) - Jeff
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<>> :(
On Fri, Apr 19, 2013 at 10:49 AM, Olaf Peter <ope-devel@gmx.de> 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. HTH, - Jeff
Am 19.04.2013 19:59, schrieb Jeffrey Lee Hellrung, Jr.:
On Fri, Apr 19, 2013 at 10:49 AM, Olaf Peter <ope-devel@gmx.de <mailto:ope-devel@gmx.de>> 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 { };
participants (2)
-
Jeffrey Lee Hellrung, Jr.
-
Olaf Peter