std::minmax is an algorithm to obtain the begin and end of a container at the same time.
Operating system(s) or programming environment(s)
- Lubuntu 11.10 (oneiric)
- Qt Creator 2.3.0
- G++ 4.6.1
Libraries used:
- STL: GNU ISO C++ Library, version 4.6.1
Qt project file: CppMinmax.pro
#------------------------------------------------- # # Project created by QtCreator 2012-01-29T10:21:35 # #------------------------------------------------- QT += core QT -= gui QMAKE_CXXFLAGS += -std=c++0x TARGET = CppMinmax CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp
#include <algorithm> #include <cassert> int main() { const std::vector<int> v = { 100,1,2,3,4,5,6,7,8,9,-100 }; const std::pair<std::vector<int>::const_iterator,std::vector<int>::const_iterator> p = std::minmax(v.begin(),v.end()); assert(p.first == v.begin()); assert(p.second == v.end()); const int min = *(p.first); const int max = *(p.second-1); assert(min == 100); assert(max == -100); }