map and for_each problem

M

Mehturt

Hi.. I have came across this problem, I don't know why it does not
work..
Thanks for your explanations..
m

#include <map>
#include <algorithm>

struct fo
{
void operator() (const std::pair<int, int>& pr)
{ }

void operator() (const std::pair<int, void*>& pr)
{ }
};

int main()
{
std::map<int, int> m;
std::map<int, void*> m2;

std::for_each(m.begin(), m.end(), fo());
std::for_each(m2.begin(), m2.end(), fo());

return 0;
}
 
?

=?ISO-8859-1?Q?Stefan_N=E4we?=

Hi.. I have came across this problem, I don't know why it does not
work..
Thanks for your explanations..
m

#include <map>
#include <algorithm>

struct fo
{
void operator() (const std::pair<int, int>& pr)
void operator() (const std::pair said:
{ }

void operator() (const std::pair<int, void*>& pr)
void operator() (const std::pair said:
{ }
};

int main()
{
std::map<int, int> m;
std::map<int, void*> m2;

std::for_each(m.begin(), m.end(), fo());
std::for_each(m2.begin(), m2.end(), fo());

return 0;
}

Check your local documentation of std::map::value_type.

/S
 
K

Kai-Uwe Bux

Hi.. I have came across this problem, I don't know why it does not
work..
Thanks for your explanations..
m

#include <map>
#include <algorithm>

struct fo
{
void operator() (const std::pair<int, int>& pr)

void operator() ( std::map said:
{ }

void operator() (const std::pair<int, void*>& pr)

void operator() ( std::map said:
{ }
};

int main()
{
std::map<int, int> m;
std::map<int, void*> m2;

std::for_each(m.begin(), m.end(), fo());
std::for_each(m2.begin(), m2.end(), fo());

return 0;
}

std::map<key_type,mapped_type> does not store data as

std::pair< key_type, mapped_type >

but as

std::pair< key_type const, mapped_type >.


Best

Kai-Uwe Bux
 
?

=?ISO-8859-1?Q?Stefan_N=E4we?=

I did, and now what?

You noticed that

std::map<T, U>::value_type

is

std::pair<const T, U> // Note the *const*

and not

std::pair<T, U>

,didn't you ?


/S
 
M

Mehturt

Stefan said:
You noticed that

std::map<T, U>::value_type

is

std::pair<const T, U> // Note the *const*

and not

std::pair<T, U>

,didn't you ?

Now I did but you could mention that in your 1st post..
 
J

Jim Langston

Stefan said:
You noticed that

std::map<T, U>::value_type

is

std::pair<const T, U> // Note the *const*

and not

std::pair<T, U>

,didn't you ?

Now I did but you could mention that in your 1st post..

He did. He had shown the code fixes, but without any white space they're a
little hard to see.
 
?

=?ISO-8859-15?Q?Stefan_N=E4we?=

Jim said:
Now I did but you could mention that in your 1st post..

He did. He had shown the code fixes, but without any white space they're a
little hard to see.

Mea Culpa...

/S
 
M

Mehturt

Jim said:
Now I did but you could mention that in your 1st post..

He did. He had shown the code fixes, but without any white space they're a
little hard to see.

Oh sorry about that, now I see it :(
Thanks a lot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,470
Messages
2,571,809
Members
48,797
Latest member
PeterSimpson
Top