468,491 Members | 1,961 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,491 developers. It's quick & easy.

map and for_each problem

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, intm;
std::map<int, void*m2;

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

return 0;
}

Aug 15 '06 #1
9 10143
Me*****@gmail.com schrieb:
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<const int, int>& pr)
{ }

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

int main()
{
std::map<int, intm;
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
--
Stefan Naewe
stefan_DOT_naewe_AT_atlas_DOT_de
Aug 15 '06 #2
Check your local documentation of std::map::value_type.
I did, and now what?

Aug 15 '06 #3
Me*****@gmail.com wrote:
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<int, int>::value_type const & pr )
{ }

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

int main()
{
std::map<int, intm;
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_typedoes not store data as

std::pair< key_type, mapped_type >

but as

std::pair< key_type const, mapped_type >.
Best

Kai-Uwe Bux
Aug 15 '06 #4
std::map<key_type,mapped_typedoes not store data as
>
std::pair< key_type, mapped_type >

but as

std::pair< key_type const, mapped_type >.
Great, thanks for your help..

Aug 15 '06 #5
Me*****@gmail.com schrieb:
>Check your local documentation of std::map::value_type.

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
--
Stefan Naewe
stefan_DOT_naewe_AT_atlas_DOT_de
Aug 15 '06 #6
Stefan Nwe wrote:
Me*****@gmail.com schrieb:
Check your local documentation of std::map::value_type.
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 ?
Now I did but you could mention that in your 1st post..

Aug 15 '06 #7
<Me*****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Stefan Nwe wrote:
Me*****@gmail.com schrieb:
Check your local documentation of std::map::value_type.
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 ?
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.
Aug 15 '06 #8
Jim Langston schrieb:
<Me*****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Stefan Nwe wrote:
>Me*****@gmail.com schrieb:
>>>Check your local documentation of std::map::value_type.
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 ?

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
--
Stefan Naewe
stefan_DOT_naewe_AT_atlas_DOT_de
Aug 16 '06 #9

Jim Langston wrote:
<Me*****@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
Stefan Nwe wrote:
Me*****@gmail.com schrieb:
>Check your local documentation of std::map::value_type.
>
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 ?

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

Aug 17 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Alberto | last post: by
11 posts views Thread by franklini | last post: by
6 posts views Thread by Michal Wyrebski | last post: by
1 post views Thread by Capstar | last post: by
12 posts views Thread by sashan | last post: by
3 posts views Thread by PolkaHead | last post: by
9 posts views Thread by Chris Roth | last post: by
13 posts views Thread by Sarath | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.