|
Vanadium posted:http://library.gnome.org/devel/gobject/unstable/index.html seems to be a pretty good place to start with gobject. Right, that's from the same documentation as the link in my first post. I was looking for something more along the lines of "Creating you're own custom GTK widgets" as opposed to "Understanding the nitty-gritty details of GObject, which by the way happens to be what GTK is based on, but let's not saying anything about GTK here. We'll leave that as an exercise for the reader."
|
# ? Jan 5, 2009 22:58 |
|
|
# ? Jun 7, 2024 11:11 |
|
Avenging Dentist posted:I definitely want to do the latter, but it gets a little bit hairy, since, in order to pass an associative container class template as a template argument, I'd need to know the exact number of template parameters it uses. Actually, it looks like GCC 4.4 handles this via N2555!
|
# ? Jan 5, 2009 23:16 |
|
Avenging Dentist posted:Yeah, I switched to using the tuple constructor. I'm not sure if it's dictated by the standard, but GCC's implementation of TR1 allows me to create a tuple of rvalue-refs and then pass that into the std::map, even though the map expects a tuple of value-types. I'd have to test it with a "noisy" class to make sure it minimizes copying, but it seems like it'd work. Avenging Dentist posted:I think you mean rvalue refs Avenging Dentist posted:The former should be pretty trivial, since I should just be able to drop tr1::function in there. Avenging Dentist posted:I definitely want to do the latter, but it gets a little bit hairy, since, in order to pass an associative container class template as a template argument, I'd need to know the exact number of template parameters it uses. Maybe concepts would help with that if they ever got pushed into GCC main (or the Standard, for that matter). Avenging Dentist posted:The updated version of all this malarkey is here: http://pastebin.com/f251786c4 Edit: Avenging Dentist posted:Actually, it looks like GCC 4.4 handles this via N2555! Never even saw this! That Turkey Story fucked around with this message at 00:01 on Jan 6, 2009 |
# ? Jan 5, 2009 23:52 |
|
That Turkey Story posted:I don't know how it is specified, but my gut is it's just working because the conversion is taking place during the argument passing to find and operator[]. You probably want to do the conversion externally to the key type before-hand to prevent the conversion from occurring multiple times. Yeah, that's the case. That Turkey Story posted:Rather than that, you'd probably want to allow them to override the function type via the template argument (if it's a function type, convert it to a function pointer to use internally, otherwise treat the type as a function object type and just use that internally). I'll probably mess with this a bit. It may even be possible to pass in a function as a template parameter to take advantage of inlining. That Turkey Story posted:Stuff about forwarding Right now, I'm just working on getting it to make fewer copies in general, before I worry about move semantics. Annoyingly, both GCC and MSVC seem to invoke 2 copy operations whenever you use the my_map[i] syntax.
|
# ? Jan 6, 2009 00:54 |
|
Avenging Dentist posted:I'll probably mess with this a bit. It may even be possible to pass in a function as a template parameter to take advantage of inlining. code:
Avenging Dentist posted:Right now, I'm just working on getting it to make fewer copies in general, before I worry about move semantics. Annoyingly, both GCC and MSVC seem to invoke 2 copy operations whenever you use the my_map[i] syntax. What's your code? It's probably because you are passing a type different from the key type, meaning a convert during argument passing and then a copy when storing it in the map. Edit: In other words because you did this in your posted code: code:
code:
That Turkey Story fucked around with this message at 02:05 on Jan 6, 2009 |
# ? Jan 6, 2009 01:54 |
|
That Turkey Story posted:What's your code? It's probably because you are passing a type different from the key type, meaning a convert during argument passing and then a copy when storing it in the map. Actually, there aren't any conversions, and it appears that operator[] creates an std::pair and passes it to insert. It also seems that tr1::tuple doesn't support move semantics, since I'm pretty sure I'm forwarding properly. Here's the code anyway. I also changed it so that the tuple doesn't store references if the function takes a reference. Oh, also my code is dangerous right now since it potentially moves an object and then uses the original object in the call to fcn_. EDIT: Ok, I wrote my own tuple class with move semantics, and I can confirm that the GCC TR1 implementation of tuple does not support move semantics. Based on N1403, there doesn't appear to be anything about move semantics in there, but that paper is pretty old, and I'm not sure if it's been superseded. EDITx2: Ahhh, I want <tuple> for the 0x code, not <tr1/tuple>. Avenging Dentist fucked around with this message at 07:48 on Jan 6, 2009 |
# ? Jan 6, 2009 02:22 |
|
Alright, be warned: this code is absolutely loving awful and uses a bunch of pointer hacks, but I managed to cut down the number of copies to just one when the map doesn't have the memoized value stored: http://pastebin.com/f1c82b332 EDIT: Updated Avenging Dentist fucked around with this message at 08:29 on Jan 6, 2009 |
# ? Jan 6, 2009 05:16 |
|
Just a small question: What's the real difference between "\n" and "endl"? My teacher recommended we use \n because you are more likely to avoid problems with it on other platforms, such as a Unix environment. I think I read somewhere that the only difference between the two was that "endl" flushes the I/O buffer, or something to that effect.
|
# ? Jan 8, 2009 12:51 |
|
Yes, endl just flushes in addition to the new line.
|
# ? Jan 8, 2009 15:27 |
|
That Turkey Story posted:Yes, endl just flushes in addition to the new line. Is endl OS specific or does it only add '\n' not "\r\n" on Windows in addition to flushing?
|
# ? Jan 8, 2009 15:39 |
|
hexadecimal posted:Is endl OS specific or does it only add '\n' not "\r\n" on Windows in addition to flushing? Outputting '\n' should do appropriate formatting (same with endl).
|
# ? Jan 8, 2009 15:46 |
|
hexadecimal posted:Is endl OS specific or does it only add '\n' not "\r\n" on Windows in addition to flushing? In text mode output streams on Win32, \n is automatically expanded to \r\n
|
# ? Jan 8, 2009 15:59 |
|
I am stupid and know almost nothing about using COM and ActiveX. Now I need to add some C++ code to our system that will call a third party's ActiveX methods, but all they sent was a document of the method names and a utility that vaguely has to do with the interface but contains no header files or the OCX file named in the documentation. I assume I need those and the utility files are of no use for this task (exes and dlls). This other company likes to forget about conference calls that they schedule with us, and wait several weeks to send requested documentation, so I wouldn't put it past them to knowingly not send what I need. But since I'm new at this stuff, I don't want to look like a dumbass and ask for stuff I don't need. I mean I am a dumbass, but they don't need to know that. Edit in case the question wasn't clear - what do I need from a third party to call their ActiveX methods? opie fucked around with this message at 18:33 on Jan 8, 2009 |
# ? Jan 8, 2009 17:54 |
|
csammis posted:In text mode output streams on Win32, \n is automatically expanded to \r\n This should probably go into the coding horrors thread because the automatic new line conversion makes it impossible to pipe binary data between processes. Le sigh.
|
# ? Jan 8, 2009 18:04 |
|
ehnus posted:This should probably go into the coding horrors thread because the automatic new line conversion makes it impossible to pipe binary data between processes.
|
# ? Jan 8, 2009 18:09 |
|
I've just started dabbling in C++ for a course I am on, and I'm having some trouble with this matrix. I just need a 3x3 matrix, filled in with 1-9, so I am using this function to initialise it:code:
Edit: another way I'm trying is: code:
honeymustard fucked around with this message at 19:05 on Jan 8, 2009 |
# ? Jan 8, 2009 19:01 |
|
honeymustard posted:I've just started dabbling in C++ for a course I am on, and I'm having some trouble with this matrix. I just need a 3x3 matrix, filled in with 1-9, so I am using this function to initialise it: You've got the loop that controls the value you assign as the outermost one, so you're actually writing the entire array 10 times. It just so happens that the last time around it writes 9 to every index.
|
# ? Jan 8, 2009 19:06 |
|
honeymustard posted:Problem is, it seems to fill in every position with 9, rather than incrementing it. Is there an easier way of doing it that I'm missing? Add in a few prints and see if you can follow the logic: code:
|
# ? Jan 8, 2009 19:06 |
|
The problem is in your loop logic. You don't need the outer loop for c. code:
|
# ? Jan 8, 2009 19:07 |
|
honeymustard posted:Problem is, it seems to fill in every position with 9, rather than incrementing it. Is there an easier way of doing it that I'm missing? The "clever" way; deriving the data from the indices. code:
code:
|
# ? Jan 8, 2009 19:07 |
|
Wow, thanks for all the replies, haha. whoknew, TSDK: I see now, the print makes it clear what's happening - thanks. Edit: I also had a mistake in the print function, which made it unclear what was going on, so adding the print inside the loop was very helpful indeed. Thanks again honeymustard fucked around with this message at 19:13 on Jan 8, 2009 |
# ? Jan 8, 2009 19:10 |
|
ShoulderDaemon posted:The "naive" way; using an explicit accumulator. Why do you have ; after } Is it any different than from omitting it?
|
# ? Jan 8, 2009 19:11 |
|
hexadecimal posted:Why do you have ; after } No, it's just habit from other languages which require it.
|
# ? Jan 8, 2009 19:14 |
|
ShoulderDaemon posted:No, it's just habit from other languages which require it.
|
# ? Jan 8, 2009 21:29 |
|
hexadecimal posted:Why do you have ; after }
|
# ? Jan 8, 2009 21:45 |
|
That Turkey Story posted:Yes, endl just flushes in addition to the new line. ShoulderDaemon posted:The "clever" way; deriving the data from the indices. Oh, that's weird, so C++ does all calculations linearly if you don't specify otherwise (with parenthises or whatever)? I first looked at that and thought it would do it like "3(i+j+1)". Also, how would I make an array's dimension size dependent upon the user input? Like if I entered 4, it would make the array in question 4-dimensional.
|
# ? Jan 8, 2009 22:52 |
|
Anunnaki posted:So does it really matter which one you use? I am pretty sure C++ and any other serious languages do operator precedence. So if you have a + b + c * d it is not going to be (a+b+c)*d, but the correct way you'd expect it to be, i.e. a + b + (c*d) For your second question, the easiest way is to use a one dimensional array but come up with a mapping formula, so you can treat it as n-dimensional array. Easiest example is how to represent a 2d array using 1d array. if i and j are coordinates of 2d array then in 1d array they would map to new index n = (j*size_in_i)+i hexadecimal fucked around with this message at 23:05 on Jan 8, 2009 |
# ? Jan 8, 2009 22:59 |
|
Anunnaki posted:I first looked at that and thought it would do it like "3(i+j+1)".
|
# ? Jan 8, 2009 23:01 |
|
Anunnaki posted:So does it really matter which one you use? Uh, C++ follows the proper mathematical order of operations. If somebody told you x = 3 * 2 + 1 + 2, would you say that x is 9 or 15? Obviously 9. Why would C++ do it any other way? TheSleeper fucked around with this message at 23:05 on Jan 8, 2009 |
# ? Jan 8, 2009 23:03 |
|
TheSleeper posted:Uh, C++ follows the proper order of operations. If somebody told you x = 3 * 2 + 1 + 2, would you say that x is 9 or 15? Obviously 9. Why would C++ do it any other way?
|
# ? Jan 8, 2009 23:04 |
|
Dijkstracula posted:To make it easier for compiler writers Welcome to the wild and wooly world of MUMPS!
|
# ? Jan 8, 2009 23:07 |
|
Dijkstracula posted:To make it easier for compiler writers It's all baggage from C anyway, so this ship sailed a long time ago.
|
# ? Jan 8, 2009 23:18 |
|
TheSleeper posted:Uh, C++ follows the proper mathematical order of operations. If somebody told you x = 3 * 2 + 1 + 2, would you say that x is 9 or 15? Obviously 9. Why would C++ do it any other way? Oh, wait, never mind, I was thinking of something like x = 3 * 2 + 1 + 4 * 5, in which you'd do the multiplications first. Never mind I said anything. Brain fart. Edit: VVVVVVVVV Is that not what I said? Cosmopolitan fucked around with this message at 01:49 on Jan 9, 2009 |
# ? Jan 8, 2009 23:54 |
|
Anunnaki posted:Oh, wait, never mind, I was thinking of something like x = 3 * 2 + 1 + 4 * 5, in which you'd do the multiplications first. Never mind I said anything. Brain fart. I think your brain is still farting, because you ALWAYS do multiplication before addition when parentheses do not indicate otherwise. Always.
|
# ? Jan 9, 2009 00:54 |
|
Avenging Dentist posted:Alright, be warned: this code is absolutely loving awful and uses a bunch of pointer hacks, but I managed to cut down the number of copies to just one when the map doesn't have the memoized value stored: http://pastebin.com/f1c82b332 What... is it?
|
# ? Jan 9, 2009 04:27 |
|
UberJumper posted:What... is it? It memoizes the results of a function.
|
# ? Jan 9, 2009 04:29 |
|
To follow up on my previous post... What I'm trying to do is a simple tic tac toe game with one player and computer (which generates a random position), using a 3x3 matrix (which is filled with 1-9, so the player or computer picks one of those numbers). It's pretty much finished now, except I'm trying to add some validation, so the player or computer cannot choose a position that is already occupied from a previous turn. I just can't figure out how to implement this though... the code I'm using for the computer's turn is: code:
|
# ? Jan 9, 2009 19:15 |
|
Use constant characters for player and computer. In your matrix put 'c' for computer having a piece there and 'p' for player having a piece there. Use some other character or 0 to represent empty square. You really don't have to use characters, you can just use an integer to represent computer and player. Just make sure that player is always represented by same number/character, and so is computer. To generate a random move, generate 2 random numbers in range 0<=n<3. Check if the random coordinate you generated is occupied or not, and repeat until you hit unoccupied one. That is probably the easiest way. However, you can use a queue. Generate all 9 coordinates, then put them in random position in linked list. Then just read the first one in that linked list to get your random coordinate, then remove it, and so on. This way you wouldn't be doing needless loop cycles. code:
hexadecimal fucked around with this message at 19:28 on Jan 9, 2009 |
# ? Jan 9, 2009 19:19 |
|
Well the thing is, in the specification, it says we have to have 1-9 in the matrix, and then X and O for the pieces. Edit: didn't see the edited stuff you added, I'll give that a try. Cheers
|
# ? Jan 9, 2009 19:22 |
|
|
# ? Jun 7, 2024 11:11 |
|
honeymustard posted:Well the thing is, in the specification, it says we have to have 1-9 in the matrix, and then X and O for the pieces. Do you have to print it out using X or O or use such char in your matrix? If its just for printing out, then you can really use whatever you want for your actual matrix.
|
# ? Jan 9, 2009 19:30 |