Boost logo

Boost Users :

Subject: Re: [Boost-users] mpl::for_each state
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-03-31 19:48:31


Skelly, Luke wrote:
> Please ignore my last message. I somehow accidentally sent it while still editing!
> I am trying to create a std::map from an mpl::map. I've been trying to figure out how to use mpl::for_each to accomplish this. The problem I have is that the runtime function is passed to for_each by value and returns void. All the examples I've seen for mpl::for_each involve printing and not creating any new objects. Here is the attempt I've made:
> <snip>
> The problem is in the call to mpl::for_each in the MapMaker constructor. The std::map is created, but never returned. I've considered making func_map static, but that complicates things quite a bit, especially since MapMaker it is a class template.

Have MapMaker store a reference to map. (Warning untested code)

typedef std::map<std::size_t, std::size_t> map_type;

struct MapMaker {
    map_type& m;
    template<class T>
    void operator()(T) const {

template<class MplMap>
map_type makeMap() {
    map_type result;
    MapMaker f = { result };
    return result;

In Christ,
Steven Watanabe

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at