Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yarp::sig::Vector::erase() #3158

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/libYARP_sig/src/yarp/sig/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,26 @@ class yarp::sig::VectorOf : public VectorBase
}

/**
* Resize the vector and initilize the element to a default value.
* Remove an element from the vector.
* @param pos iterator pointing at the element to remove
*/
void erase(iterator pos)
{
bytes.erase(pos);
}

/**
* Remove one or more elements from the vector.
* @param first iterator pointing at the first element to remove
* @param last iterator pointing at the last element to remove
*/
void erase(iterator first, iterator last)
{
bytes.erase(first, last);
}

/**
* Resize the vector and initialize the element to a default value.
* @param s the new size
* @param def the default value
*/
Expand Down Expand Up @@ -263,7 +282,7 @@ class yarp::sig::VectorOf : public VectorBase
/**
* @brief Construct a new element in the vector: size is changed
* @param args, arguments to be forwarded for constructing the new element.
* @return the reference to the new element contructed.
* @return the reference to the new element constructed.
*/
template<typename... _Args>
inline T& emplace_back(_Args&&... args)
Expand Down
15 changes: 14 additions & 1 deletion src/libYARP_sig/tests/VectorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,20 @@ TEST_CASE("sig::VectorTest", "[yarp::sig]")
CHECK(v[2] == 3.0); // Checking data consistency
}

SECTION("Checking the the for range based")
SECTION("Checking the erase method")
{
Vector v{0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0};
Vector vtest1{0.0, 1.0, 3.0, 4.0, 5.0, 6.0};
Vector vtest2{0.0, 1.0, 5.0, 6.0};

v.erase(v.begin() + 2);
CHECK(v == vtest1);

v.erase(v.begin() + 2, v.begin()+4);
CHECK(v == vtest2);
}

SECTION("Checking the for range based")
{
Vector v{0.0, 1.0, 2.0, 3.0, 4.0};
double i = 0.0;
Expand Down
Loading