|
rjmccall posted:Hilariously, standard C++ doesn't let you specialize member templates of non-fully-specialized templates. The only compliant solution is to hoist the member templates out of the class and specialize them there; for example, you would need to have: Hmm, I think I see, I'll give it a go. Is there a reason the standard is this way and not the way MSVC permits? It seems far more sensible and readable. edit: Ok, I don't see it at all. What on earth am I meant to do? I'm having trouble seeing the logic here. xPanda fucked around with this message at 10:10 on Jun 16, 2010 |
# ? Jun 16, 2010 08:56 |
|
|
# ? Jun 9, 2024 02:04 |
|
No good reason. There are some wierdnesses, but as long as it's understood that you can't specialize members along different dimensions than the enclosing template (†), everything stays reasonable. I don't know whether MSVC allows member specializations to be defined out-of-line or specifies what the interaction between specializations in the template and "standard" explicit member specializations is supposed to be, though. † I mean like this: code:
|
# ? Jun 16, 2010 10:36 |
|
In what little free time I have, I started playing around with llvm, specifically the Kaleidoscope tutorial they have on their website. Holy crap, it's a beautiful piece of software. I want to familiarize myself with it and design my own toy language, but I've been out of the programming languages/compilers scene for a while (the last time I did anything I was playing with lex and yacc). Is there a highly recommended parser generator out there that generates C++ code? I know there's Boost.Spirit, but looking at some of the sample code makes my head hurt and I'm wondering how hideous it would look with a grammar of any significant size.
|
# ? Jun 16, 2010 15:20 |
|
Hi! I've been trying to learn socket programming, but have run into a problem. I copied one of the server examples from http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html and have been using a data generator a friend of mine made a while ago. It connects once, all the data goes through, but when it gets to the accept() call in the while loop again I get a segmentation fault. Here is my code http://codeviewer.org/view/code:fed and here is an example of what the data generator is sending (not sure if it's relevant, but whatevs): code:
I ran it through gdb, just to try to figure stuff out and here is the output from that: http://codeviewer.org/view/code:fee Thanks, and if you need any more info from me please let me know
|
# ? Jun 16, 2010 18:27 |
|
Flobbster posted:In what little free time I have, I started playing around with llvm, specifically the Kaleidoscope tutorial they have on their website. Holy crap, it's a beautiful piece of software. I don't have any experience with spirit although people here seem to like it. You can use Bison+flex to make C++ parsers/scanners, though.
|
# ? Jun 16, 2010 20:51 |
|
xPanda posted:edit: Ok, I don't see it at all. What on earth am I meant to do? I'm having trouble seeing the logic here. Didn't see your edit before. Under the standard, you cannot specialize a template in dependent context. So if you have a member template nested within a class template, you can only specialize it for one specific specialization of the outer template; you can't specialize it for, say, an entire pattern of specializations of the outer template ("pattern" meaning something like "primary template or partial specialization thereof"). The solution is to hoist the member template out of the class template, like I did with R, and then specialize it there. With member function templates this is actually really annoying/difficult/impossible, but unfortunately that's what's required.
|
# ? Jun 16, 2010 21:57 |
|
Painless posted:I don't have any experience with spirit although people here seem to like it. You can use Bison+flex to make C++ parsers/scanners, though. Note that bison+flex may not be able to do everything you need (like if you wanted to write a parser for C++!), and Boost.Spirit has a lot of other built-in niceties that bison+flex may not have. It's been a while since I used bison+flex, but as I recall, they don't have stuff that automatically handles things like delimited lists or escape sequences in strings, both of which Spirit can do really easily. Of course, if you mistype anything in Spirit, you are in for a world of pain, so it all depends on your tolerance for template errors. You could probably compile it under clang though, and you'd get some decent error messages, but I'm not sure how much that'd help.
|
# ? Jun 17, 2010 00:33 |
|
C# question here. Is it possible to pass a list as an argument into a function? Or do I have to convert it to an array first? code:
RonniePudding fucked around with this message at 00:49 on Jun 18, 2010 |
# ? Jun 18, 2010 00:42 |
|
Yes, you can pass an instance of any type to a function if the function accepts that type.
|
# ? Jun 18, 2010 01:19 |
|
RonniePudding posted:Is it possible to pass a list as an argument into a function? Or do I have to convert it to an array first? Why didn't you just write the code, run it, and see if it works?
|
# ? Jun 18, 2010 02:46 |
|
shrughes posted:Why didn't you just write the code, run it, and see if it works? Come on, don't expect too much; he can't even tell the difference between "C/C++" and "C#".
|
# ? Jun 18, 2010 02:49 |
|
Thanks for the help guys! Why post if you're just going to insult me? This thread is about helping isn't it? There is no Small questions for C# thread, and most competent programmers know two languages anyway so that's why I posted here. Also, I did try to run this in my program, but it's in Unity and depending on what class I inherit from depends on what features are added (string, list). It did not run, and does not make sense to me why it would not run seeing as how I can use an array just fine. Is that a better question, thread gods? RonniePudding fucked around with this message at 12:20 on Jun 18, 2010 |
# ? Jun 18, 2010 12:18 |
|
RonniePudding posted:There is no Small questions for C# thread http://forums.somethingawful.com/showthread.php?threadid=2262300
|
# ? Jun 18, 2010 12:48 |
|
RonniePudding posted:Thanks for the help guys! Why post if you're just going to insult me? This thread is about helping isn't it?
|
# ? Jun 18, 2010 13:45 |
|
I have the following code that does not work in the following way: If I enter a valid file name the first time, the file gets read in just fine. If I enter an invalid file name at first, and then a valid file name the second time, the code seems to enter the while (!readIn.eof()) { loop and never stop. I cannot figure out why this is happening. Is there something stupid I am missing or doing? code:
|
# ? Jun 18, 2010 14:13 |
|
Jose Cuervo posted:Is there something stupid I am missing or doing? Yes, you're using iostreams -- possibly the most poorly designed programming interfaces in the history of computing. (Real answer: predicate your loop on readIn.good() rather than !readIn.eof(). There are more problems possible with a stream than just EOF, and their incidence isn't consistent between implementations or defined properly in the C++ standard.)
|
# ? Jun 18, 2010 14:23 |
|
Call clear on your stream before the read loop.
|
# ? Jun 18, 2010 14:43 |
|
ctz posted:Yes, you're using iostreams -- possibly the most poorly designed programming interfaces in the history of computing. Thanks, that worked. Is there something else you suggest using instead of iostreams?
|
# ? Jun 18, 2010 14:44 |
|
Jose Cuervo posted:Thanks, that worked. Is there something else you suggest using instead of iostreams? use the C stdio stuff -- fopen(), fread(), fgets(), printf(), fprintf() (but not gets()).
|
# ? Jun 18, 2010 14:59 |
|
Those suck too.
|
# ? Jun 18, 2010 15:52 |
|
Does any language or framework have an I/O library that isn't at least 68% terrible? C-style I/O sucks, C++ iostreams suck, Java's I/O has sucked so many times that over time they've added about 10 different types of streams/readers/channels/descriptors that all suck (will NIO.2 finally get it right??)... Maybe I'm just forgetting an obvious good one because the lovely ones stick out so much.
|
# ? Jun 18, 2010 16:23 |
|
Plenty. Lua, python, and bash come to mind. Can't think of any for C/++ though.
|
# ? Jun 18, 2010 16:46 |
|
Perl! while (my $line = <STDIN>) { ... }
|
# ? Jun 18, 2010 17:28 |
|
Line-based IO with iostreams is not that bad,code:
|
# ? Jun 18, 2010 18:01 |
|
I am just now getting into the Boost library, is their File IO not very good either?
|
# ? Jun 18, 2010 19:18 |
|
Is there a way to emulate Haskell-like argument deconstruction in C++ without doing something bad like using dynamic_cast? I'm trying to translate (the process of evaluating expressions at least) http://okmij.org/ftp/Haskell/Lambda_calc.lhs into C++ in an OOPy manner and am having a hard time translating things likecode:
I'm probably square peg round holing this, and if so, what would somebody else do? Scrub code: http://codepad.org/MG59J4Yh Probably helpful too: http://codepad.org/iHltsgUI MagneticWombats fucked around with this message at 05:49 on Jun 19, 2010 |
# ? Jun 19, 2010 05:46 |
|
MagneticWombats posted:Is there a way to emulate Haskell-like argument deconstruction in C++ without doing something bad like using dynamic_cast? Yes. Or kind of. See http://forums.somethingawful.com/showthread.php?threadid=2773485&userid=0&perpage=40&pagenumber=170#post377240191 and rjmccall's reply on the same page. You might be able to do nested deconstruction with autoconversion hackery, see if that tr1::tie library mentioned in the link above can do it. It's probably just not worth bothering with nested deconstruction even if it's possible. Note that this just gives you deconstruction, it doesn't give you pattern matching. Ultimately you'll just have to implement visitors all over the place or just forget about C++ entirely. And don't follow some stupid rule that says you have to implement every visitor with a separate header file and cpp file. shrughes fucked around with this message at 05:55 on Jun 19, 2010 |
# ? Jun 19, 2010 05:53 |
|
shrughes posted:Yes. Or kind of. See http://forums.somethingawful.com/showthread.php?threadid=2773485&userid=0&perpage=40&pagenumber=170#post377240191 and rjmccall's reply on the same page. I'm going to interpret this as, "don't". But ultimately, I want to have the same class hierarchy and the same tree structure representing the lambda calculus expressions. The real problem, I think, is that I need to dispatch based not only on type but also on what the objects themselves point to. Of course I could just hack in an enum that says that this term is a Lambda and this term is an Apply EDIT: I think a more direct approach would be to create a data structure to keep track of scope and then do a second pass looking at the applies and then associate the bound variables parameters and then some magic. I'm thinking: code:
The problem for eta-reduction remains code:
EDIT2: Would it be bad form to just send a visitor that returns NULL if something isn't what you want it to be? For example, I have a CheckApplyVisitor that returns NULL if the thing visitor doesn't see an Apply. MagneticWombats fucked around with this message at 16:12 on Jun 19, 2010 |
# ? Jun 19, 2010 06:03 |
|
I'm working on a project where I need to basically hijack the sound card: read from the output buffer, apply a series of filters, then rewrite the altered output to the output buffer replacing the original input. Does anyone have any recommendations on what library to use to do this or know of any good tutorials. Right now I am looking at PortAudio because it has good cross-platform compatibility but the examples don't deal with pulling data off of the sound card for processing, they all rely upon portaudio generated input data. Also, it doesn't help that their wiki appears to be broken.
|
# ? Jun 20, 2010 20:29 |
|
MagneticWombats posted:Would it be bad form to just send a visitor that returns NULL if something isn't what you want it to be? For example, I have a CheckApplyVisitor that returns NULL if the thing visitor doesn't see an Apply. No (it would not be bad form). My personal preference would be to have it take an extra bool* or bool& parameter for the purpose, but hey.
|
# ? Jun 20, 2010 20:50 |
|
shrughes posted:No (it would not be bad form). My personal preference would be to have it take an extra bool* or bool& parameter for the purpose, but hey. Or that. EDIT: Even then, would the general method I'm trying to use be what you would use to tackle this problem in C++? MagneticWombats fucked around with this message at 06:57 on Jun 21, 2010 |
# ? Jun 20, 2010 21:25 |
|
Modern Pragmatist posted:I'm working on a project where I need to basically hijack the sound card: read from the output buffer, apply a series of filters, then rewrite the altered output to the output buffer replacing the original input. Does anyone have any recommendations on what library to use to do this or know of any good tutorials. I don't think there's any portable API that does what you're asking for, or that there's even an OS-level API to do that (on major OSes). If you really need to do exactly what you're describing in your post, you will probably have to add your own hooks to your OS's audio subsystem or your sound card's driver (you do have an open-source driver for your soundcard, right? ). On the other hand, there might be another way to do what you're trying to do that doesn't involve hacking custom APIs into your OS. If you would post more details about your setup (OS and soundcard) and the ultimate goal you're trying to achieve we could probably point you in the right direction.
|
# ? Jun 21, 2010 01:11 |
|
Mr.Radar posted:On the other hand, there might be another way to do what you're trying to do that doesn't involve hacking custom APIs into your OS. If you would post more details about your setup (OS and soundcard) and the ultimate goal you're trying to achieve we could probably point you in the right direction. On Linux, it might be doable user-level as some sort of an ALSA module (assuming apps use ALSA, but most can be configured to); but that might just be harder than messing with the sound driver.
|
# ? Jun 21, 2010 06:19 |
|
I'm tossing around designs for some scientific computing software. The application will need to manage millions of (small) nodes and I'm afraid memory constraints may be a real problem. Should I avoid creating class instances because of associated object overhead and just stick to arrays of structs and functions to manipulate those arrays?
|
# ? Jun 21, 2010 21:02 |
|
There's only going to be a difference in "object overhead" if your classes have virtual members. (Class instances can be stored in arrays, too)
Mustach fucked around with this message at 21:18 on Jun 21, 2010 |
# ? Jun 21, 2010 21:15 |
|
Mustach posted:There's only going to be a difference in "object overhead" if your classes have virtual members. Oooooh, gotcha. Thanks.
|
# ? Jun 21, 2010 21:18 |
|
polyfractal posted:I'm tossing around designs for some scientific computing software. The application will need to manage millions of (small) nodes and I'm afraid memory constraints may be a real problem. Should I avoid creating class instances because of associated object overhead and just stick to arrays of structs and functions to manipulate those arrays? What kind of "nodes" are we talking about here? Mustach is right in general, but when scientific packages refer to "non-object-based" implementation, it's not because they use structs instead of classes. It's because the data for each node isn't stored all together. Example: if "nodes" are vertices, each node might just be an arbitrary handle that ends up being transformed into an index into an array that stores coordinate data. This can let you do cool stuff like return consecutive ranges of nodes using much less memory (i.e. return "start = 1, end = 100" instead of "[1, 2, 3, ..., 100]"). EDIT: in practice, these implementations are almost always slower than object-based ones, but also use considerably less memory, assuming you get clever. Avenging Dentist fucked around with this message at 21:52 on Jun 21, 2010 |
# ? Jun 21, 2010 21:44 |
|
Avenging Dentist posted:What kind of "nodes" are we talking about here? Erm, neurons I'm working on a biological neural network model. Each node is a neuron and contains information such as coordinate position and connection details. Some of the data is stereotyped (ie. all neurons of type X have a resting potential of Z), while other data is unique to that neuron. The program will work in two phases: the first phase generates the spatial positioning and connectivity of the neuron nodes. The second phase uses this spatial information to generate a wiring diagram and use that for neural computation junk. My current design feels very naive and inefficient. It consists of a giant, gently caress-off array of neuron objects, spatially sorted by an Octree class. After the neurons are positioned, each neuron object gets an updated list of connection pointers. I'm really struggling to work out an efficient design for this. I'm a competent programmer, but have never dealt with programs that demand huge amounts of memory or really efficient performance. Any help or reading material would be appreciated (for reference I'm an ex-computer science major turned biologist, so I know my biology better than my CS unfortunately). Edit: I looked at structures like directed graphs, but don't feel they provide any benefit since I will never need to do stuff like sorting, shortest path or network flow. Really the only information I need to keep track of are 1) where is the node spatially 2) who does it connect to and 3) what are its internal properties. Is having a bigass list really the best way to accomplish this? polyfractal fucked around with this message at 22:09 on Jun 21, 2010 |
# ? Jun 21, 2010 22:02 |
|
polyfractal posted:It consists of a giant, gently caress-off array of neuron objects, This is fine if you don't need to add/remove neurons after the initial setup. polyfractal posted:spatially sorted by an Octree class. There might be a better spatial partitioning, but if you're just dealing with point objects, octrees are probably pretty ok.
|
# ? Jun 21, 2010 22:10 |
|
|
# ? Jun 9, 2024 02:04 |
|
I have what I think is a pretty stupid question. In my continuing effort to port a program from MSVC to GCC, I've come up against this type of error a number of times with this sort of code: code:
code:
|
# ? Jun 22, 2010 09:33 |