Skip to content

Commit

Permalink
utils: improve max() with folding
Browse files Browse the repository at this point in the history
  • Loading branch information
tmplt committed May 22, 2017
1 parent 9abc219 commit acd5095
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ string full_process(string str);

size_t min(size_t a, size_t b);

#ifdef CPP17

template <typename First, typename ... T>
decltype(auto) max(const First &f, const T & ... t)
{
const First *retval = &f;
( (retval = &std::max(*retval, t)), ... );
return *retval;
}

#else

/*
* An "extension" of std::max() so that more than two arguments
* can be passed. The first argument decides what everything else
Expand All @@ -39,6 +51,8 @@ auto max(const T &first, const Args&... args)
return *max;
}

#endif

} // utils utils

} // utils fuzz

0 comments on commit acd5095

Please sign in to comment.