Thanks David, it works beautifully. Here is my code including
conversion to fusion list plus printing of the foreign key fields.
#include "boost/mpl/vector.hpp"
#include
#include
#include
#include
#include
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 id_field_t;
typedef mpl::vector name_field_t;
typedef mpl::vector address_field_t;
typedef mpl::vector birthday_field_t;
typedef mpl::vector< id_field_t
, name_field_t
, address_field_t
, birthday_field_t
> table;
// find all foreign keys fields
typedef mpl::filter_viewmpl::_,
tags::foreign> >::type iter_2;
typedef fusion::result_of::as_list::type foreign_keys_t;
struct print
{
template <typename T>
void operator()( T const& vec ) const
{
fusion::at >(vec).print();
}
};
int _tmain(int argc, _TCHAR* argv[])
{
BOOST_STATIC_ASSERT(( is_same< mpl::deref<iter>::type, id_field_t
::value ));
foreign_keys_t foreign_keys;
for_each( foreign_keys, do_something() );
return 0;
}