Boost logo

Boost Users :

From: David Greene (greened_at_[hidden])
Date: 2004-12-20 12:19:49


I'm not understanding something about the interaction of map with
the algorithms. I've got a map whose value_type is another map.
I'd like to iterate through the map entries and add all the "sub-map"
entries to the "primary" map. I wrote a little testcase, attached
below. When I compile it with g++ 3.3.3, I get this:

boost-1_32/boost/mpl/pair.hpp: In instantiation of
`boost::mpl::second<mpl_::_2>':
fold2.cc:23: instantiated from
`boost::mpl::value_type_impl<boost::mpl::aux::map_tag>::apply<map_types,
mpl_::_2>'
fold2.cc:23: instantiated from `boost::mpl::value_type<map_types,
mpl_::_2>'
fold2.cc:23: instantiated from here
boost-1_32/boost/mpl/pair.hpp:56: error: no
    type named `second' in `struct mpl_::_2'
fold2.cc:23: error: `types' is not a member of type `
    boost::mpl::value_type<map_types, mpl_::_2>'
fold2.cc:24: error: template argument 1 is invalid
fold2.cc:24: error: ISO C++ forbids declaration of `type name' with no type
boost-1_32/boost/mpl/aux_/preprocessed/gcc/fold_impl.hpp: In
instantiation of `boost::mpl::apply_wrap2<int, map_types,
boost::mpl::pair<key1, entry> >':
boost-1_32/boost/mpl/aux_/preprocessed/gcc/fold_impl.hpp:49:
instantiated from `boost::mpl::apply2<int, map_types,
boost::mpl::pair<key1, entry> >'
boost-1_32/boost/mpl/aux_/preprocessed/gcc/fold_impl.hpp:49:
instantiated from `boost::mpl::aux::fold_impl<1,
boost::mpl::m_iter<map_types, 2, 3>, boost::mpl::m_iter<map_types, 3,
3>, map_types, int>'
boost-1_32/boost/mpl/fold.hpp:39: instantiated from
`boost::mpl::fold<map_types, map_types, int>'
fold2.cc:24: instantiated from here
boost-1_32/boost/mpl/aux_/preprocessed/gcc/fold_impl.hpp:49: error: `
    int' is not a class, struct, or union type
boost-1_32/boost/mpl/aux_/preprocessed/gcc/fold_impl.hpp: In
instantiation of `boost::mpl::aux::fold_impl<1,
boost::mpl::m_iter<map_types, 2, 3>, boost::mpl::m_iter<map_types, 3,
3>, map_types, int>':
boost-1_32/boost/mpl/fold.hpp:39: instantiated from
`boost::mpl::fold<map_types, map_types, int>'
fold2.cc:24: instantiated from here
boost-1_32/boost/mpl/aux_/preprocessed/gcc/fold_impl.hpp:49: error: no
    type named `type' in `struct boost::mpl::apply2<int, map_types,
    boost::mpl::pair<key1, entry> >'
boost-1_32/boost/mpl/aux_/preprocessed/gcc/fold_impl.hpp: In
instantiation of `boost::mpl::aux::fold_impl<1,
boost::mpl::m_iter<map_types, 2, 3>, boost::mpl::m_iter<map_types, 3,
3>, map_types, int>':
boost-1_32/boost/mpl/fold.hpp:39: instantiated from
`boost::mpl::fold<map_types, map_types, int>'
fold2.cc:24: instantiated from here
boost-1_32/boost/mpl/aux_/preprocessed/gcc/fold_impl.hpp:53: error: no
    type named `type' in `struct boost::mpl::apply2<int, map_types,
    boost::mpl::pair<key1, entry> >'
boost-1_32/boost/mpl/fold.hpp: In instantiation of
`boost::mpl::fold<map_types, map_types, int>':
fold2.cc:24: instantiated from here
boost-1_32/boost/mpl/fold.hpp:39: error: no
    type named `state' in `struct boost::mpl::aux::fold_impl<1,
    boost::mpl::m_iter<map_types, 2, 3>, boost::mpl::m_iter<map_types,
3, 3>,
    map_types, int>'
fold2.cc:24: error: syntax error before `;' token
fold2.cc:26: error: syntax error before `::' token

An EDG-based compiler gives much the same error.

What am I doing wrong?

Much thanks for the help!

                            -Dave

#include <boost/mpl/fold.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/copy.hpp>
#include <boost/mpl/map.hpp>
#include <boost/mpl/value_type.hpp>
#include <boost/mpl/inserter.hpp>
#include <boost/mpl/insert.hpp>
#include <boost/mpl/pair.hpp>

using namespace boost;
using namespace boost::mpl;

struct key1 {};
struct key2 {};

struct entry {
    typedef map<pair<key2, int> > types;
};

typedef map<pair<key1, entry> > map_types;

typedef fold<map_types, map_types,
              copy<value_type<map_types, _2>::types,
              inserter<_1, insert<_1, _2> > > >::type result;

result::blah; // Get a printout


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