|
niteice posted:XInput may also work for you, though it has very specific limitations. XInput is designed specifically for an Xbox 360 controller so it probably won't work with his racing wheel. Just use DirectInput.
|
# ? Apr 5, 2010 01:28 |
|
|
# ? Jun 1, 2024 23:25 |
|
It might work if it's a 360 wheel. I've never tried, but XInput technically should support them (XINPUT_DEVSUBTYPE_WHEEL.)
|
# ? Apr 5, 2010 05:13 |
|
I'm trying to work with the unordered_map in Boost for doing some hashing. I think my problem below is more an issue with templates and how to make them behave. This code is from snippets in unordered_map documentation uses to demonstrate the structure. You'll see that when the unordered_map is typedef'd the code is happy. If I try to spell out the full type, it will not compile.code:
|
# ? Apr 5, 2010 05:14 |
|
Comma confusing a macro, perhaps?
|
# ? Apr 5, 2010 05:16 |
|
Yeah, BOOST_FOREACH can't handle that.
|
# ? Apr 5, 2010 07:54 |
|
Put the type in parens. The preprocessor doesn't recognize < and > as grouping things and so it splits on the comma in your template. Also don't use that god-awful foreach macro (though it's admittedly better than rolling your own).
|
# ? Apr 5, 2010 13:03 |
|
Why do you hate it?
|
# ? Apr 5, 2010 13:17 |
|
Mustach posted:Why do you hate it? I'll let the source file speak for itself: http://www.boost.org/doc/libs/1_38_0/boost/foreach.hpp
|
# ? Apr 5, 2010 14:24 |
|
That's grosser than I expected.
|
# ? Apr 5, 2010 14:53 |
|
I am trying to sort an array of numbers and I am using the sort function in C++. Unfortunately, I cannot think of a way to also come up with an array of sorted indices, eg If my array is initially [9, 8, 6, 17], the sorted array using sort will be [6, 8, 9, 17], and I would also like to get the array of sorted indices: [3, 2, 1, 4]. Is it possible to get this?
|
# ? Apr 5, 2010 19:42 |
|
Initialize a second array to [0, 1, 2, 3, 4...] and perform every swap operation on it as well?
|
# ? Apr 5, 2010 19:43 |
|
I'm not familiar with sort, and I don't see a man page for it, but if it is like qsort you specify a comparison function for use by the sorting function. Make the array a vector of two elements, with the second element the index. Have your comparison function only use the first element of the vector, but pass the size of the entire vector to the sorting function so that they are swapped together.
|
# ? Apr 5, 2010 20:18 |
|
emf posted:I'm not familiar with sort, and I don't see a man page for it, but if it is like qsort you specify a comparison function for use by the sorting function. Make the array a vector of two elements, with the second element the index. Have your comparison function only use the first element of the vector, but pass the size of the entire vector to the sorting function so that they are swapped together. I ended up doing something very similar to this. Thank you.
|
# ? Apr 5, 2010 20:20 |
|
Avenging Dentist posted:Put the type in parens. The preprocessor doesn't recognize < and > as grouping things and so it splits on the comma in your template. Also don't use that god-awful foreach macro (though it's admittedly better than rolling your own). Sorry, but BOOST_FOREACH owns, not really much reason to not use it until range-based for. Even with 0x lambdas, BOOST_FOREACH is generally ahead of the game as opposed to std::for_each. Also, simply putting the type in parenthesis will not work. The way the parenthesis trick usually works with other macros is that inside the macro, the type parameter is referred to as something along the lines of function_traits< void your_type_param_name >::arg1_type. It can be made to account for [basic] cases of void by just having a metafunction that yields void when passed a function type with no args. The downsides of this are that it means you always have to pass your type in parenthesis regardless of whether or not is has commas, there are some cases it doesn't handle, at least not as intended (function types, array types, typedefed void, etc), and it internally may need to use typename cases where it's a dependent name. If you're using a compiler that supports the 0x use of auto (GCC works fine), just use auto with BOOST_FOREACH instead of specifying the type, unless you need to be portable to compilers that are not able to handle it yet. More portably, just use a typedef as described in the docs.
|
# ? Apr 6, 2010 08:11 |
|
ok this is likely a simple question but after a while of googling around I can't find a satisfactory example. I am creating a series of instrument objects which have parameters that need to be accessed and changed by a uniform system. So each object needs to have a set of parameters and each parameter needs a description, but the descriptions need to be unique and constant. So I want each instrument base class to define some constant parameter descriptions, however I get compiler errors whenever I try and declare a constant in the class interface. It looks a bit like this code:
|
# ? Apr 6, 2010 19:57 |
|
Construct the objects outside of the class.
|
# ? Apr 6, 2010 19:59 |
|
Avenging Dentist posted:Construct the objects outside of the class. is that really the best practice? I was doing that originally but I thought it made more sense to have the descriptions linked to the class. Especially since a bunch of different classes are going to have parameters with similar names like amp or frequency that may have different bounds.
|
# ? Apr 6, 2010 23:02 |
|
Zaxxon posted:is that really the best practice? It is not so much a "best practice" as "required by the standard". Note that you can keep them as class members. code:
|
# ? Apr 6, 2010 23:17 |
|
Got another couple of questions. I think I know the answers to both, but I want to be sure. 1) When using an ofstream, is there any way to write binary values using the stream operators, or do I have to use write() with a size? I suspect the latter, and though wrapping around that is no big deal, it seems strange. I woulda thought the ios::binary flag would change the behavior of the stream operators. 2) When templating a function, is it possible to make a particular attempted instantiation raise a compile-time error as below? (I suspect the answer is, again, "no, make it fail at runtime with an assert in a specialization or something") code:
|
# ? Apr 7, 2010 00:07 |
|
rjmccall posted:It is not so much a "best practice" as "required by the standard". Note that you can keep them as class members. ah! Thanks, thats what he meant! I feel dumb because I was trying to do something like this at first code:
|
# ? Apr 7, 2010 00:19 |
|
Ledneh posted:Got another couple of questions. I think I know the answers to both, but I want to be sure. iostreams are for formatted text output. The binary flag refers to opening a file in binary mode, that is not converting lineendings or whatever funny mechanics your OS imposes on text files. quote:2) When templating a function, is it possible to make a particular attempted instantiation raise a compile-time error as below? (I suspect the answer is, again, "no, make it fail at runtime with an assert in a specialization or something") This works for me: code:
|
# ? Apr 7, 2010 00:23 |
|
Vanadium posted:iostreams are for formatted text output. The binary flag refers to opening a file in binary mode, that is not converting lineendings or whatever funny mechanics your OS imposes on text files. Oh, okay. Should I be using something other than fstream for binary file writing/reading then, or is .write() and .read the best I'm going to get? And thanks for the template trick
|
# ? Apr 7, 2010 00:29 |
|
Vanadium posted:This works for me: http://codepad.org/HKgcutnR
|
# ? Apr 7, 2010 00:39 |
|
Avenging Dentist posted:http://codepad.org/HKgcutnR I'm so terrible at this profession.
|
# ? Apr 7, 2010 00:44 |
|
Avenging Dentist posted:http://codepad.org/HKgcutnR That's a link-time error.
|
# ? Apr 7, 2010 00:58 |
|
floWenoL posted:That's a link-time error. I like linking the errors are more fun.
|
# ? Apr 7, 2010 01:10 |
|
code:
|
# ? Apr 7, 2010 01:11 |
|
The correct answer is to use C++0x to add your own meaningful, smug diagnostic:code:
code:
code:
Flobbster fucked around with this message at 03:47 on Apr 7, 2010 |
# ? Apr 7, 2010 01:53 |
|
This isn't a question, but I think this is probably the best place for it. I've gotten really sick of YACC, ANTLR and Spirit so I decided to roll my own parser generator that's contained entirely in C++ like Spirit is. The idea is that at every assignment for a rule all of the parsed results get handed off to your function where you can process them and eventually return any type you want. In this case it's an int. I think the end result is simple, clean, easy to set up and gives you a lot of freedom to construct whatever you want. code:
It's a little rough around the edges of course. I've just implemented throw away (!) and optional (~) rules, but haven't tested them out yet.
|
# ? Apr 7, 2010 21:30 |
|
I'm (not) proud of this template exclusion solution. http://codepad.org/W2H3T5Ea
|
# ? Apr 7, 2010 22:02 |
|
You can reduce that entire second part to is_pointer. Also you forgot about volatile variables. http://codepad.org/MvuXbKPK
|
# ? Apr 7, 2010 22:16 |
|
Avenging Dentist posted:You can reduce that entire second part to is_pointer. Also you forgot about volatile variables. http://codepad.org/MvuXbKPK You're all over-complicating things http://codepad.org/lg4Cp1ab
|
# ? Apr 7, 2010 22:33 |
|
Well this post series was certainly a learning experience. Thanks for the education and correction
Ciaphas fucked around with this message at 00:33 on Apr 8, 2010 |
# ? Apr 8, 2010 00:29 |
|
I wish type_traits had a base type trait to strip out all arrays refs, pointers, and cv-qualifiers.
|
# ? Apr 8, 2010 01:39 |
|
That's what I was looking for at first when I started reading about the enable/disable_if constructs, yeah. Actually, on that last codepad, is the is_pointer clause even necessary? It looks like the star in the second is_convertible parameter covers that, making the is_pointer redundant, unless I'm missing something important here (read: I'm missing something).
|
# ? Apr 8, 2010 03:12 |
|
Ledneh posted:That's what I was looking for at first when I started reading about the enable/disable_if constructs, yeah.
|
# ? Apr 8, 2010 03:22 |
|
TTS explained it but here's the code: http://codepad.org/sMZ1yblu
|
# ? Apr 8, 2010 03:25 |
|
Slowly I continue to learn things. Thanks you two
|
# ? Apr 8, 2010 03:30 |
|
Hi guys, I hope you can help with what (I think) is a relatively stupid C question but for some reason I can't quite wrap my head around it. The classes I've done have sort of glossed over headers so they're still a bit confusing. Basically I've got a program with multiple (3) c files. I've got a structure that's used across all of them. Where do I define it and how do I import it? I tried creating a types.h file and putting it in there, but then the other header files threw a hissy fit because, I guess, they couldn't see it? I hope I'm explaining myself okay - can anyone help?
|
# ? Apr 9, 2010 07:41 |
|
|
# ? Jun 1, 2024 23:25 |
|
That's pretty much exactly what you want to do (put the structure declaration in a .h file), so you might have to be more specific about what is going wrong. If another header refers to your struct you need to include the struct header beforehand. Edit: code:
code:
UraniumAnchor fucked around with this message at 07:52 on Apr 9, 2010 |
# ? Apr 9, 2010 07:50 |