Archive
All About Boost
Given the hint I dropped yesterday about game data files, you may be wondering what lead to the change in subject of today’s post. Well I’ll first reassure you that data files will come up in a day or to. I shan’t tell you what serialization library we’ll be using just yet, but given the title of the present post, I’m sure you can make an informed guess
Regardless, we’ll be using the Boost libraries a fair bit anyway, so I thought I should take a second to make sure you know exactly what they are. I did post about them once before, but it was really just a brief mention. But Boost offers us so much extra – and often highly desirable – functionality that I felt it deserved a slightly longer introduction.
So, I’m sure by now you’ve worked out that by “Boost”, I refer to the Boost C++ Libraries. These 80 or so libraries, united under the Boost “flag”, are open source and peer reviewed. They are generally licensed under the Boost Software Licence, which allows for both commercial and non commercial use, in open source and closed source projects. Moreover, several prominent Boost authors are on the C++ standards committee and indeed many features of the Boost libraries have made it into the C++11 standard. While smart pointers may be new to standard C++, they’ve been in Boost for years. The same is true of lambda functions, threads, and more. (Of course, you should choose the standard C++ versions over the Boost versions now whenever possible.)
You probably want to know a few things you can do with Boost… Well, I’ll not say much for now. But here are a few of my favourite libraries
- Boost Program Options – read program options from the command line and from config files
- Boost Filesystem – manipulate files and directories
- Boost Lexical Cast – safely and seamlessly convert the integer 5 to the string literal “5″ and back again
If you want to see a complete list of Boost libraries, just visit the Boost libraries page. Many are entirely header based, meaning you don’t have to compile any binaries. A few, however, involve source code as well so you’ll need to compile them into static or dynamic libraries. And to the “compile shy” ones among you, don’t think you can’t just skip it. Some of the most useful Boost libraries of all require compilation, and you’ll need them eventually. But don’t worry. It’s really not that hard, and over the next few days I’ll show both Windows and Unix users how.
Oh, and one other thing. I’m thinking of having a “Boost Week” in a bit. I’ll tell you about a library a day. I already have a few favourites I want to share with you, but if you want to know about any particular Boost library component, then just let me know in the comments!
GoingNative 2012: Minus 1 Day « Sutter’s Mill
You’ve probably already heard, but there’s a big upcoming C++ conference from everyone’s favourite friendly software giant, Microsoft. Actual seats are, of course, all booked up. But you can watch online. If you can spare the time, watch as many as you can. It’s a great opportunity to learn the language from the big names of the industry, including Bjarne Stroustrup himself! And they’ll be available on demand, as well as live, so there’s no excuse to miss them. Have fun!
Singletons
Here’s another little something to keep you entertained while you’re waiting for things to get underway here again (it’ll happen eventually, I promise!).
SFML Coder’s C++ Primer
Hi again! Firstly I want to confirm that I probably won’t be writing many more SFML tutorials until a stable SFML 2.0 is released. Unless – of course – a stable release is still a very long way off!
Anyway, I feel I should provide something in the mean time so I’ve decided to pick up my C++ tutorial series again. As some of you may know, I have already put one or two videos on YouTube on this topic and the blog has a few pages related to it. And don’t worry if you already know C++, as I’m sure many of you do. Hopefully some of the later tutorials will be interesting for you as well – I’ll try to make explanations fairly complete so you’ll still be able to take something from videos.
Now, I have some ideas as to the ‘syllabus’ I’m going to follow. Let me know what you think – anything I’ve missed out, things I should remove until later, or simply a few re-orderings.
- Introduction to C++, GCC and Code::Blocks
- Hello World! Program
- Statements, expressions and operators
- Variables and more operators
- Conditionals – if, else and switch; boolean variables and operators
- Loops – for, while and do while
- Functions – arguments and return types etc; inline functions
- Larger projects – multiple source files, header files, IDE projects
Related articles
- SFML 2.0 Prebuilt Binaries for Download (sfmlcoder.wordpress.com)
- SFML Graphics – Fonts and Text (sfmlcoder.wordpress.com)
- SFML Graphics – Images and Sprites (sfmlcoder.wordpress.com)
- Building SFML 2.0 with Make (for GCC) (sfmlcoder.wordpress.com)
Integers… and Sheep
Hi there! Was just wasting away my time clicking the ‘random‘ button on xkcd (just joking – time on xkcd is never wasted), when I came upon this programming related sketch which I thought I’d share. Enjoy!
Introduction to C++0x
I’ve just recorded a short video introducing you to C++0x. Unless you’ve been living under a rock for the past few years, or don’t have an internet connection (and somehow still frequent my blog) then chances are you know about it anyway. You may well have been reading Dr. Stroustrup’s FAQ, my own C++0x articles, or some of the many other sources available on the new standard.
Anyway, this video is going to be the first in a series that will cover C++0x features in video form, rather than textual. Enjoy!
C++0x Support Chart, and a Revision to Nomenclature
Thought you might like to ssee C++0x support for various compilers. Here is a list for GCC, or you can check out this comparison, which features many of the major compilers: Digital Mars’, Intel’s, Microsoft’s, IBM’s and, of course, GCC.
You’ll see that GCC has better support than many, which is in fact why I’ve recently switched from Microsoft Visual Studio to Code::Blocks and/or Qt Creator. I might post a little more about my experiences thereof at a later date. In particular, notice that both MSVC and GCC support long long and nullptr (about which I posted late yesterday). Indeed, long long has unanimous support across all the compilers mentioned in the chart.
And what about the last part of the title? Well I’ve been continuing to say C++0x (and probably will still do so), but as we can expect it’s release sometime this year, I guess I should start saying C++11. Ah well, I probably won’t. That is all.
Related articles
- C++0x Suffix Return Types (sfmlcoder.wordpress.com)
- C++0x Is Official: Unanimously (cplusplus-soup.com)
- Introduction to C++0x (sfmlcoder.wordpress.com)
- C++ 11 Approved (herbsutter.com)
Two Small C++0x Features
I’m going to mention two little C++0x features today. I don’t have much time, but I thought I may as well share them briefly. They’re both fairly small and quick to explain, so let’s get to it. I’ve put the one that’s faster to discuss first. As always, check out Dr. Stroustrup’s FAQ for more information.
I. long long Integers
The C++0x standard has a new type – the long long integer – which is guaranteed to be at least 64bit. No more annoyances because too many compilers make int and long int the same size – use long long int and you can be sure that you’ll get 8 whole bytes of integral goodness!
Apparently this feature was already supported by a number of compilers, but it’s standard now so you don’t have to worry about non portable code (well you do, but you can blame compiler vendors for being slow to comply with the new standard…
). There’s really not much to say here, merely that you have two 64bit types: long long (i.e. long long int) and unsigned long long (i.e. unsigned long long int). Also note the new literal suffixes: LL for long long and ULL for unsigned long long.
II. nullptr
This one’s exactly as the name suggests: that is, the nullptr keyword represents a null pointer. Previously one might have done something like this:
char* name = 0;
In C++0x, however, one can do the following instead:
char* name2 = nullptr;
These two examples have the same result, that is name == name2 would evaluate to true. On the other hand, while we can also assign the value o to an integral type, we can assign nullptr only to a pointer variable. So the following would yield a compiler error:
int age = nullptr; // compiler error: age is not a pointer
This is all well and good, but it’s quicker to type 0 than nullptr. Why, therefore, should we use the latter over the former? Well the fact is that the double meaning of 0 as the integer 0 and as the null pointer 0×00000000 has the potential to cause problems. Allow me to demonstrate using Dr. Stroustrup’s example. Consider a function f with two overloads:
- void f(int)
- void f(char*)
We call f(0). What happens? Well in fact, f(int) is called, but what if we wanted to pass a null pointer to f(char*). Previously we should have had to resort to something like f((char*)0), which is rather undesirable, in my opinion at least (and, presumably in the opinion of committee members!). So, do the right thing and use nullptr to represent your null pointers.
SFML 2.0 Prebuilt Binaries for Download
As you know, I’ve now started to provide prebuilt SFML 2.0 binaries, downloadable from Google docs. Previously you had to subscribe to the blog by email to get them. However, one or two of you weren’t too keen on this, so I’ve decided to place a link here.
If you’ve already subscribed by email to get them, don’t feel short changed. You’ll still come out on top. I intend to regularly update the binaries, and I’ll send email subscribers an email notification with the new link as soon as the files are online. This page will be updated as well, but I shan’t be able to do it as frequently. Also, of course, you won’t be reminded to download a new version if you’re not subscribed by email.
In fact, I’ll take this opportunity to remind you: to get prompt notification of updated SFML 2.0 binaries, including builds for different platforms, then subscribe to the blog by email if you haven’t already. Just enter your email address on the right and click ‘Sign me up’; if you’re logged in to WordPress, you probably won’t need to enter the email address.
However, if you really don’t want email notifications and prefer to subscribe via WordPress or using the RSS feed then fear not. You can download the binaries on my new downloads page – you just might get updates a little less frequently.
Disclaimer: All the files provided in these downloads are AS-IS. I cannot guarantee that they are suitable for purpose, and nor can I be held accountable or responsible for any damages caused by them, even if I was advised of such. Note also that SFML is developed by Laurent Gomila. I do not intend to imply by this service that I am in any way affiliated with him. I compile the binaries from his source and provide them to you merely as a convenience.
Scheduled Maintenance
The blog’s been quiet for quite a while now, for which I apologise. Basically, my work has dragged on longer than expected, but hopefully I’ll be able to continue soon.
But to the title of the post. My computer is becoming old and too hot, so I am upgrading one or two components and switching case. I also want to reinstall Windows, but there’s no point doing that until the hardware’s been changed. Why should you care? Well basically, I am meaning to upload some prebuilt SFML binaries, but to do so I want to install Visual C++ Express 2008 and 2010 in order to provide the widest range of development options I can. However, my computer is not in a fit state for extra junk right now and frankly I don’t want two of the same IDE on the primary desktop. Therefore, what I’ll do is run it off Virtual PC. Once again, however, I don’t want to get knee deep in that kind of thing until my desktop is new and improved.
Anyway, I hope you won’t lose interest in the mean time, and I’ll try not to keep you waiting too long!
Until then,
Xander



