Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::minmax

 

std::minmax is an algorithm to obtain the begin and end of a container at the same time.

 

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

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

 

 

 

 

 

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);
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml