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.

27 line
537 B

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