fn: std::vector.erase

[contents]

Contents

Syntax

The syntax for std::vector.erase calls is:

f++:  
name.erase(index)
name.erase(index, index)
std::vector.erase(name, index)
std::vector.erase(name, index, index)

n++:  
@name.erase(index)
@name.erase(index, index)
@std::vector.erase(name, index)
@std::vector.erase(name, index, index)

Description

The std::vector.erase function takes:

  • two parameters with the first parameter being the name of a standard C++ vector variable and the second variable being a valid index, it erases the element at the specified index; or
  • an optional third index parameter and erases the elements between the two specified indices.

As a member function it takes:

  • a single index parameter and erases the element at the specified index; or
  • two index parameters and erases the elements between the two specified indices.

Note: For large scale projects you will find specifying the !mf option to not add member functions during definitions and using std::vector.erase is faster than using the erase member function.

f++ example

Example of std::vector.erase being used with f++:

std::vector<double> v
v.push_back(2.0, 5.3, 3.26)
v.erase(1)
std::vector.erase(v, 0)
console(v.at(0))

n++ example

Example of std::vector.erase being used with n++:

@std::vector<double> v
@v.push_back(2.0, 5.3, 3.26)
@v.erase(1)
@std::vector.erase(v, 0)
@console(v.at(1))
@console(std::vector.at(v, 2))

Sponsors