chore(util): use && when appropriate
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
63bbf07f64
commit
df04dbe096
2 changed files with 14 additions and 14 deletions
|
@ -138,7 +138,7 @@ list<T> append(list<T> const & l1, list<T> const & l2) {
|
|||
\brief Given list <tt>(a_0, ..., a_k)</tt>, return list <tt>(f(a_0), ..., f(a_k))</tt>.
|
||||
*/
|
||||
template<typename T, typename F>
|
||||
list<T> map(list<T> const & l, F f) {
|
||||
list<T> map(list<T> const & l, F && f) {
|
||||
static_assert(std::is_same<typename std::result_of<F(T const &)>::type, T>::value,
|
||||
"map: return type of f is not sxpr");
|
||||
if (is_nil(l)) {
|
||||
|
@ -161,7 +161,7 @@ list<T> map(list<T> const & l, F f) {
|
|||
list cells. The elements are compared using the predicate \c eq.
|
||||
*/
|
||||
template<typename T, typename F, typename Eq = std::equal_to<T>>
|
||||
list<T> map_reuse(list<T> const & l, F f, Eq const & eq = Eq()) {
|
||||
list<T> map_reuse(list<T> const & l, F && f, Eq const & eq = Eq()) {
|
||||
if (is_nil(l)) {
|
||||
return l;
|
||||
} else {
|
||||
|
@ -191,7 +191,7 @@ list<T> map_reuse(list<T> const & l, F f, Eq const & eq = Eq()) {
|
|||
\brief Given list <tt>(a_0, ..., a_k)</tt>, exec f(a_0); f(a_1); ... f(a_k)</tt>.
|
||||
*/
|
||||
template<typename T, typename F>
|
||||
void for_each(list<T> const & l, F f) {
|
||||
void for_each(list<T> const & l, F && f) {
|
||||
static_assert(std::is_same<typename std::result_of<F(T const &)>::type, void>::value,
|
||||
"for_each: return type of f is not void");
|
||||
typedef typename list<T>::cell cell;
|
||||
|
@ -206,7 +206,7 @@ void for_each(list<T> const & l, F f) {
|
|||
\brief Compare two lists using the binary predicate p.
|
||||
*/
|
||||
template<typename T, typename P>
|
||||
bool compare(list<T> const & l1, list<T> const & l2, P p) {
|
||||
bool compare(list<T> const & l1, list<T> const & l2, P && p) {
|
||||
static_assert(std::is_same<typename std::result_of<P(T const &, T const &)>::type, bool>::value,
|
||||
"compare: return type of f is not bool");
|
||||
auto it1 = l1.begin();
|
||||
|
|
|
@ -292,7 +292,7 @@ class splay_tree : public CMP {
|
|||
}
|
||||
|
||||
template<typename F, typename R>
|
||||
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<typename std::result_of<F(T const &, R)>::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<typename F>
|
||||
static void for_each(node const * n, F & f) {
|
||||
static void for_each(node const * n, F && f) {
|
||||
static_assert(std::is_same<typename std::result_of<F(T const &)>::type, void>::value,
|
||||
"for_each: return type of f is not void");
|
||||
if (n) {
|
||||
|
@ -432,20 +432,20 @@ public:
|
|||
<tt>a_0, a_1, ... a_k</tt> are the elements is stored in the splay tree.
|
||||
*/
|
||||
template<typename F, typename R>
|
||||
R fold(F f, R r) const {
|
||||
R fold(F && f, R r) const {
|
||||
static_assert(std::is_same<typename std::result_of<F(T const &, R)>::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>(f), r);
|
||||
}
|
||||
|
||||
/**
|
||||
\brief Apply \c f to each value stored in the splay tree.
|
||||
*/
|
||||
template<typename F>
|
||||
void for_each(F f) const {
|
||||
void for_each(F && f) const {
|
||||
static_assert(std::is_same<typename std::result_of<F(T const &)>::type, void>::value,
|
||||
"for_each: return type of f is not void");
|
||||
for_each(m_ptr, f);
|
||||
for_each(m_ptr, std::forward<F>(f));
|
||||
}
|
||||
};
|
||||
template<typename T, typename CMP>
|
||||
|
@ -453,15 +453,15 @@ splay_tree<T, CMP> insert(splay_tree<T, CMP> & t, T const & v) { splay_tree<T, C
|
|||
template<typename T, typename CMP>
|
||||
splay_tree<T, CMP> erase(splay_tree<T, CMP> & t, T const & v) { splay_tree<T, CMP> r(t); r.erase(v); return r; }
|
||||
template<typename T, typename CMP, typename F, typename R>
|
||||
R fold(splay_tree<T, CMP> const & t, F f, R r) {
|
||||
R fold(splay_tree<T, CMP> const & t, F && f, R r) {
|
||||
static_assert(std::is_same<typename std::result_of<F(T const &, R)>::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>(f), r);
|
||||
}
|
||||
template<typename T, typename CMP, typename F>
|
||||
void for_each(splay_tree<T, CMP> const & t, F f) {
|
||||
void for_each(splay_tree<T, CMP> const & t, F && f) {
|
||||
static_assert(std::is_same<typename std::result_of<F(T const &)>::type, void>::value,
|
||||
"for_each: return type of f is not void");
|
||||
return t.for_each(f);
|
||||
return t.for_each(std::forward<F>(f));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue