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

25 行
535 B

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