Inline virtual final

I was looking into virtual functions (that link is the most succinct exposition I have seen) for some of my code. And I began to think, huh, won't this slow things down? The code first has to go to a virtual table and then look up the correct function - that's a WHOLE extra step. …

Advertisements

C++: how to order class declarations

Of course, this is all a matter of opinion. When I started out writing C++ (back in the days of glBegin() and glEnd() ) I followed the convention (which I found in books and example code) of putting all the member variables first, then all the member functions. There was  much hand-wringing about whether the …

C++: Notes on moves and copies

I found the behavior of Objects in STL containers a bit confusing, so I wrote down some notes for myself. (I've updated this post after helpful comments from my colleagues Vladimir Semenyuk and Björn Pollex. They pointed out that I hadn't implemented copy and move constructors in my original code. Hopefully the post now looks …

Derived classes and std::vector

I want to talk about a fun corner of C++ I ran into recently. It has to do with how to handle calling member functions of a list of heterogenous objects. My use case was a bit like the following: say we have a bunch of different functions - a * x^2, b * x, …

Why would I ever write in C?

I've made computers do tricks in both C/C++ and Python for many years now. For the past few years I've written exclusively in Python for both work and play. I recently went back to a personal project to rewrite it in C++ and, for the first time in my life, thought, "Why would I ever …

Get more out of Cython

Getting more out of your Cython code doesn't have to be a black art. A key step is to peek into the cythonized .c file and note if inner loops are getting down to bare C without any of the overheads associated with Python's dynamism. In an earlier post I had introduced Cython, which is …