Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » Discussion Thursdays?

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Discussion Thursdays?
alethiophile
Member #9,349
December 2007
avatar

Actually I haven't. I don't use C++; I only know it to the extent that it's based on C.

--
Do not meddle in the affairs of dragons, for you are crunchy and taste good with ketchup.
C++: An octopus made by nailing extra legs onto a dog.
I am the Lightning-Struck Penguin of Doom.

Vanneto
Member #8,643
May 2007

Well if you are interested here is a nice entry in C++ FAQ Lite.

In capitalist America bank robs you.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Quote:

How does that std::swap work? It shouldn't be able to swap variables in the calling context without getting pointers to them, unless C++ is much weirder than I thought.

A reference works like a pointer, but acts like an object.

mingw/include/c++/3.4.5/bits/stl_algobase.h lines 114 - 133

1//
2 /**
3 * @brief Swaps two values.
4 * @param a A thing of arbitrary type.
5 * @param b Another thing of arbitrary type.
6 * @return Nothing.
7 *
8 * This is the simple classic generic implementation. It will work on
9 * any type which has a copy constructor and an assignment operator.
10 */
11 template<typename _Tp>
12 inline void
13 swap(_Tp& __a, _Tp& __b)
14 {
15 // concept requirements
16 __glibcxx_function_requires(_SGIAssignableConcept<_Tp>)
17 
18 const _Tp __tmp = __a;
19 __a = __b;
20 __b = __tmp;
21 }
22 
23//

That's just one of many swaps though, but it's possible they mostly just use that one in varying ways - grep for swap in your compiler include directory.

Wetimer
Member #1,622
November 2001

One way to use bits in numbers is as a set. Suppose that you have ten items and want to represent subsets of those items. Simply use the first ten bits of an int, where 1 means its included and 0 means it is not included.

To check if a particular item is included

subset_flags & (1 << index)

Flip it using

subset_flag ^= (1 << index)

However, the neatest part is iteration

for(int subset = 0; subset < ( 1 << count_of_items_in_set);subset++)

This will iterate through all possible subsets. But due to nature of order through which it will go through the possiblities, for every set under consideration, all possible subsets will have already undergone consideration.

I.e. for the subset

1101

All of the following are before it:

1100
1001
0101
0001

<code>if(Windows.State = Crash) Computer.halt();</code>

Sol Blast
Member #9,655
April 2008
avatar

Topic's been dead for a few days I know, but I'll stick to with the plan anyway :P.

There was alot of good reading in this so far. It seems that a few folk learnt something, so the thread is working :).
Cheers to anyone who contributed this week.
I was intrigued by Thomas Harte's idea of putting this stuff into the wiki if the powers that be feel the information inputted here is valuable enough so far?
If so, I'd be happy to type it up in article form myself if no-one else would rather do it (giving credit to the original contributors of course ;)).

Either way however, the topic changes tomorrow. Has anyone got any suggestion for a new one they feel there's plenty of dicussion potential in?

weapon_S
Member #7,859
October 2006
avatar

Maybe you already noticed I tried to make a wiki entry under "bitwise operators".
But now I can't log-in anymore. I attached my second draft version you might use to complete it.(Notice I dubbed it "Thursday's topic".)
The reason last topic went so well however, is that there's little discussion about these things. And there is verifiable information. If I suggested "project(file)s" or "Open source game development", your average discussion chaos would occur, procuring any effort to transpose it into the wiki.
Oh, what also would be nice if you updated (in the future) your first post to have an index.

Sol Blast
Member #9,655
April 2008
avatar

Ahh, I seen that topic but i never noticed it was related to this topic haha.
I can't check our your attachment from where I am right now, but I'll have a look tonight and see if i can finish it off/ post it on the wiki if you're cool with that :).
About the subject matter, i think you're right. I'd love to hear what people have to say about proper OOP (I just can't get it right! :P), but the subject is covered in depth in so many places that i don't think anyone would really feel it's worth it to offer their two cents.

One idea I had been thinking about for discussion this week is function pointers. Any objections or better ideas?

Thomas Harte
Member #33
April 2000
avatar

Will you be just carrying on this thread or starting a new one?

Without wanting to say anything of them before Thursday, I can think of at least five things to say about function pointers...

Sol Blast
Member #9,655
April 2008
avatar

Wonderful. I look forward to hearing them :D.

I wasn't so sure about whether to start a new thread or not though.
On one hand it would be clearer, although on the other it may be regarded as 'spammy'.

Vanneto
Member #8,643
May 2007

1 Thread once a week is definitely not spammy. Open up a new thread to avoid confusion and mixing up subjects.

In capitalist America bank robs you.

Sol Blast
Member #9,655
April 2008
avatar

Thy will be done ;).

 1   2 


Go to: