|
Boost Users : |
From: Christian Henning (chhenning_at_[hidden])
Date: 2007-03-26 15:47:07
Hi there, is it somehow possible to access a sequence element at
runtime? Just image you're reading some name value pairs from file and
you would like them to assign them to a fusion sequences. This way I
don't know they order the values are supplied. Is that possible?
For example take the following code:
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <boost/any.hpp>
#include <boost/bind.hpp>
#include <boost/fusion/sequence.hpp>
using namespace std;
using namespace boost;
struct A {};
struct B {};
struct info
{
string name;
any value_type;
};
static info info_table[] =
{
{ "A_Value", any( A() ) },
{ "B_Value", any( B() ) }
};
string& get_name( info& i )
{
return i.name;
}
typedef fusion::map< fusion::pair< A , int >
, fusion::pair< B , double >
> seq_type;
int _tmain(int argc, _TCHAR* argv[])
{
// Image a file read has delivered the following name value pair.
string name = "A_Value";
int a_value = 12;
// Find the type of the supplied name
info* p = find_if( &info_table[0]
, &info_table[0] + 2
, bind( equal_to<string>()
, bind( &get_name, _1 )
, name ));
seq_type seq;
// How to add the value to the supplied name??
}
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