Help with Cryptic C++ code

Programming, for all ages and all languages.
User avatar
Candy
Member
Member
Posts: 3882
Joined: Tue Oct 17, 2006 11:33 pm
Location: Eindhoven

Re:Help with Cryptic C++ code

Post by Candy »

Solar wrote: Col. Kernel is right, though - STL style allocater functions would be a point where placement new would come in handy.
Well... any time you wanted to place an object in memory you control separately. That includes allocators and shared memory.
I've never seen anyone actually using the option of defining your own allocator functions, either... (You'd probably do this if you were optimizing like hell, but who does these days where labor is expensive, but better hardware is cheap...) ;)
I'll be at Breakpoint 2006, I promise.

It came in handy when trying to cut down on memory requirements for a large linked list or tree of one object type, so I made a separate allocator and used it. I can't stand people making algorithmic improvements and completely ignoring plain common sense.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Help with Cryptic C++ code

Post by Solar »

Candy wrote: It came in handy when trying to cut down on memory requirements for a large linked list or tree of one object type, so I made a separate allocator and used it. I can't stand people making algorithmic improvements and completely ignoring plain common sense.
No doubt and 100% ACK. But here at work our production server is running debug code because the additional testing of release code would cost more than the additional bits of RAM and CPU cycles... the beautiful difference between "business" and what you would like to do...
Every good solution is obvious once you've found it.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Help with Cryptic C++ code

Post by Neo »

In some other similar code (it used a multimap)
I saw that within the for loop the iter variable was used with a member 'second' as in

Code: Select all

iter->second;
Any idea what this 'second' refers to?
Only Human
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Help with Cryptic C++ code

Post by Solar »

Check the documentation for the "pair" container. A pair has two elements, pair->first and pair->second.
Every good solution is obvious once you've found it.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Help with Cryptic C++ code

Post by Neo »

Oh! I was looking at the multimap members and could not find any 'second' there.
Thanks Solar.
Only Human
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Help with Cryptic C++ code

Post by distantvoices »

@candy&solar: You tell how it's been at breakpoint 2006, yeah?

Some photostory. *gg*

It's a pity I canna show up there, but for one I have to attend university and for second I have to go to work *?rks* (and not too much free days left, eh?)
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Help with Cryptic C++ code

Post by Solar »

Neo wrote: Oh! I was looking at the multimap members and could not find any 'second' there.
I strongly recommend the library references available at http://www.dinkumware.com, if for nothing else but their fully searchable index. 8)
Every good solution is obvious once you've found it.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Help with Cryptic C++ code

Post by Neo »

Err.. ?????
Only Human
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Help with Cryptic C++ code

Post by Solar »

Well, Ctrl-F on the Dinkumware C++ reference index and searching for "second" would have given you three "hits":
  • binary_function::second_argument_type
  • pair::second
  • pair::second_type
I assume you would have been able to find out what that iter->second meant, given the above result.

Besides, it's a very useful reference in any case - if simply because you can have it on file instead of carrying a hardcopy around. ;)
Every good solution is obvious once you've found it.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Help with Cryptic C++ code

Post by Neo »

Neo wrote: Err.. ?????
That was to beyond_infinity's post.
Only Human
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Help with Cryptic C++ code

Post by Solar »

Ah... Breakpoint 2006 is where Candy, Pype and myself will meet each other the first time in person. BI was referring to Candy's earlier reference to that upcoming occasion.
Every good solution is obvious once you've found it.
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Help with Cryptic C++ code

Post by Neo »

Anyway a quick question on multimap iterators.
Multimaps allows more than I element with the same key.
So if I traverse through the list how does it go through the elements in the list (I can't test this out because my CYGWIN g++ is acting funny when I try to declare a multimap)
Only Human
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Help with Cryptic C++ code

Post by Solar »

When constructing a multimap, you can pass to the constructor a function object (predicate) that does the ordering. By default, this is [tt]less[/tt], meaning that, if you get two elements X, Y with X->first == Y->first, you will get one after another, but the exact order is unspecified (as neither is "less" than the other). This is called "strict weak ordering".
Every good solution is obvious once you've found it.
distantvoices
Member
Member
Posts: 1600
Joined: Wed Oct 18, 2006 11:59 am
Location: Vienna/Austria
Contact:

Re:Help with Cryptic C++ code

Post by distantvoices »

@NEO: if you have a problem with what I am posting you may as well consider talking to me in plain sentences so we can speak about the problem and get rid of the one or other difference, ok?

stay safe
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Help with Cryptic C++ code

Post by Neo »

@beyond_infinity: Now what was that all about?
Only Human
Post Reply