update c++ template for better iteration