Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost] [fusion] fusion::map doesn't define 'category'
From: Steve Lorimer (steve.lorimer_at_[hidden])
Date: 2012-07-27 00:38:53


D'oh - I found the error:

    typedef typename fusion::result_of::as_map<pair_sequence> type;

should be

    typedef typename fusion::result_of::as_map<pair_sequence>::type type;

On 27 July 2012 13:48, Steve Lorimer <steve.lorimer_at_[hidden]> wrote:

> I am attempting to create a fusion map which looks like:
>
> map< pair<field1, int>, pair<field2, int> >
>
> I am then attempting to find out if *field1 *exists in the map using *has_key,
> *but am getting a compile error:
>
> error: no type named ‘category’ in ‘struct
> boost::fusion::result_of::as_map<boost::fusion::vector2<boost::fusion::pair<field1,
> int>, boost::fusion::pair<field2, int> > >
>
> Can anyone offer insight on what I'm doing wrong?
>
> I have a simple example below:
>
> #include <iostream>
> #include <boost/fusion/container.hpp>
> #include <boost/fusion/sequence.hpp>
> #include <boost/fusion/mpl.hpp>
> #include <boost/fusion/include/has_key.hpp>
> #include <boost/mpl/transform.hpp>
>
> namespace fusion = boost::fusion;
> namespace mpl = boost::mpl;
>
> *// given a field, returns a fusion pair of <field, field::type>*
> template<class field>
> struct make_pair
> {
> typedef typename fusion::result_of::make_pair<field, typename
> field::type>::type type;
> };
>
> *// given a sequence of fields, returns a fusion map which maps field ->
> field::type*
> template<class fields>
> struct make_map
> {
> typedef typename mpl::transform<fields, make_pair<mpl::_1>>::type
> pair_sequence;
> typedef typename fusion::result_of::as_map<pair_sequence> type;
> };
>
> *// sets boolean value to true if field is in fields*
> template <class field, class... fields>
> struct contains_key
> {
> typedef typename boost::fusion::vector<fields...> vector;
> typedef typename make_map<vector>::type map;
> typedef typename fusion::result_of::has_key<map, field>::type result;
>
> static const bool value = result();
> };
>
> struct field1 { typedef int type; };
> struct field2 { typedef int type; };
>
> int main()
> {
> std::cout << contains_key<field1, field1, field2>::value << std::endl;
> return 0;
> }
>
>
>



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