diff --git a/src/util/list_fn.h b/src/util/list_fn.h index 86ec4c0fc..c72e56985 100644 --- a/src/util/list_fn.h +++ b/src/util/list_fn.h @@ -137,17 +137,17 @@ list append(list const & l1, list const & l2) { /** \brief Given list (a_0, ..., a_k), return list (f(a_0), ..., f(a_k)). */ -template -list map(list const & l, F && f) { - static_assert(std::is_same::type, T>::value, +template +list map2(list const & l, F && f) { + static_assert(std::is_same::type, To>::value, "map: return type of f is not equal to input type"); if (is_nil(l)) { - return l; + return list(); } else { - buffer::cell*> tmp; + buffer::cell*> tmp; to_buffer(l, tmp); unsigned i = tmp.size(); - list r; + list r; while (i > 0) { --i; r = cons(f(tmp[i]->head()), r); @@ -156,6 +156,14 @@ list map(list const & l, F && f) { } } +/** + \brief Given list (a_0, ..., a_k), return list (f(a_0), ..., f(a_k)). +*/ +template +list map(list const & l, F && f) { + return map2(l, std::move(f)); +} + /** \brief Filter/Remove elements from the list that do not satisfy the given predicate.