produced by g++. The programs below works fine, until I uncomment out
the two "transform" lines. Then it points me to line 24 (where the
second "bind1st" is) and results in an error message complaining about
no match for 'operator=' and/or problems with 'back_insert_it erator'
(see the entire error message reproduced below). Do I need a cast
somewhere to keep the type-checker happy? Is it a template problem?
Since I'm working with standard containers, I can't imagine that
there's no assignment operator defined. Is there a subtle mistake I've
made, or am I doing something obviously wrong? In addition to figuring
out this particular error, I'd also appreciate general strategies for
figuring out compiler messages produces by g++. Do commercial products
do a better job in the error message department?
Thanks,
Greg Buchholz
#include <list>
#include <string>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <functional>
using namespace std;
list<string> aux(list<string > ps, string n);
int main()
{
list<string> f, out;
f.push_back("fo o");
f.push_back("ba r");
f.push_back("ba z");
list<string> g = bind1st(ptr_fun (*aux),f)("TEST ");
//transform(f.beg in(),f.end(),ba ck_inserter(out ),
// bind1st(ptr_fun (aux),f));
copy(g.begin(), g.end(),ostream _iterator<strin g>(cout, " "));
cout << endl;
return 0;
}
list<string> aux(list<string > ps, string n)
{
list<string> out;
transform(ps.be gin(),ps.end(), back_inserter(o ut),
bind1st(plus<st ring>(),n));
return out;
}
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.2/../../../../include/c++/3.4.2/bits/stl_algo.h:
In function `_OutputIterato r std::transform( _InputIterator,
_InputIterator, _OutputIterator , _UnaryOperation ) [with _InputIterator
=
std::_List_iter ator<std::strin g>, _OutputIterator =
std::back_inser t_iterator<std: :list<std::stri ng,
std::allocator< std::string> > >, _UnaryOperation =
std::binder1st< std::pointer_to _binary_functio n<std::list<std ::string,
std::allocator< std::string> >, std::string, std::list<std:: string,
std::allocator< std::string> > > >]': test3.cpp:24: instantiated from
here
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.2/../../../../include/c++/3.4.2/bits/stl_algo.h:789:
error: no match for 'operator=' in
'(&__result)->std::back_inse rt_iterator<_Co ntainer>::opera tor* [with
_Container = std::list<std:: string, std::allocator< std::string> >]() =
std::binder1st< _Operation>::op erator()(typena me
_Operation::sec ond_argument_ty pe&) const [with _Operation =
std::pointer_to _binary_functio n<std::list<std ::string,
std::allocator< std::string> >, std::string, std::list<std:: string,
std::allocator< std::string> >
](((std::string& )(+(&__first)->std::_List_ite rator<_Tp>::ope rator*
[with _Tp = std::string]())))'
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator.h: 363:
note: candidates are: std::back_inser t_iterator<_Con tainer>&
std::back_inser t_iterator<_Con tainer>::operat or=(typename
_Container::con st_reference) [with _Container = std::list<std:: string,
std::allocator< std::string> >]
/usr/local/lib/gcc/i686-pc-linux-gnu/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator.h: 338:
note: std::back_inser t_iterator<std: :list<std::stri ng,
std::allocator< std::string> > >&
std::back_inser t_iterator<std: :list<std::stri ng,
std::allocator< std::string> > >::operator=(co nst
std::back_inser t_iterator<std: :list<std::stri ng,
std::allocator< std::string> > >&)