C++ ::value_type

Hey,

Looking at these lines:

typedef map<SomeKeyType, SomeValueType*>::iterator   SomeName;
typedef map<SomeKeyType, SomeValueType*>::value_type  SomeOtherName;

I understand the iterator one, I use syntax like that plenty -- but what is ::value_type, and what is SomeOtherName useful for after this declaration?

Thanks,

-w00te
LVL 12
w00teAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
Infinity08Commented:
>> but what is ::value_type

it is the type of the value stored in the map. In the case of a map, it is a pair.


>> and what is SomeOtherName useful for after this declaration?

as a shorthand for map<SomeKeyType, SomeValueType*>::value_type ... it's simply an alias to simplify the code somewhat (and also to abstract some of the implementation details).
0
 
lucky_jamesCommented:
its the iterator function to return the type of value associated with that iterator.
check out:
http://www.sgi.com/tech/stl/value_type.html
http://msdn.microsoft.com/en-us/library/bb385860.aspx
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
Infinity08Commented:
>> In the case of a map, it is a pair.

Or specifically, in your case : std::pair<const SomeKeyType, SomeValueType*>
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
Infinity08Commented:
>> its the iterator function to return the type of value associated with that iterator.

No, it's defined at the level of the STL container (a map in this case).
The iterator makes use of it though.
0
 
w00teAuthor Commented:
I appreciate both responses and they both helped, but I was only really asking about  what ::value_type meant specifically as ooposed to the whole typedef so I assigned some more points to that solution.  Split points, thank you both!
0
 
Infinity08Commented:
>> I appreciate both responses and they both helped, but I was only really asking about what ::value_type meant specifically as ooposed to the whole typedef so I assigned some more points to that solution.

I thought that was what I explained :) value_type is a typedef at the level of the STL map container that defines the type of the values stored in it. That's what value_type is.

This has nothing to do with iterators, although iterators do make use of this typedef.

Both links posted in lucky_james's post are not related to your question. The first is about the value_type function defined in iterators, and the second is about some specific Microsoft implementation details.
0
 
w00teAuthor Commented:
Yeah actually i hadn't read into the links much, his post just made me remember how I've used the value_type member in the past (was more a process in my head than the actual solution).
You're right though upon further look your post makes more sense, it just didn't trigger the response in my head at the time.  If I could swap the points I would -- sorry about that.  I'll be more careful in the future!
0
 
Infinity08Commented:
No worries. As long as you have your answer you needed, I'm happy :) I just wanted to make sure you knew that those links aren't exactly about what was asked :)
0
 
w00teAuthor Commented:
Haha, well thanks.  I appreciate the helpfulness :)
0
 
lucky_jamesCommented:
Sorry Guys, for the delay in response. Was out for sometime.

>>Both links posted in lucky_james's post are not related to your question. The first is about the value_type function defined in iterators, and the second is about some specific Microsoft implementation details.

Regarding the first link, Infinity has already said that its a typedef and i just want to show that with some more description. That its a type has already been described in my first post.
I still thought why w00te had chosen this question to include the Microsoft Visual C++.Net in the zones. so he might be interested in looking the microsoft specific details of value_type which is applicable, obviously, for microsoft compilers. To say that whether we should say that this "some specific Microsoft implementation details" should be comsidered as a part of  STL or not is debatable as MSDN itself states (STL/CLR) in the heading alongwith the topic name map::value_type .
 
I hope, this justifies how the links were relevant to the question.
What else, the points? i never thought of stealing the points off something what even the author does not think that I deserve. :) Inifinity and jkr are the guys I would love to offer my points to (becoz I myself have learnt a lot from them...). So, w00te, you can always raise the concern to moderator and get things sorted out.
 
regards,
James
0
 
Infinity08Commented:
lucky_james, the value_type that was mentioned in the question is NOT a function defined for iterators. It is instead the type defined in the map container. I know the choice of names might be confusing, but there is a difference ;)

An sgi link that would have been relevant is : http://www.sgi.com/tech/stl/Map.html
0
 
phoffricCommented:
The force that causes acceleration on an object is the net force on the object. When talking about the force due to gravity, we do not write F=mA, we write F = mg, where g is a gravitational constant vector (almost constant around sea level on the Earth).

Only if there is a net force will the object accelerate (and it could be rotational acceleration rather than translational acceleration).
0
 
phoffricCommented:
I wondered why my previous post did not appear in the question when I looked again later. So ignore previous post and this one unless you're interested in OT.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.