From df04dbe096dfcc958a19430365be21cf08342973 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Thu, 21 Nov 2013 12:48:04 -0800 Subject: [PATCH] chore(util): use && when appropriate Signed-off-by: Leonardo de Moura --- src/util/list_fn.h | 8 ++++---- src/util/splay_tree.h | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/util/list_fn.h b/src/util/list_fn.h index 0b937861a9..3c0e6aec41 100644 --- a/src/util/list_fn.h +++ b/src/util/list_fn.h @@ -138,7 +138,7 @@ 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) { +list map(list const & l, F && f) { static_assert(std::is_same::type, T>::value, "map: return type of f is not sxpr"); if (is_nil(l)) { @@ -161,7 +161,7 @@ list map(list const & l, F f) { list cells. The elements are compared using the predicate \c eq. */ template> -list map_reuse(list const & l, F f, Eq const & eq = Eq()) { +list map_reuse(list const & l, F && f, Eq const & eq = Eq()) { if (is_nil(l)) { return l; } else { @@ -191,7 +191,7 @@ list map_reuse(list const & l, F f, Eq const & eq = Eq()) { \brief Given list (a_0, ..., a_k), exec f(a_0); f(a_1); ... f(a_k). */ template -void for_each(list const & l, F f) { +void for_each(list const & l, F && f) { static_assert(std::is_same::type, void>::value, "for_each: return type of f is not void"); typedef typename list::cell cell; @@ -206,7 +206,7 @@ void for_each(list const & l, F f) { \brief Compare two lists using the binary predicate p. */ template -bool compare(list const & l1, list const & l2, P p) { +bool compare(list const & l1, list const & l2, P && p) { static_assert(std::is_same::type, bool>::value, "compare: return type of f is not bool"); auto it1 = l1.begin(); diff --git a/src/util/splay_tree.h b/src/util/splay_tree.h index 0814f6ae93..b9d5feec00 100644 --- a/src/util/splay_tree.h +++ b/src/util/splay_tree.h @@ -292,7 +292,7 @@ class splay_tree : public CMP { } template - static R fold(node const * n, F & f, R r) { + static R fold(node const * n, F && f, R r) { static_assert(std::is_same::type, R>::value, "fold: return type of f(t : T, r : R) is not R"); if (n) { @@ -305,7 +305,7 @@ class splay_tree : public CMP { } template - static void for_each(node const * n, F & f) { + static void for_each(node const * n, F && f) { static_assert(std::is_same::type, void>::value, "for_each: return type of f is not void"); if (n) { @@ -432,20 +432,20 @@ public: a_0, a_1, ... a_k are the elements is stored in the splay tree. */ template - R fold(F f, R r) const { + R fold(F && f, R r) const { static_assert(std::is_same::type, R>::value, "fold: return type of f(t : T, r : R) is not R"); - return fold(m_ptr, f, r); + return fold(m_ptr, std::forward(f), r); } /** \brief Apply \c f to each value stored in the splay tree. */ template - void for_each(F f) const { + void for_each(F && f) const { static_assert(std::is_same::type, void>::value, "for_each: return type of f is not void"); - for_each(m_ptr, f); + for_each(m_ptr, std::forward(f)); } }; template @@ -453,15 +453,15 @@ splay_tree insert(splay_tree & t, T const & v) { splay_tree splay_tree erase(splay_tree & t, T const & v) { splay_tree r(t); r.erase(v); return r; } template -R fold(splay_tree const & t, F f, R r) { +R fold(splay_tree const & t, F && f, R r) { static_assert(std::is_same::type, R>::value, "fold: return type of f(t : T, r : R) is not R"); - return t.fold(f, r); + return t.fold(std::forward(f), r); } template -void for_each(splay_tree const & t, F f) { +void for_each(splay_tree const & t, F && f) { static_assert(std::is_same::type, void>::value, "for_each: return type of f is not void"); - return t.for_each(f); + return t.for_each(std::forward(f)); } }