Java's min(long... values) equivalent in C++

How should look C++ version of a method below? I mean, is there any possibility to create a "..." in C++?

1
2
3
4
5
6
7
8
9
long min(final long... values) {
	long minimum = Long.MAX_VALUE;
	for (final long value : values) {
		if (value < minimum) {
			minimum = value;
		}
	}
	return minimum;
}
You can dig this up for C and C++ by looking for varargs or the stdarg header.

A better way to do this, though, would be to just have the values in a vector or some other container that keeps track of its own size (and indeed, to use the provided min_element function from <algorithms> )

1
2
3
4
long min(vector<long> inputVector)
{
  return (*min_element(&(inputVector[0]),&(inputVector[0])+inputVector.size()));
}
Last edited on
Topic archived. No new replies allowed.