implement template dual pivot sort