C++ implementation.