Peng Yu wrote:
On Sep 3, 2:40 pm, Leandro Melo <ltcm...@gmail.com> wrote:
On 3 set, 16:33, Peng Yu <PengYu...@gmail.com> wrote:
Hi,
I'm wondering if there is a min function (in boost, maybe?) that
accepts any number of arguments? std::min only accepts two arguments.
If I want to get the minimum number out of many, I have use std::min
many times, which is not convenient.
Hi.
Maybe, you could iterate through the elements with a for (or something
similar) keeping track of the smallest element. This is pretty simple.
Hi,
The numbers are at compile time not at runtime time. It has to some
how use the template to implement such a function.
How many numbers are we talking about? You can roll your own 'min_of'
implementation using recursive template definitions in no time, can't you?
template<class T> T min_of(T t1, T t2) {
return std::min(t1, t2);}
template<class T> T
min_of(T t1, T t2, T t3) {
return std::min(min_of(t1, t2), t3);}
template<class T> T
min_of(T t1, T t2, T t3, T t4) {
return std::min(min_of(t1, t2, t3), t4);}
template<class T> T
min_of(T t1, T t2, T t3, T t4, T t5) {
return std::min(min_of(t1, t2, t3, t4), t5);}
... and so on
I can define my own version of min_of. But I feel that the min
library. I think that it is worthwhile to add such function in boost
if it is not there. At this point, since the issue is with boost,