Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) StdVectorExample2

 

Cpp98Qt CreatorLubuntuWindows

 

std::vector example 2: erase-remove idiom is a std::vector example that demonstrates the erase-remove idiom.

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppStdVectorExample2/CppStdVectorExample2.pro

 

TEMPLATE = app
CONFIG += console
CONFIG -= qt
QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++ -Werror
SOURCES += main.cpp

 

 

 

 

 

./CppStdVectorExample2/main.cpp

 

#include <algorithm>
#include <cassert>
#include <vector>

int main()
{
  const std::vector<int> v_expected { 1,2,3,4,5,6,7 };
  std::vector<int> v { 0,1,0,2,0,0,3,4,0,5,0,0,6,7,0 };

  //The erase-remove idiom
  v.erase(std::remove(v.begin(),v.end(),0),v.end());

  assert(v == v_expected);
}

 

 

 

 

 

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