Sign in to follow this  
paulecoyote

[C++] Do you use Boost?

Recommended Posts

I've been looking at Boost library, particularly the implementation of multidimensional arrays: http://www.boost.org/libs/multi_array/doc/user.html I was contemplating using a nested vector, but this quote caught my eye:
Quote:
Boost MultiArray is a more efficient and convenient way to express N-dimensional arrays than existing alternatives (especially the std::vector<std::vector<...>> formulation of N-dimensional arrays).
... being better then the stl is quite a bold claim. But the examples seem compelling. The licence seems pretty unrestrictive too. I'm looking for developers comments whom have actually used the library and if they like it or not, or had any problems. Thanks, Paul

Share this post


Link to post
Share on other sites
I've not used MultiArray but boost is useful. I've found boost::smart_ptr, function, bind, thread and signals very helpful.

Most C++ programmers know the library and its classes are almost a standard way to do things, in a similar way to the STL. If you're going to write something from scratch its best to check boost for something that fits your needs first.

Share this post


Link to post
Share on other sites
The Boost libraries are widely used and quite well regarded. A fair number of the Boost libraries are currently under review for being added as part of the official C++ standard, so they'd actually become part of the STL. Their multi-dimentional array would be more efficient than the vector of vectors solution, because a vector of vectors has an extra pointer to dereference, while a true multidimentional array would not.

Personally, I have yet to use one of the Boost libraries, but I don't expect that to last long. I'm familiar with the libraries they offer, and when I encounter a problem where I feel one of their libraries would be of benefit, I'll use it, unless I have some reason for wanting to implement it myself.

Share this post


Link to post
Share on other sites
I haven't used multiarray, but I use other boost libraries all the time. Many boost libraries should be a part of C++ standard and some possibly will be in the future. The STL is quite limited in many ways and boost patches up many of the holes in it.

As an added bonus, many boost libraries are header only, so you don't even have to worry about linking to the library, which can be useful if you're working on a multiplatform project.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord Maz
Still haven't got boost to install correctly, but I would use it if I could.


Use bjam -sTOOLS=mingw [libname] on MinGW. There are different settings depending on your compiler and platform

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord Maz
Still haven't got boost to install correctly, but I would use it if I could.


The installation does seem to have many steps - I've downloaded it and will use it if there is a bigger need. The exe extractor didn't work for me so I've downloaded the zip.

For the moment the yucky embedded vector solution is alright... if it annoys me further I'll use boost.

Share this post


Link to post
Share on other sites
I recommend/use boost::spirit, boost::thread, boost::lambda, phoenix, boost::lexical_cast, boost::shared_ptr (occasionally), boost::filesystem and boost::datetime. All of them are excellent libraries. There aren't a great deal of [good] portable c++ threading libraries around, you know.

Share this post


Link to post
Share on other sites
I am using mingw (the version that comes with dev-c++) but calling bjam and including the root path gives me a couple of hundred errors. It nags alot about VC++ mumbo-jumbo - maybe because I'm also using the VC++ compiler?

Share this post


Link to post
Share on other sites
Quote:
Original post by MrEvil
I recommend/use boost::spirit, boost::thread, boost::lambda, phoenix, boost::lexical_cast, boost::shared_ptr (occasionally), boost::filesystem and boost::datetime.


hmmm you left you out boost::mpl & boost preprocessor [grin].

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord Maz
Still haven't got boost to install correctly, but I would use it if I could.

I had trouble setting boost up myself, but here is a link where Fruny explains how to do it step by step. Linky

I just recently started using boost myself, I've really only used a few of its smart ptrs and the dynamic bitset so far, but I'm already convinced that its definately worth learning.

hth.
moe.ron

Share this post


Link to post
Share on other sites
Mm, I've done those things but I guess my path is screwed up or something because it doesn't work for the reasons i explained above. Anyhow, it seems that I can use quite a lot of boost juice without doing any compiling; when I got the include paths right it worked for arrays, shared pointers and some other stuff I tried. Very nice tools.

