Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. template <typename F>
  2. auto foo (F && f)
  3. {
  4. // ...
  5.  
  6. auto x = std::forward<F>(f)(/* some arguments */);
  7.  
  8. // ...
  9. }
  10.  
  11. template <typename F>
  12. auto foo (F && f)
  13. {
  14. using A = typename decltype(std::function{std::forward<F>(f)})::result_type;
  15.  
  16. A val { std::forward<F>(f)() };
  17.  
  18. return val;
  19. }
  20.  
  21. template <typename F>
  22. auto bar (F && f)
  23. {
  24. using A = typename decltype(std::function{std::forward<F>(f)})::result_type;
  25.  
  26. std::vector<A> vect;
  27.  
  28. for ( auto i { 0u }; i < 10u ; ++i )
  29. vect.push_back(std::forward<F>(f)());
  30.  
  31. return vect;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement