Boost logo

Boost :

From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2006-08-07 16:11:21


Joe Gottman wrote:
> This looks very nice. I hope the standards committee accepts it. I do have
> one question: is it possible to define a variadic function such that all the
> variadic parameters are of the same type? This would be useful, for
> instance, to define a max() function that can finds the max value of any
> number of parameters:
>
> long x1, x2, x3, x4, x5;
> // Some code
> const long &max_x = max(x1, x2, x3, x4, x5);
>
> If this is possible, would it be possible to define a variadic function
> without making it a template function?

FWIW, you can do that today by providing an overload of std::mac_element:

template< class Rng >
range_iterator<Rng>::const_iterator max_element( const Rng& r )
{ return std::max_element( boost::begin(r), boost::end(r) ); }

const long& max = *max_element(
boost::assign::ref_list_of(x1)(x2)(x3)(x4) );

-Thorsten


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk