Boost logo

Boost Users :

From: Christian Henning (chhenning_at_[hidden])
Date: 2007-04-02 12:05:08


> > // find all foreign keys fields
> > typedef mpl::filter_view<table, is_same<mpl::back<mpl::_>,
> > tags::foreign> >::type iter_2;
> ^^^^^^
> not needed
>
> Why are you calling this type sequence "iter_2"? It's not an
> iterator, is it?
>

Sorry this was my error. But how can I use the filter_view result to
do something useful? For what I understand the filter_view results in
a lazy forward sequence and though, why not use it with the transform1
algorithm. The following code displays what I trying to do.

#include "boost/mpl/vector.hpp"
#include "boost/mpl/list.hpp"
#include <boost/mpl/find_if.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/filter_view.hpp>
#include <boost/mpl/transform.hpp>

using namespace std;
using namespace boost;

namespace fields
{
  struct id { void print() { cout << "id" << endl; } };
  struct name { void print() { cout << "name" << endl;} };
  struct address { void print() { cout << "address" << endl; }};
  struct birthday { void print() { cout << "birthday" << endl; }};
}

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;

// finds primary key field
typedef mpl::find_if< table, is_same< mpl::at< mpl::_1, mpl::int_<1>
>, tags::primary > >::type primary_key_t;

template <typename T>
struct add_vector
{
   typedef mpl::at_c< T, 0 >::type field_t;
   typedef std::vector<field_t> type;
};

// find all foreign keys fields
typedef mpl::filter_view<table, is_same<mpl::back<mpl::_>,
tags::foreign> > foreign_keys_view_t;
typedef mpl::transform1< foreign_keys_view_t, add_vector<mpl::_1>
>::type foreign_key_vectors_t;

int _tmain(int argc, _TCHAR* argv[])
{
   return 0;
}

Regards,
Christian


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