Subject Archive for Tutorial

How to use Function Pointers in C++
Category: Programming April 7, 2013 Tags: , ,

Function pointers in C++ have a somewhat obtuse syntax and similarly confusing semantics. This tutorial will lay out the syntax and semantics for the most common use cases in a way that is comprehensible and easy to get to grips with. The description here is by no means exhaustive but in my experience it should cover about 90% of the things you would want to do as long as you are making appropriate use of Boost.bind and Boost.function or their std equivalents (as you should be). read on
How to swap two integers without a temporary
Category: Programming October 28, 2012 Tags: , ,

This question is sometimes asked in interviews and it boils down to whether you know about and understand binary XOR. Binary XOR Binary XOR behaves in a slightly non intuitive way. Bits are compared between the two values and if they are the same the result is a 0 if they are different it is […] read on
How to use Boost.Program_options
Category: Programming August 2, 2012 Tags: , , , ,

If it so happens that you’re writing a console application, then chances are you will (or should) want to pass it some parameters at the command line. By default C++ has only the argc and argv parameters to the main function to facilitate this and I can assure you that working with them directly is […] read on
3 Linux Command Line Programming Boosters
Category: Programming November 15, 2011 Tags: , , ,

The following is a description of three linux command line features I use on a regular basis that provide a strong boost to my productivity. Pipe to Clipboard. Find with Exec. Aggressive history for reverse-i-search. read on
How Futures Aid Task Based Multithreading
Category: Programming December 8, 2010 Tags: , , , ,

Task based multithreading makes a lot of sense and is a great way to break work into manageable parcels that can be processed in parallel. A task can be conceptualised as a finite piece of work that produces a result when complete. Using a thread to carry out a task is logical, but the problem […] read on
Function pointers for thread communication
Category: Programming December 8, 2010 Tags: , , , ,

When you program with thread objects (a thread bound to a class instance) in C++ you inevitably run into the need for an effective way of extracting information from them. At this point the dilemma becomes; do you ask the thread for the information or do you get the thread to report it to you? […] read on
How to use Boost.Bind
Category: Programming December 8, 2010 Tags: , , , , ,

Function pointers are a powerful programming tool but are extremely difficult to use with only the standard C++ syntax at your disposal. Boost.Bind steps into this breach, transforming the syntax from obtuse and confusing to intuitive and accessible. This tutorial will walk you through the basics of Boost.Bind in a way that will have you […] read on
Generating Random Numbers in C++
Category: Programming December 8, 2010 Tags: , , ,

Generating random numbers in C++ has long relied on the venerable rand() function. However times have changed (and they did so a while ago) and there is now a new random number facility that replaces rand(), this is the library Boost.Random. Boost.Random is not just another boost library, it was taken as the basis for […] read on
An Object Oriented Approach to Threading in C++
Category: Programming December 8, 2010 Tags: , , , ,

Multithreading in C++ can be a daunting topic to approach. Not only is the subject matter confusing and filled with gotchas, but it can also be hard to know how to effectively implement threads in real code and real situations. In this tutorial I will describe an object oriented approach to dealing with threads that […] read on
How to use Boost.Function
Category: Programming December 8, 2010 Tags: , , , , ,

Specifying variables of function pointer type in standard C++ has a downright filthy syntax and rightly strikes confusion into the hearts of programmers everywhere. Boost.Function provides a different syntax which is far superior in every way. This tutorial shows how to use Boost.Function with examples of common tasks and covers all of the main features […] read on