Boost logo

Boost Users :

Subject: Re: [Boost-users] Variadic Max Function
From: Larry Evans (cppljevans_at_[hidden])
Date: 2010-10-25 14:16:11


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




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net