An Efficient implementation of TopK algorithm using C++ templates