P
pillbug
I'm having trouble using bind1st with mem_fun1. I can't compile
the line marked below with a @@. If I use the join2 method everything
is fine, but I wind up passing string vectors by value. I would like
to use the reference passing version, or something similar.
The errors I get point the finger at binder1st:
perator() being defined
as "const argument_type&" which becomes "const const string_vector&&"
when i use Joiner::join below.
Any advice would be appreciated. I use vc7.1
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <iostream>
typedef std::basic_string<char> string;
typedef std::vector<string> string_vector;
struct Joiner {
string join (const string_vector& v) {
return std::accumulate (v.begin(), v.end(), string()); }
string join2 (string_vector v) {
return std::accumulate (v.begin(), v.end(), string()); }
};
int main (int argc, char** argv)
{
// a 10x7 matrix of strings initialized to "Text"
std::vector<string_vector> vv (10, string_vector (7, "Text"));
Joiner j;
string_vector result (vv.size());
std::transform (vv.begin(), vv.end(),
result.begin(),
//std::bind1st (std::mem_fun1 (&Joiner::join), &j)); //error
std::bind1st (std::mem_fun1 (&Joiner::join2), &j));
std::copy (result.begin(), result.end(),
std:
stream_iterator<string> (std::cout, "\n"));
return 1;
}
the line marked below with a @@. If I use the join2 method everything
is fine, but I wind up passing string vectors by value. I would like
to use the reference passing version, or something similar.
The errors I get point the finger at binder1st:
as "const argument_type&" which becomes "const const string_vector&&"
when i use Joiner::join below.
Any advice would be appreciated. I use vc7.1
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <iostream>
typedef std::basic_string<char> string;
typedef std::vector<string> string_vector;
struct Joiner {
string join (const string_vector& v) {
return std::accumulate (v.begin(), v.end(), string()); }
string join2 (string_vector v) {
return std::accumulate (v.begin(), v.end(), string()); }
};
int main (int argc, char** argv)
{
// a 10x7 matrix of strings initialized to "Text"
std::vector<string_vector> vv (10, string_vector (7, "Text"));
Joiner j;
string_vector result (vv.size());
std::transform (vv.begin(), vv.end(),
result.begin(),
//std::bind1st (std::mem_fun1 (&Joiner::join), &j)); //error
std::bind1st (std::mem_fun1 (&Joiner::join2), &j));
std::copy (result.begin(), result.end(),
std:
return 1;
}