"Ganny" <> ???????/???????? ? ???????? ?????????:
news: oups.com...
> Is it possible to write a template function min that takes variable
> number of arguments? It should be without using ugly C var args,
> arrays, or statically overloading the method for N arguments. Say, min
> function which will take N arguments. Any approaches like generative
> programming will help?
>
> -Ganesh
>
Another suggestion would be to pass one at a
time,just like Andrei Alexandrescu suggests in
one of his articles,"Inline Containers".Just
imagine how standard streams handle this:
namespace manyargs{
template <typename T>
class minfunc
{
public:
minfunc(const T& x)

tr(&x){}
minfunc& operator() (const T& x)
{
if(*ptr_>x) ptr_=&x;
return *this;
}
const T& operator() ()
{
return *ptr_;
}
private:
const T* ptr_;
};
template <typename T>
minfunc<T> min(const T& x)
{
return minfunc<T>(x);
}
}
And use it like this:
int a=manyargs::min(123)(56)(78

(777)();
I agree that the syntax is somewhat ugly,but
still completely typesafe, as opposed to printf
and their kin.