rewrite lf by C++