some C++ utility code