Share this post


Link to post
Share on other sites
Yea you can use a lot of the functionality without building it. I think just filesystem, parsing, and a few others actually need to build. I just built mine yesterday but I've been using it for about two months

Share this post


Link to post
Share on other sites
I'd probably use some of it if I could get it installed. On windows, bjam failed to install. On BSD, the OS provided package failed to compile even the most basic example code with some manner of templating error.

I just took it as a sign, and will try again later, when I'm feeling an abundance of patience.

Share this post


Link to post
Share on other sites
Quote:
Original post by Lord Maz
Still haven't got boost to install correctly, but I would use it if I could.
Quote:
Original post by Lord Maz
I am using mingw (the version that comes with dev-c++) but calling bjam and including the root path gives me a couple of hundred errors. It nags alot about VC++ mumbo-jumbo - maybe because I'm also using the VC++ compiler?


I had the same problem (without VC++ installed even), and ignored boost for a while. Later (a few months ago) when I really wanted some of the stuff in there, I googled around for a few hours and found an obscure post on one of the boost mailing lists by someone with the same problem (I think posted in 2004, not sure).
They never actually found out what the problem was, but it turned out that compiling it from MSYS (available from the MinGW site if you haven't installed it yet, it's optional) was a workaround. Works for me, but I'm not really happy about all the time it cost me to find out about it [headshake]. Hope this helps.

Share this post


Link to post
Share on other sites
I've used some things in boost.. such as regex, graph, smart_ptr, and serialization. Most of their libraries are straightforward and easy to use.

However, there are some that are just absolute abuses of C++ and templates in particular (IMHO).. And others can be notoriously complex, like the boost:graph library, for which there is actually a 300+ page book + CD-ROM on how to use it.

Properly used, I don't have anything against boost. However, as with any libraries/classes, use it wisely. I was recently on a development team who would use boost objects for everything they could. One component they wrote was a dataset class which functioned like a virtual table. During system tests they found that to populate the dataset with 100 fields and 50000 rows would take 40 seconds, and sucked up 50MB of RAM so they called me to take a look at it. Boost EVERYWHERE. As a proof of concept, I re-wrote the class in 4 hours to use simple stl lists/vectors and other basic classes, while maintaining the same functionality and interface. The difference? The test ran in under a second and used less than 5MB of memory.

I realize this is an extreme case, but after seeing how some people abuse 3rd-party libraries claiming it will "solve all their problems" really makes me consider them a last resort.

This is just my opinion.. using good quality 3rd-party libraries rather than reinventing the wheel is generally a good thing. Just be sure to use them wisely.

Share this post


Link to post
Share on other sites
- Boost.Bind is so much better than std::bind(1st|2nd) that I'd consider it a requirement for anyone trying to use STL-style programming.
- Boost.Shared_Ptr is often the easiest, decently-performing way to deal with heap memory.
- Boost.Filesystem is possibly the best way to use files, since there's no portable way to do many things it does. Same with Boost.Date_Time.
- Boost.Function ( with Boost.Bind or Boost.Lambda ) makes callbacks so much easier to use.
- Boost.Conversion is an extremely convenient wrapper for simple string->data or data->string conversion. Boost.Format can also be used for more precise formatting of data->string without needing explicit streams or manipulators.

In Short: Use it.

Fury does have a point though. Use it when it's helpful, not 'cause it's "cool".

Share this post


Link to post
Share on other sites
OK well so far we have lots of posts from people who use boost.
Here's one from someone who doesn't use boost...

For starting new things I might consider using it, although I'd have a lot of learning ahead of me. However most of my work involves maintaining existing systems, which I certainly wont be adding boost to, as I couldn't possibly justify it.

I'm interested in learning how some of it works. I'm one who likes to fairly well understand how something works before I make thorough use of it.

