templated tools::f_nb_element() function