View Full Version : Favorite libraries, or parts of libraries? (Boost? Loki? etc)
eddie
11-07-2005, 02:45 PM
Hey!
I just read a post where monjardin mentioned boost::noncopyable, which I'd never heard of (the boost library is *huge*).
I was curious. Would anyone be interested in contributing to a thread talking about the various parts of libraries like boost they like/learn from?
The reason I mention this is because a lot of these libraries are so expansive that it's hard to get a firm grasp on it (I'd love to know more about the boost MPL and good examples of the Boost.PreProcessor stuff, as well as plenty more), particularly without examples.
Anyone interested in putting in their experiences?
Dia Kharrat
11-07-2005, 04:30 PM
Here's another good library (and quite comprehensive) as well that is worth checking out:
http://www.rawmaterialsoftware.com/juce/
haven't used it myself, but from the looks of it, it seems nicely designed.
monjardin
11-08-2005, 09:00 AM
I've been learning parts of boost recently and I'm finding shared_ptr, bind and function extremely useful.
boost::shared_ptr is a reference counted smart pointer. What I like about it is the custom clean-up function. For example, I manage SDL_Surface structures with them:
typedef boost::shared_ptr<SDL_Surface> surface_ptr;
...
surface_ptr p( IMG_Load_RW(rw, 1), SDL_FreeSurface );
Now when the pointer goes out of scope the SDL_FreeSurface function is called to release the SDL_Surface*. This saves me time writing little resource managing classes to perform similar duties.
boost::function is great for generic callbacks. Sticking with the SDL theme, I set up an event manager that keeps lists of function objects to call registered event handlers (e.g. key presses, mouse clicks, render, etc). Combined with boost::bind, it doesn't matter if they are global functions or class methods.
Bind is great for performing batch operations with STL containers. For example, you could update your entities with a time delta like this:
// dt is your time difference
// Entity is some class
// entities is a std::vector<Entity>
std::for_each( entities.begin(), entities.end(),
boost::bind( &Entity::update, _1, dt ) );
That is the same as this:
for( std::vector<Entity>::iterator it = entities.begin();
it != entities.end(); ++it )
{
it->update( dt );
}
monjardin
11-08-2005, 09:05 AM
Some words of warning: The compiler warnings associated with a lot of the boost library (especially MPL) are extremely esoteric. Expect to troubleshoot a few internal compiler errors as well.
dave_
11-08-2005, 01:24 PM
Some words of warning: The compiler warnings associated with a lot of the boost library (especially MPL) are extremely esoteric. Expect to troubleshoot a few internal compiler errors as well.
I have to admit that I've not had too many problems, but GCC is worse for cryptic clues of error messages than m$vc. :wallbash:
The worst problems you get is when you're dealing with overload-heavy template code. Rather than tell you what the error is, the compiler just tells you that something doesnt fit an overload. :sleeping:
dave_
11-08-2005, 01:30 PM
// dt is your time difference
// Entity is some class
// entities is a std::vector<Entity>
std::for_each( entities.begin(), entities.end(),
boost::bind( &Entity::update, _1, dt ) );
That is the same as this:
for( std::vector<Entity>::iterator it = entities.begin();
it != entities.end(); ++it )
{
it->update( dt );
}
Thats a good example of a use for bind.
I've changed bind in my own ways to use for many applications from reflection to signals and slots.
But avoid iterator adapters. They add unnessecary complexity and bloat code.
eddie
11-08-2005, 01:45 PM
Has anyone played with stlfilt? I hear that makes working with templates a lot nicer.
vBulletin, Copyright ©2000-2010, Jelsoft Enterprises Ltd.