calling map::insert through bind.
Hi list.
I've got a question on calling map::insert using bind. What I'd like to
do is to copy all members in m into m2:
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include
On 8/23/06, Minkoo Seo
for_each(m.begin(), m.end(), bind(&map
::insert, &m2, bind(&make_pair, bind(&map ::value_type::first, _1), bind(&map ::value_type::second, _1)))); Unfortunately, the above code fails to compile and I have no idea why it fails. I'm using g++ and the errors are as follows:
First off, just thought I would mention that for an example such as this,
regular boost::bind would probably suffice. You don't need lambda.
Second of all, I don't know which insert function you are trying to call,
but you should be able to write this code instead, which is much simpler:
for_each(m.begin(), m.end(),
bind(&map
On 8/23/06, Phillip Hellewell
[snipped]
Now after going to ALL that work just so you can use for_each, don't you just want to forget it and use iterators?
for( map
::const_iterator it = m.begin(); it != m.end(); ++it ) m2.insert(*it);
And after ALL this, you could write just:
std::map
Phillip Hellewell
-- Felipe Magno de Almeida
participants (3)
-
Felipe Magno de Almeida
-
Minkoo Seo
-
Phillip Hellewell