Boost logo

Boost Users :

From: Istvan Buki (buki.istvan_at_[hidden])
Date: 2008-06-02 09:30:05


Hello,

I'm trying out some ideas with boost.fusion maps.
Here is a small example:

namespace fields
{
  struct general
  {
    struct first_name ;
    struct last_name ;
    struct age ;
  } ;

  struct address
  {
    struct street ;
    struct postal_code ;
    struct country ;
  } ;
}

typedef fusion::map <
  fusion::pair< fields::general::first_name, std::string >,
  fusion::pair< fields::general::last_name, std::string >,
  fusion::pair< fields::general::age, int >
> general_person ;

typedef fusion::map <
  fusion::pair< fields::address::street, std::string >,
  fusion::pair< fields::address::postal_code, std::string >,
  fusion::pair< fields::address::country, std::string >
> address_person ;

typedef fusion::map <
  fusion::pair< fields::general, general_person >,
  fusion::pair< fields::address, address_person >
> person ;

int
main()
{
  using namespace fields ;

  general_person gp =
    fusion::make_map< general::first_name,
    general::last_name, general::age >( "John", "Doe", 99 ) ;

  address_person ap =
    fusion::make_map< address::street,
    address::postal_code, address::country >( "Foo street 1", "12345",
"Barland" ) ;

  person a_person =
    fusion::make_map< general, address >( gp, ap ) ;

  std::cout << "Age: "
        << fusion::at_key< general::age >( fusion::at_key< general >(
a_person ) )
        << std::endl ;

  return 0 ;
}

I'm not happy with the last line that retrieve the value of a specific pair
inside a nested map.
I was wondering whether this could benefit from some MPL trick to make it
more readable. I was thinking about something like the following: get_value<
general, age >( a_person ).

My questions are:

1) Is MPL the right tool to transform a call to
           get_value< general, age >( a_person )
   into
         fusion::at_key< general::age >( fusion::at_key< general >( a_person
) )

2) If it is, could someone provide me some help on how to achieve such a
result?

Thank you for your help



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