|
Boost Users : |
From: David Abrahams (dave_at_[hidden])
Date: 2007-04-01 15:04:17
on Sun Apr 01 2007, "Christian Henning" <chhenning-AT-gmail.com> wrote:
> Hi there,
>
> is it possible to find all type vectors in a type matrix ( 2D type
> vector ) that match a predicate? In the end I would like to have them
> in another type matrix.
How about using filter_view?
> Can somebody point out how I would put together such a metafunction?
> I'm not sure if the mpl lib supports my feature request.
>
> Consider the following code:
>
> #include "boost/mpl/vector.hpp"
> #include <boost/mpl/find_if.hpp>
> #include <boost/mpl/at.hpp>
>
> using namespace std;
> using namespace boost;
>
> namespace fields
> {
> struct id {};
> struct name {};
> struct address {};
> struct birthday {};
> }
>
> namespace tags
> {
> struct primary {};
> struct foreign {};
> struct no_key {};
> }
>
> typedef mpl::vector<fields::id , tags::primary> id_field_t;
> typedef mpl::vector<fields::name , tags::foreign> name_field_t;
> typedef mpl::vector<fields::address , tags::foreign> address_field_t;
> typedef mpl::vector<fields::birthday, tags::no_key> birthday_field_t;
>
>
>
> typedef mpl::vector< id_field_t
> , name_field_t
> , address_field_t
> , birthday_field_t
> > table;
// untested
mpl::filter_view<table, mpl::is_same<mpl::back<_>, tags::foreign> >
You can copy the filter_view into a vector if you want to, but you're
probably better off just using it as though it were a vector.
-- Dave Abrahams Boost Consulting www.boost-consulting.com Don't Miss BoostCon 2007! ==> http://www.boostcon.com
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