General Purpose library for Freestanding C++ and POSIX systems
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
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. }