min function that accepts any number of arguments

Hi, std::min accepts only two arguments. When I have more than two arguments to compare, it becomes inconvenient. I'm wondering it is possible to added a min function that accepts any number of arguments in the future version of boost? Thanks, Peng

Peng Yu wrote:
Hi,
std::min accepts only two arguments. When I have more than two arguments to compare, it becomes inconvenient. I'm wondering it is possible to added a min function that accepts any number of arguments in the future version of boost?
Yes, it could probably be done with pseudo-vararg preprocessor magic. However, the next standard contains a real vararg min. Given that, the question is how many people are willing to invest the effort. Pseudo-vararg code is a mess. Sebastian

On Wed, Sep 3, 2008 at 3:11 PM, Sebastian Redl <sebastian.redl@getdesigned.at> wrote:
Peng Yu wrote:
Hi,
std::min accepts only two arguments. When I have more than two arguments to compare, it becomes inconvenient. I'm wondering it is possible to added a min function that accepts any number of arguments in the future version of boost?
Yes, it could probably be done with pseudo-vararg preprocessor magic.
However, the next standard contains a real vararg min. Given that, the question is how many people are willing to invest the effort. Pseudo-vararg code is a mess.
Since Pseudo-vararg code is a mess, we may not what to do it at this moment. But GCC has an option -std=c++0x, can the variadic version min (non-pseudo) be added in boost at least to support GCC before the upcoming C++ standard finalized? Thanks, Peng

On Wed, Sep 3, 2008 at 16:27, Peng Yu <pengyu.ut@gmail.com> wrote:
Since Pseudo-vararg code is a mess, we may not what to do it at this moment. But GCC has an option -std=c++0x, can the variadic version min (non-pseudo) be added in boost at least to support GCC before the upcoming C++ standard finalized?
I suspect that if you have the GCC that supports it, you can also get the libstdc++ that has a variable-argument min. (Or an initializer-list version, if the paper from the lastest mailing goes through.)

On Wed, Sep 3, 2008 at 3:58 PM, Peng Yu <pengyu.ut@gmail.com> wrote:
std::min accepts only two arguments. When I have more than two arguments to compare, it becomes inconvenient. I'm wondering it is possible to added a min function that accepts any number of arguments in the future version of boost?
I emailed a version that did this to Hervé Brönnimann and Doug Gregor I believe. Hervé said that he would try to include it in a future Boost release. FWIW, I used variadic templates, so unless you have a compiler that supports them, my solution is interesting only in an academic sense. --Michael Fawcett

on Wed Sep 03 2008, "Peng Yu" <pengyu.ut-AT-gmail.com> wrote:
Hi,
std::min accepts only two arguments. When I have more than two arguments to compare, it becomes inconvenient. I'm wondering it is possible to added a min function that accepts any number of arguments in the future version of boost?
There's always std::min_element :-) -- Dave Abrahams BoostPro Computing http://www.boostpro.com
participants (5)
-
David Abrahams
-
Michael Fawcett
-
Peng Yu
-
Scott McMurray
-
Sebastian Redl