|
Avenging Dentist posted:Yes, the Boost documentation. Where else would it be? Who knows, perhaps in the vault, perhaps the documentation is only in svn, or on the library's non-boost page or something. Edit: goddamnit I was planning on sleeping tonight Vanadium fucked around with this message at 03:32 on Feb 8, 2009 |
# ? Feb 8, 2009 03:27 |
|
|
# ? Apr 24, 2024 10:50 |
|
Vanadium posted:Who knows, perhaps in the vault, perhaps the documentation is only in svn, or on the library's non-boost page or something. Only if what you are looking for isn't yet a part of an official boost release.
|
# ? Feb 8, 2009 03:29 |
|
I probably should have explained a little bit better. (I'm using C, so I don't think I can use boost) Say I have the number 01011001 10100011 and I want to get the value for the range in bold (the value 6).
|
# ? Feb 8, 2009 03:30 |
|
Super Dude posted:I probably should have explained a little bit better. (I'm using C, so I don't think I can use boost) You need to shift it right by 10 bits, and then mask off the part you want: code:
|
# ? Feb 8, 2009 03:33 |
|
Vanadium posted:Edit: goddamnit I was planning on sleeping tonight Hey, eat my butt! Let's see you do it a better way
|
# ? Feb 8, 2009 03:39 |
|
That Turkey Story posted:Hey, eat my butt! Boom: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2378.pdf
|
# ? Feb 8, 2009 03:40 |
|
Avenging Dentist posted:Boom: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2378.pdf Let us now travel into the future!
|
# ? Feb 8, 2009 03:42 |
|
I'm imagining a listing of useful, common things for people like myself who aren't very familiar with them. I'm not finding anything on Google though. I guess you just have to browse the libraries and read all their descriptions.
|
# ? Feb 8, 2009 03:43 |
|
oldkike posted:You need to shift it right by 10 bits, and then mask off the part you want: Ohhh I get it now. Thanks!
|
# ? Feb 8, 2009 03:44 |
|
Super Dude posted:Ohhh I get it now. Thanks! Also be careful with using shifts and bitwise operators in the same statement without parentheses. Bitwise operators have higher precedence than shifts, so your original code x >> 10 & 0xD is actually equivalent to x >> (10 & 0xD), and I don't think that's what you meant to write.
|
# ? Feb 8, 2009 05:36 |
|
Smackbilly posted:Also be careful with using shifts and bitwise operators in the same statement without parentheses. Bitwise operators have higher precedence than shifts, so your original code x >> 10 & 0xD is actually equivalent to x >> (10 & 0xD), and I don't think that's what you meant to write. No it isn't. The parenthesis are not necessary, though you probably should write them anyway for clarity.
|
# ? Feb 8, 2009 05:48 |
|
What is the proper way to enforce type safety via argument with polymorphic classes? For example what if in the following code I wanted to make a derivative of my container class that would only take B* as the argument to add(), rather than ACont which takes A*.code:
code:
Thug Bonnet fucked around with this message at 05:22 on Feb 9, 2009 |
# ? Feb 9, 2009 05:18 |
|
The proper way is to avoid doing that at all. There's no way you're going to get compile-time type safety for BCont, since imagine what would happen if you were using it via a Cont pointer. The compiler wouldn't be able to tell that it should be using the types associated with BCont. One solution (used by the STL, obviously) is to take advantage of compile-time polymorphism with the use of templates. Depending on your requirements, you may also choose to remove Cont::add[fixed] and have [fixed]add only appear in the subclasses, thus requiring you to use a (A|B)Cont if you want to insert objects. More about this here: http://www.parashift.com/c++-faq-lite/proper-inheritance.html#faq-21.3
|
# ? Feb 9, 2009 06:06 |
|
Dang, I was just combing through c++-faq-lite. I had a feeling it had the answer, I just couldn't find it. I'd really like to avoid templates for this for a number of reasons. I guess I need to re-think it. I'm glad to know I wasn't just missing something, though Avenging Dentist posted:Depending on your requirements, you may also choose to remove Cont::add and have add only appear in the subclasses, thus requiring you to use a (A|B)Cont if you want to insert objects. But this would mean I can't guarantee you can add() in some instances (for example passing the interface pointer). Thug Bonnet fucked around with this message at 06:24 on Feb 9, 2009 |
# ? Feb 9, 2009 06:22 |
|
Thug Bonnet posted:But this would mean I can't guarantee you can add() in some instances (for example passing the interface pointer). You simply can't safely add anything given an interface pointer. You're only allowed to add something that's the same class, but given only the interface you don't know what class that is, so there's no way you can add anything. This is the same reason a vector of Cars isn't a vector of Vehicles.
|
# ? Feb 9, 2009 06:30 |
|
ShoulderDaemon posted:You simply can't safely add anything given an interface pointer. You're only allowed to add something that's the same class, but given only the interface you don't know what class that is, so there's no way you can add anything. This is the same reason a vector of Cars isn't a vector of Vehicles. Ah, a lightbulb just went on. This makes things marginally more complicated then
|
# ? Feb 9, 2009 06:40 |
|
A really, really hacky option would be to ensure that you have the correct type by using a dynamic_cast, but I really don't recommend that. (Also it obviously only works at runtime).
|
# ? Feb 9, 2009 09:48 |
|
Avenging Dentist posted:A really, really hacky option would be to ensure that you have the correct type by using a dynamic_cast, but I really don't recommend that. (Also it obviously only works at runtime). Well i mean its not THAT hacky, and in fact has been recommended to me. But it just feels.. dirty. And doesn't really help all that much because what, you just silently ignore bad input? Not a wonderful solution.
|
# ? Feb 9, 2009 10:42 |
|
Thug Bonnet posted:Well i mean its not THAT hacky, and in fact has been recommended to me. But it just feels.. dirty. And doesn't really help all that much because what, you just silently ignore bad input? Not a wonderful solution. You'd throw an exception or assert or something.
|
# ? Feb 9, 2009 11:56 |
|
Here's what I would like to do. I want to implement a small scripting language in my C++ programs. What I'd like to know is what would be the best way to implement this. Why? I'd like to be able to plug custom functionality into some of my programs at runtime. Right now I'd like to use it in a small graphical program so that I can rapidly play with / write new AI for some agents or something. In the future I'd like to use it for scripted behaviors / events on a networked game server. Things I've considered:
So what I'd like to be able to do in my code is this: code:
code:
Wish List:
I'm sure there are libraries that do a good chunk of this sort of thing. I just don't know what they are or which ones are the most useful etc. Can you guys point me in the right direction? Or are my requirements too absurd and I should just try to make my own language (and fail miserably)?
|
# ? Feb 10, 2009 02:48 |
|
Use Boost.Python? Lua/Luabind? Lua is pretty drat lightweight and runs well on embedded systems. Python is a little more heavyweight but has better libraries (not really an issue for application extensibility, though). Lua is used in lots of games, too: Dawn of War, Sam and Max, both STALKER games, etc. Also, I'm one of the Luabind developers. Avenging Dentist fucked around with this message at 02:54 on Feb 10, 2009 |
# ? Feb 10, 2009 02:50 |
|
Lua is probably the most commonly used embedded languags for this sort of thing. If you really want a scheme, you can use guile, the embedded scheme interpreter.
|
# ? Feb 10, 2009 03:07 |
|
Luabind looks fantastic. Thank you so much.ShoulderDaemon posted:If you really want a scheme, you can use guile, the embedded scheme interpreter. I'll check this out also.
|
# ? Feb 10, 2009 03:17 |
|
Contero posted:Luabind looks fantastic. Thank you so much. Just roll your own Scheme interpreter; the language is trivial.
|
# ? Feb 10, 2009 03:43 |
|
(that is if you leave out little implementation details like call/cc)
|
# ? Feb 10, 2009 06:34 |
|
Hi; I'm having trouble making lists of a templated class: I'm working in Visual Studio 2008, C++ code:
The error is only generated if I try to use the list (such as the resize), which makes sense and all. Actual intended use questions: Will I have further problems if the class I'm templating on, is itself a templated class? Will I have further problems if either of those classes are themselves, or inheriting from, "curiously recurring template pattern" classes? (CRTP = class b : public t<b> ) Thanks! EDIT: CRTP was wrong. narfanator fucked around with this message at 05:17 on Feb 11, 2009 |
# ? Feb 10, 2009 07:31 |
|
tef posted:(that is if you leave out little implementation details like call/cc) call/cc is really easy if you (1) understand Landin's paper (which is extraordinarily transparent) and (2) write your interpreter in CPS. The alternatives might be pretty obnoxious.
|
# ? Feb 10, 2009 08:10 |
|
narfanator posted:Hi; I'm having trouble making lists of a templated class Your copy ctor needs to take a const reference. Also, you don't need to explicitly specify the template class inside of the class template (i.e. bar works where you have bar<T>).
|
# ? Feb 10, 2009 08:51 |
|
#$*#% const. Thanks.
|
# ? Feb 10, 2009 10:03 |
|
Contero posted:I'm sure there are libraries that do a good chunk of this sort of thing. I just don't know what they are or which ones are the most useful etc. Can you guys point me in the right direction? Or are my requirements too absurd and I should just try to make my own language (and fail miserably)?
|
# ? Feb 10, 2009 13:53 |
|
TSDK posted:Scripting languages also worth considering: The problem is the support. It's got a tiny userbase, and a definite lack of tutorials and I'm sure it's this which is hampering its wider adoption.
|
# ? Feb 10, 2009 15:12 |
|
Quick and stupid question: I'm writing a smart container that owns the pointers I push to it, and I want to ensure that the objects these point to are unchanged for their lifetime. Can I do this as: code:
|
# ? Feb 10, 2009 21:00 |
|
PStore should be a vector of const MyObject*s, push_back() needs a return type, I'm guessing that you just made a whole bunch of typos and meant to type something like this: code:
Mustach fucked around with this message at 21:23 on Feb 10, 2009 |
# ? Feb 10, 2009 21:14 |
|
DoctorTristan posted:Is there any problem in insisting that push_back() takes a pointer to a const MyObject, and have I managed to avoid screwing up my iterators in the destructor definition? A pointer-to-const-object only guarantees (well, "guarantees") that the object can't be changed through that pointer and no more; to actually guarantee that no-one can change the object at all, you'd have to guarantee that nothing out there has a pointer-to-non-const-object to it, which is not possible to prove via the type system. Also, a quick mechanical point: you take in the pointer-to-const and immediately try to put it in a collection of pointer-to-non-const, which is a violation; you need that to be std::vector<const MyObject*>. Your iterators are totally screwed up. If you're trying to iterate through the vector backwards, (1) you need special iterators for that (rbegin and rend), and (2) you need to actually update the iterator at some point, like so: code:
|
# ? Feb 10, 2009 21:23 |
|
Mustach posted:PStore should be a vector of const MyObject*s, push_back() needs a return type, that while-loop is infite if storage contains at least one element, and (related to the previous) I don't know what you're trying to do with i = 0, but it's not the right thing. I swear that some of those mistakes only crept in when I wrote up that post... I wasn't quite sure abot the i=0 thing myself actually, I actually stole it from a generic purging template function from Eckel vol. 2, I assumed it was some kind of safety feature that I didn't quite get. What he wrote was: code:
|
# ? Feb 10, 2009 21:24 |
|
Okay, that makes sense, because *i = 0 assigns to the element, but i = 0 assigns to the iterator. Although you don't need to reassign the elements in the destructor, since the the vector's going to be destroyed right after. Check out my edit and rjmccall's post for more corrections and info.
|
# ? Feb 10, 2009 21:32 |
|
Great, thanks guys. Some of those stupid errors were typos, but a lot were just me being plain dumb.
|
# ? Feb 10, 2009 21:36 |
|
narfanator posted:Will I have further problems if either of those classes are themselves, or inheriting from, "curiously recurring template pattern" classes? That is not CRTP. CRTP is class b : some_template< b > {};
|
# ? Feb 10, 2009 21:59 |
|
rjmccall posted:Your iterators are totally screwed up. If you're trying to iterate through the vector backwards, (1) you need special iterators for that (rbegin and rend), That's not true. rbegin and rend are meant to be used with the generic STL algorithms when you need to do something in reverse. If you're making the loop yourself, you can (and many times should) use regular iterators: http://codepad.org/jKL4tmqk . Reverse iterators don't always have very good support in the STL. Off the top of my head, I know that you can't use a reverse iterator to erase parts of a string, but a regular iterator works just fine.
|
# ? Feb 10, 2009 22:09 |
|
|
# ? Apr 24, 2024 10:50 |
|
Okay. I wasn't sure if decrementing end was actually specified behavior; obviously it works given a simple implementation.
|
# ? Feb 10, 2009 23:05 |