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 counters_t;
typedef counters_t::value_type counters_value_t;
counters_t counters;
typedef map occurences_t;
typedef occurences_t::value_type occurences_value_t;
occurences_t number_of_occurences;
while(cin >> s)
++counters[s];
for(map::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@yahoogroups.com
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 counters_t;
typedef counters_t::value_type counters_value_t;
counters_t counters;
typedef map occurences_t;
typedef occurences_t::value_type occurences_value_t;
occurences_t number_of_occurences;
while(cin >> s)
++counters[s];
for(map::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@yahoogroups.com
Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/