Questions tagged [erase]

This tag refers to the process of removing or deleting data, text, files, or memory.

739 questions
6
votes
0 answers

Image gets blurry and zoomed out when erasing

I am using functionality of erasing image and my code is like below. You can see Video HERE. Here current_sticker_img is my Imageview NOTE: I am also using Pan Gesture for zooming image //MARK: Eraser touch event override func touchesBegan(_…
Jitendra Modi
  • 2,344
  • 12
  • 34
6
votes
1 answer

std::map Known-Position Erase Amortized Complexity And Number of Red-Black Tree Recolorings

The complexity of std::map::erase(iterator) is amortized O(1) (see here, for example). While the standard library does not dictate implementations, this de-facto means that the number of rebalancing operations needed for a red-black tree is…
Ami Tavory
  • 74,578
  • 11
  • 141
  • 185
6
votes
3 answers

which one is faster using erase or resize in a vector?

In the following code which one is more efficient calling resize or erase ? vector a(5000); //.... vector::iterator it = remove(a.begin(),a.end(),8) a.resize( std::distance(a.begin(),it)); //or a.erase(it,a.end()); I think it depends on…
uchar
  • 2,552
  • 4
  • 29
  • 50
6
votes
2 answers

string::erase(0) on an empty string?

Is the behaviour of std::string::erase(0) is well defined on an empty string. Because cppreference says: Removes count characters starting at index. But for an empty string, the character at index 0 does not exist.
Vincent
  • 57,703
  • 61
  • 205
  • 388
6
votes
4 answers

Remove characters from std::string from "(" to ")" with erase ?

I want to remove the substring of my string , it looks something like this : At(Robot,Room3) or SwitchOn(Room2) or SwitchOff(Room1) How can I remove all the characters from the left bracket ( to the right bracket ) , when I don't know their…
JAN
  • 21,236
  • 66
  • 181
  • 318
5
votes
1 answer

Why do associative containers have an erase overload with non-const iterator argument?

C++11 changed std::vector::erase to take a const_iterator instead of an iterator. The same thing applies to std::deque and std::list, while std::forward_list came in C++11 with erase_after, which also takes a const_iterator. In contrast,…
Nelfeal
  • 12,593
  • 1
  • 20
  • 39
5
votes
3 answers

Will the erase function of set in C++ change the address of other elements?

I have the following code: set test; test.insert(key1); test.insert(key2); iter1 = test.find(key1); iter2 = test.find(key2); test.erase(iter1); My question is, if key1 is deleted, now can I use iter2 to refer to key2 in test? Thanks
cheng
  • 2,106
  • 6
  • 28
  • 36
5
votes
3 answers

Deleting user-defined elements in the middle of a vector

I'm coding a program where I want to draw a card, and then delete so that it doesn't get drawn again. I have a vector of Cards (class containing 2 structs that define Suit and Value) called deck and I don't really know how to use iterators very…
Jota
  • 234
  • 2
  • 11
5
votes
5 answers

Doesn't erasing std::list::iterator invalidates the iterator and destroys the object?

Why does the following print 2? list l; l.push_back( 1 ); l.push_back( 2 ); l.push_back( 3 ); list::iterator i = l.begin(); i++; l.erase( i ); cout << *i; I know what erase returns, but I wonder why this is OK? Or is it undefined, or does…
Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187
5
votes
5 answers

vectors: rend() is being invalidated by erase()

According to the C++ specification (23.2.4.3), vector::erase() only invalidates "all the iterators and references after the point of the erase" As such, when using reverse_iterators to pass over all vector members, an erase on the current iterator…
Mahmoud Al-Qudsi
  • 28,357
  • 12
  • 85
  • 125
5
votes
1 answer

JavaFX: Erase Line by painting

i'm new to JavaFX and i'm trying to draw some things on a canvas. First I'm setting the linecolor to black and draw a line. canvas.getGraphicsContext2D().setStroke(Color.BLACK); canvas.getGraphicsContext2D().strokeLine(20,20,100,100); After this…
Ma Sch
  • 501
  • 1
  • 4
  • 8
5
votes
4 answers

Problem with invalidation of STL iterators when calling erase

The STL standard defines that when an erase occurs on containers such as std::deque, std::list etc iterators are invalidated. My question is as follows, assuming the list of integers contained in a std::deque, and a pair of indicies indicating a…
Matthieu N.
5
votes
6 answers

How can I free a pointer vector?

How can I free up memory in a pointer vector? Here's the code: class A { private: int x,y,z; public: A(param1, param2, param3) { x=param1; y=param2; z=param3; } …
Tibor
  • 105
  • 2
  • 9
5
votes
1 answer

calling .clear() or .erase() on c++ std::multimap sometimes causes freeze (100% cpu)

We are using a multimap for quick value/index lookups, declared like this typedef double Numerical; std::multimap SortableRowIndex; And we fill it up with pairs, using SortableRowIndex.insert(std::pair
5
votes
5 answers

Erasing elements from a vector, if they are also in another vector

Suppose I've a vector a = {"the", "of"} and a vector b = {"oranges", "the", "of", "apples"}. I want to compare both vectors and remove the elements from a which are also in b. This is what I came up with: for (int i = 0; i < a.size(); i++) { for…
muqsitnawaz
  • 236
  • 2
  • 9