General Purpose library for Freestanding C++ and POSIX systems
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

29 行
573 B

4 年前
  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. }