An implementation of a flattening algorithm for C++98 or above.