I'm sure that it's multidimensional array is great, though I'm also very capable of writing my own too, or using other existing tools.

Share this post


Link to post
Share on other sites
Just want to mention that Boost is no ordinary 3rd-party library members of boost have either close ties with or are part of the C++ standards committee. 10 Boost libraries are already being reviewed in the library technical report (TR1) some compilers already implement most or all of std::tr1.

Anyways the point of Boost is to compensate for flaws in the current C++ standard and useful cross-platform componenets that are not in the C++ standard library.

For example the standard library binders are broken and i don't mean implementation wise i mean in the standard they are broken. boost::bind is replacement that goes well beyond the capabilities of the standard library binders.

[Edited by - snk_kid on June 23, 2005 3:54:16 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by iMalc
I'm sure that it's multidimensional array is great, though I'm also very capable of writing my own too, or using other existing tools.


Just try it ;) I have several pieces of such an implementation lying around and well, I've learned a fair bit but haven't found the motivation yet to pull it all together.

Quote:
... being better then the stl is quite a bold claim.


Boost::multi_array isn't claiming to be "better than the STL"; it's claiming to be better for a particular purpose than a particular common STL-using implementation (nested std::vectors). In particular, when you nest std::vectors like that to build what is supposed to be a rectangular array, you end up writing the code yourself to make sure it stays rectangular - and you have a std::vector object's overhead "per row" (and it's even worse in 3+ dimensional cases) which is useless (specifically because you *do* want it to stay rectangular). A smart implementation holds a single block of memory that gets resized as needed, and does arithmetic in order to translate a set of array indices into a single index.

For example, my implementation uses a single std::vector underneath the hood for storage, and creates objects representing "x-dimensional views" (for x in 1..N) of the storage; operator[] returns an (x-1)-dimensional view object, except in the x=1 case which is specialised to return the element type. Or at least, that's how I intend it to work if I ever finish it :)

Share this post


Link to post
Share on other sites
GameDev.net is a game deveoper site, right?
So, the question should perhaps be:
"Do you use boost in your published games or game engines?".
The answer to that is probably NO!
The same goes, to a lesser extent, to STL.

// Riddick B Riddick

Share this post


Link to post
Share on other sites
Quote:
Original post by Bucko
"Do you use boost in your published games or game engines?".
The answer to that is probably NO!
The same goes, to a lesser extent, to STL.


I hope that wasn't your answer to the question or was that meant to reflect what you think most people would say?

Also there is no such thing as STL only standard library.

Honestly that is just being ignorant, use both where ever its appropriate and use it effectively, the last thing we need is more custom mediocre versions of std::list or boost::function/std::tr1::function etc. I would love to see how far you would get trying to write your own version of boost::mpl.

i've used the standard library and boost in my own works, at the appropriate places and used it effectively had no issues, it was efficient, it saved me from wasting time on unnecessary things, it made my code clear & concise. Would i use it again? yes.

Share this post


Link to post
Share on other sites
Quote:
Original post by Urxae
Quote:
Original post by Lord Maz
Still haven't got boost to install correctly, but I would use it if I could.
Quote:
Original post by Lord Maz
I am using mingw (the version that comes with dev-c++) but calling bjam and including the root path gives me a couple of hundred errors. It nags alot about VC++ mumbo-jumbo - maybe because I'm also using the VC++ compiler?


I had the same problem (without VC++ installed even), and ignored boost for a while. Later (a few months ago) when I really wanted some of the stuff in there, I googled around for a few hours and found an obscure post on one of the boost mailing lists by someone with the same problem (I think posted in 2004, not sure).
They never actually found out what the problem was, but it turned out that compiling it from MSYS (available from the MinGW site if you haven't installed it yet, it's optional) was a workaround. Works for me, but I'm not really happy about all the time it cost me to find out about it [headshake]. Hope this helps.


Thanks, I tried it now but it wasn't any different. Not sure if I used it correctly, however...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this