
Dear all, Is there any variadic max function in Boost? I mean something which returns the max of all the arguments it takes -- no matter how many they are. (Feel free to correct me if this use of 'variadic' is not the correct terminology.) Please note that I'm not after working on ranges of arguments. I'm rather looking for a max function which is applicable in all the examples below: int m1 = max(a1, a2); int m2 = max(a1, a2, a3); ... int mk = max(a1, a2, ..., ak); TIA, --Hossein

On Mon, Oct 25, 2010 at 11:08 AM, Hossein Haeri
Dear all,
Is there any variadic max function in Boost? I mean something which returns the max of all the arguments it takes -- no matter how many they are. (Feel free to correct me if this use of 'variadic' is not the correct terminology.) Please note that I'm not after working on ranges of arguments. I'm rather looking for a max function which is applicable in all the examples below:
int m1 = max(a1, a2); int m2 = max(a1, a2, a3); ... int mk = max(a1, a2, ..., ak);
I privately emailed Hervé Brönnimann with a variadic implementation of min/max for inclusion into the minmax library in 2007. It was implemented both as brute force overloads using Boost.PP (up to 10 arguments) and using variadic templates. He said he liked it and would include it. A later reply mentioned that a student of his had independently come up with the same solution and was also working on a proposal for C++0x so he was going to use that one. I'm not sure what happened to it. I don't see it listed in the current Boost documentation, but it was accepted for C++0x, so perhaps your compiler has support for it if you compile in C++0x mode. --Michael Fawcett

On Mon, Oct 25, 2010 at 12:06 PM, Hossein Haeri
Michael,
but it was accepted for C++0x, so perhaps your compiler has support for it if you compile in C++0x mode.
So, which header would that be in? <algorithm> should I suppose?
That would be my guess, but I don't have access to a compiler to try it out right now. Here's the paper: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2551.pdf --Michael Fawcett

On 10/25/2010 11:26 AM, Michael Fawcett wrote:
On Mon, Oct 25, 2010 at 11:08 AM, Hossein Haeri
wrote: Dear all,
Is there any variadic max function in Boost? I mean something which returns the max of all the arguments it takes -- no matter how many they are. (Feel free to correct me if this use of 'variadic' is not the correct terminology.) Please note that I'm not after working on ranges of arguments. I'm rather looking for a max function which is applicable in all the examples below:
int m1 = max(a1, a2); int m2 = max(a1, a2, a3); ... int mk = max(a1, a2, ..., ak);
I privately emailed Hervé Brönnimann with a variadic implementation of min/max for inclusion into the minmax library in 2007. It was implemented both as brute force overloads using Boost.PP (up to 10 arguments) and using variadic templates.
With my variadic macro data library in the sandbox you could probably do it fairly easily for compilers which support variadic macros.

On 10/25/10 10:08, Hossein Haeri wrote:
Dear all,
Is there any variadic max function in Boost? I mean something which returns the max of all the arguments it takes -- no matter how many they are. (Feel free to correct me if this use of 'variadic' is not the correct terminology.) Please note that I'm not after working on ranges of arguments. I'm rather looking for a max function which is applicable in all the examples below:
int m1 = max(a1, a2); int m2 = max(a1, a2, a3); ... int mk = max(a1, a2, ..., ak);
TIA, --Hossein
Compilation with the gcc variadic template compiler and run of attached produces output: /home/evansl/download/gcc/4.5.1-release/install/bin/g++ -Wl,-rpath /home/evansl/download/gcc/4.5.1-release/install/lib64 /home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_5_1v/boost-svn/ro/sandbox/rw/variadic_templates/sandbox/varbin.o -o /home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_5_1v/boost-svn/ro/sandbox/rw/variadic_templates/sandbox/varbin.exe /home/evansl/prog_dev/boost-svn/ro/trunk/sandbox-local/build/gcc4_5_1v/boost-svn/ro/sandbox/rw/variadic_templates/sandbox/varbin.exe 6 60 So, replacing add with another binary op, such as max, should work. HTH, -Larry
participants (4)
-
Edward Diener
-
Hossein Haeri
-
Larry Evans
-
Michael Fawcett