Boost logo

Boost Users :

From: Ioffe, Robert (robert.ioffe_at_[hidden])
Date: 2003-08-15 14:23:52


The following code would not compile, since it complains about trying to
copy cout. Any comments?

 

Robert

 

#include <string>

#include <map>

#include <vector>

#include <iterator>

#include "boost/lambda/lambda.hpp"

#include "boost/lambda/bind.hpp"

#include "boost/lambda/algorithm.hpp"

 

using namespace boost::lambda;

using namespace std;

 

int main() {

        string s;

        typedef map<string, int> counters_t;

        typedef counters_t::value_type counters_value_t;

        counters_t counters;

        typedef map<int, vector<string> > occurences_t;

        typedef occurences_t::value_type occurences_value_t;

        occurences_t number_of_occurences;

 

        while(cin >> s)

                ++counters[s];

 

        for(map<string, int>::const_iterator it = counters.begin();

            it != counters.end(); ++it)

                number_of_occurences[it->second].push_back(it->first);

 

        std::for_each(number_of_occurences.begin(),
number_of_occurences.end(),

                (cout << bind(&occurences_value_t::first, _1) << ":\t",

                 bind(ll::for_each(),

                   bind(call_begin(), bind(&occurences_value_t::second,
_1)),

                   bind(call_end(), bind(&occurences_value_t::second,
_1)),

                   protect(cout << _1 << " ")),

                 cout << "\n"));

 

        return 0;

}

[Non-text portions of this message have been removed]


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