Boost, what do you use it for?
I keep coming back to the boost libraries, as i feel i should be using it as so many people recommend it. But i can never see anything that i really need, just really simple things like "noncopyable", which i can easily implement myself without having to add dependancies to my application
As application/Game/Graphics programmers, what do you use it for?
Off the top of my head: shared_ptr, bind, function, lambda, unordered containers, random, cstdint.hpp, mpl, type traits.
TR1 in VS2008 takes care of most of my needs from boost, but very helpful are lexical_cast<>, the whole boost threading library (until we get the C++0x implementation), and Any :)
[edit] oh yay... there's a cstdint.hpp?
[edit] oh yay... there's a cstdint.hpp?
I use, in addition to what SiCrane uses: filesystem, interprocess, asio, string_algorithms, range, foreach.
[size=1]Visit my website, rawrrawr.com
Regular expressions. Played with spirit a bit, gave up because of horrible compile times for projects of any complexity.
In addition to the above:
- regex
- thread (the less Win32 API I have to touch directly, the happier I am)
- lexical_cast (replaces atoi and itoa among others)
- case-insensitive string algorithms
If you can't see a use for Boost, you're either doing too much yourself, not doing anything remotely complicated, or using a better language than C++.
- regex
- thread (the less Win32 API I have to touch directly, the happier I am)
- lexical_cast (replaces atoi and itoa among others)
- case-insensitive string algorithms
If you can't see a use for Boost, you're either doing too much yourself, not doing anything remotely complicated, or using a better language than C++.
At work I use :
thread - for the cross platform threading api
serialization - loading/saving of objects to binary, text, xml streams for persistance or sending over network
date_time - date arithmetic, stringising
bind - binding member functions
asio - I use this mainly for the networking api
shared_ptr - need I say more?
lambda - small unnamed callback functions
lexical_cast - converting between strings and various types
program_options - options from command line / ini files / environment variables, and it was easy to extend to xml files and values from the windows registry by writing some simple iterators.
I have used graph too for a project at home.
If I'm feeling a bit dirty it can be fun to play with preprocessor [grin]
I have used graph too for a project at home.
If I'm feeling a bit dirty it can be fun to play with preprocessor [grin]
Haven't used C++ in a little while, but bind and function from std::tr1 is what I used a lot for callbacks.
Most of this has already been mentioned, but off the top of my head: lexical_cast, bind, function, lambda, any, variant, format, string algorithms, filesystem, type traits, enable_if, preprocessor, cstdint, noncopyable, shared/weak/scoped_ptr, pool, assign, tokenizer, array, multi_array, dynamic_bitset.
(Some of the above is of course now available as part of tr1 for some compilers.)
(Some of the above is of course now available as part of tr1 for some compilers.)
I was first introduced to boost as part of my University course, boost function was used fairly extensively in the Library the tutor had written as a basis for one of my modules.
But the reasons I first used it in any personal projects was for shared_ptr. Since then I've adopted a few other random bits and pieces into my project:
- function
- bind (pretty much solely as member function bind with boost::function, although has been useful for custom deleters with shared_ptr)
- noncopyable (you're right, I could write it myself, but it was already there)
- date_time
- string_algorithms
- filesystem
- variant
- unordered containers
- intrusive containers
Future plans:
- thread
- pool
As for examples of use.
variant: GLSL shader parameter values. I don't know how well you know openGL or GLSL but you can pass several different types of object into a shader. I decided to treat all of these the same, and store the data in a variant. The visitor pattern works perfectly for this, and the only other solution I could think of was inheritance. So this was a case where I just decided to experiment.
shared_ptr: Personally I use it for pretty much every pointer. But you might not like that. Something you might like though is automatic graphics resource management.
I have a central repository of resources (textures, shaders, meshes etc.) in my game. When a resource is allocated a shared_ptr is created with a custom delete function, a weak_ptr is stored in the repository and the shared_ptr is returned to the game. When that shared_ptr is no longer referenced it will call the custom delete function I provided which will remove it from the repository and free the resource. The reason for storing the weak_ptr in the repository is so that if the game tries to load the same resource more than once, I can get the shared_ptr from the weak_ptr and return that instead of loading the resource again and creating a new shared_ptr.
Having said all of that. If you really don't think you need boost. Then don't use it. But technically no one really needs anything in boost, it just make our lives a hell of a lot easier [grin]
But the reasons I first used it in any personal projects was for shared_ptr. Since then I've adopted a few other random bits and pieces into my project:
- function
- bind (pretty much solely as member function bind with boost::function, although has been useful for custom deleters with shared_ptr)
- noncopyable (you're right, I could write it myself, but it was already there)
- date_time
- string_algorithms
- filesystem
- variant
- unordered containers
- intrusive containers
Future plans:
- thread
- pool
As for examples of use.
variant: GLSL shader parameter values. I don't know how well you know openGL or GLSL but you can pass several different types of object into a shader. I decided to treat all of these the same, and store the data in a variant. The visitor pattern works perfectly for this, and the only other solution I could think of was inheritance. So this was a case where I just decided to experiment.
shared_ptr: Personally I use it for pretty much every pointer. But you might not like that. Something you might like though is automatic graphics resource management.
I have a central repository of resources (textures, shaders, meshes etc.) in my game. When a resource is allocated a shared_ptr is created with a custom delete function, a weak_ptr is stored in the repository and the shared_ptr is returned to the game. When that shared_ptr is no longer referenced it will call the custom delete function I provided which will remove it from the repository and free the resource. The reason for storing the weak_ptr in the repository is so that if the game tries to load the same resource more than once, I can get the shared_ptr from the weak_ptr and return that instead of loading the resource again and creating a new shared_ptr.
Having said all of that. If you really don't think you need boost. Then don't use it. But technically no one really needs anything in boost, it just make our lives a hell of a lot easier [grin]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement