|
Boost Users : |
From: Ioffe, Robert (robert.ioffe_at_[hidden])
Date: 2003-08-15 14:40:43
The following code works:
#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"
&& true,
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 << constant("\n") && true));
return 0;
}
-----Original Message-----
From: Ioffe, Robert
Sent: Friday, August 15, 2003 12:24 PM
To: boost-users_at_[hidden]
Subject: [Boost-Users] Boost::lambda: Why the following code would not
compile?
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]
Info: <http://www.boost.org>
Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl>
Unsubscribe: <mailto:boost-users-unsubscribe_at_[hidden]>
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
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