Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. template<class F>
  2. tree find(const tree& where, F&& predicate)
  3. {
  4.     tree ret;
  5.     find_aux(where, std::forward<F>(predicate), ret);
  6.     return ret;
  7. }
  8.  
  9. template<class F>
  10. void find_aux(const tree& where, F&& predicate, tree& accum)
  11. {
  12.     if (predicate(where.value)) accum.add(where.value);
  13.    
  14.     find_aux(where.left,  std::forward<F>(predicate), accum);
  15.     find_aux(where.right, std::forward<F>(predicate), accum);
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement