General Purpose library for Freestanding C++ and POSIX systems
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 line
317 B

  1. #pragma once
  2. #include <stddef.h>
  3. namespace gp{
  4. template <typename range, typename F>
  5. void indexed_foreach(range n, F f) {
  6. for(size_t idx = 0; idx < n.size(); ++idx)
  7. {
  8. f(idx, n[idx]);
  9. }
  10. }
  11. template <typename range, typename F>
  12. void foreach(range n, F f) {
  13. for(auto& elem : n)
  14. {
  15. f(elem);
  16. }
  17. }
  18. }