A GLib-style C library for writing network clients and servers. Abstracts out sockets and event handling (select(), poll(), /dev/epoll, kqueue()
, etc.)
Category Archives: C++
Beyond the C++ Standard Library: An Introduction to Boost
I just finished reading Beyond the C++ Standard Library: An Introduction to Boost. A really interesting read. Some of the more interesting things that I picked up:
boost::shared_ptr
– likeauto_ptr
on steroids, a very nice reference-counted smart pointer. Not only can it clean up memory allocated with new, but you can pass in a custom deleter and thus use it to clean up anything, such as close a file or database connection, etc. The book also coversshared_array, intrusive_ptr, weak_ptr, scoped_ptr,
andscoped_array
boost::numeric_cast
can warn you when you’re casting a number to a smaller number type that will truncate.boost::lexical_cast
can convert back and forth between strings and numbers, thereby accomplishing in one concise line, conversions that I normally do with a few lines ofstringstream
code.boost::regex
can do all kinds of interesting things with regular expressions.boost::any
is an interesting variant type that allows storing several types of values, but is type-safe in the sense that it makes the caller specify the correct type in order to gain access.boost::tuple
is a logical extension ofstd::pair
and allows a nice way to get multiple return values from a function:boost::tuple
gcd_lcm(int val1, int val2); ... boost::tie(gcd, lcm) = gcd_lcm(15, 20); boost::signal
is an interesting “signals and slots” (or “publish and subscribe” or callbacks) implementation.
Messing around with Anjuta and Fink
I had some trouble getting Eclipse working on my FreeBSD box so I started to mess around a bit with Anjuta yesterday – surprisingly nice-looking C/C++ (GNOME-based) IDE.
So then I thought I’d install Anjuta on my PowerBook so that I could play with it offline. I figured it would be a simple Fink install but alas it was not. It’s only on the unstable branch of Fink and it seems that my Fink was really old and I couldn’t get it to self-update because it insisted that I need gcc-4.0 and I have gcc-4.0.1 (presumably from my recent install of Xcode 2.2?) So I moved /sw
out of the way and reinstalled Fink and set it to look for unstable packages and then had it CVS update from the sources and build. It’s been building now for around 12 hours with no end in site… 🙂
libebt: human-readable backtraces for C++
The libebt library provides a clean way of getting human-readable backtrace messages in C++. It uses the RAII (resource acquisition is initialisation) idiom to manage backtrace stack items.
libebt is a pure template library, so there is no need to link your application against anything.
Exceptions vs. status codes
Here’s a great post about exceptions vs. status codes. The author is very much in the exception camp but he cites a Joel on Software post that argues against exceptions and there is some interesting discussion in the comments.
This is why C++ templates are evil
stlfilt helps, but it doesn’t always save you from template hell.
comaofferimagegeneratorlib.cpp:149: cannot convert `it.Mdbm<_comaofferid ,ImageData *>::iterator::operator ->()-> pair::key_type, Mdbm<_comaofferid ,ImageData *>::data_type>::second' from type `Mdbm<_comaofferid ,ImageData *>::data_type' to type `ImageData *'
It’s not impossible to interpret this, but it isn’t exactly a walk in the park either.
It’s times like these that make me appreciate the utter simplificity of Java and its container classes – by making every object inherit from a common base class (Object) and making containers that contain references to objects of that base class, you get a simple, elegant container mechanism. C++, not having a common base class, resorts to templates – a nifty but sometimes very irritating feature.
Nice little bash function for determining the meaning of error codes
Here’s a cool idea from Deadman.org | Advancing in the Bash shell: