Try to write a C++ implementation