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.

29 lines
573 B

4 years ago
  1. #pragma once
  2. #include "gp_config.hpp"
  3. #include "gp/algorithms/move.hpp"
  4. namespace gp{
  5. // TODO: this goes in functional
  6. template<typename T>
  7. T identity(T v){return v;}
  8. template<typename T>
  9. T& identity(T& v){return v;}
  10. template<typename it, typename transform>
  11. auto&& min_of(it beg, it end, transform fn = identity) {
  12. gp_config::assertion(beg != end, "min_of provided with empty range");
  13. auto fn_v = fn(*beg);
  14. ++beg;
  15. while(beg != end) {
  16. auto n_fn_v = fn(*beg);
  17. if(n_fn_v < fn_v) {
  18. fn_v = n_fn_v;
  19. }
  20. ++beg;
  21. }
  22. return gp::move(fn_v);
  23. }
  24. }