Here my code. I want remove from vector all elements with successfully called method 'release'.  bool foo::release() {     return true; }  // ... vector&lt;foo&gt; vec; // ... remove_if(vec.begin(), vec.end(), [](foo &amp; f) { return f.release() == true; }); // ...   But remove_if not deleting all elements from vector vec. How remove_if works?
634
I want to clear a element from a vector using the erase method. But the problem here is that the element is not guaranteed to occur only once in the vector. It may be present multiple times and I need to clear all of them. My code is something like this:  void erase(std::vector&lt;int&gt;&amp; myNumbers_in, int number_in) {     std::vector&lt;int&gt;::iterator iter = myNumbers_in.begin();     std::vector&lt;int&gt;::iterator endIter = myNumbers_in.end();     for(; iter != endIter; ++iter)     {         if(*iter == number_in)         {             myNumbers_in.erase(iter);         }     } }  int main(int argc, char* argv[]) {     std::vector&lt;int&gt; myNmbers;     for(int i = 0; i &lt; 2; ++i)     {         myNmbers.push_back(i);         myNmbers.push_back(i);     }      erase(myNmbers, 1);      return 0; }   This code obviously crashes because I am changing the end of the vector while iterating through it. What is the best way to achieve this? I.e. is there any way to do this without iterating through the vector multiple times or creating one more copy of the vector?
98843
In my initial basic tests it is perfectly safe to do so.  However, it has struck me that attempting to manipulate this later in a function that deletes this could be a runtime error.  Is this true, and is it normally safe to delete this? or are there only certain cases wherein it is safe?
16396
I am trying to write a little script that checks if mesh has more than one material, and if it does, remove materials until there is only one left on the item. Here is what I have so far: import bpy for ob in bpy.data.objects:     number_of_mats = len(ob.material_slots.items())     if number_of_mats &gt; 1:         for i in range(number_of_mats-1):             # remove material here?  I cannot seem to figure out the method to remove a mat at this point. Any suggestions?
14806
How do I remove empty elements from an array in JavaScript?   Is there a straightforward way, or do I need to loop through it and remove them manually?
73942
Can someone explain to me how XOR swapping of two variables with no temp variable works?  void xorSwap (int *x, int *y) {     if (x != y) {         *x ^= *y;         *y ^= *x;         *x ^= *y;     } }   I understand WHAT it does, but can someone walk me through the logic of how it works?
4188
While I was investigating a problem I had with lexical closures in Javascript code, I came along this problem in Python:  flist = []  for i in xrange(3):     def func(x): return x * i     flist.append(func)  for f in flist:     print f(2)   Note that this example mindfully avoids lambda. It prints "4 4 4", which is surprising. I'd expect "0 2 4".   This equivalent Perl code does it right:  my @flist = ();  foreach my $i (0 .. 2) {     push(@flist, sub {$i * $_[0]}); }  foreach my $f (@flist) {     print $f-&gt;(2), "\n"; }   "0 2 4" is printed.  Can you please explain the difference ?    Update:   The problem is not with i being global. This displays the same behavior:  flist = []  def outer():     for i in xrange(3):         def inner(x): return x * i         flist.append(inner)  outer() #~ print i   # commented because it causes an error  for f in flist:     print f(2)   As the commented line shows, i is unknown at that point. Still, it prints "4 4 4".
10585
Right now I have vector3 values represented as lists. is there a way to subtract 2 of these like vector3 values, like  [2,2,2] - [1,1,1] = [1,1,1]   Should I use tuples?  If none of them defines these operands on these types, can I define it instead?  If not, should I create a new vector3 class?
4408
I just noticed that you can not use standard math operators on an enum such as ++ or +=  So what is the best way to iterate through all of the values in a C++ enum?
14235
That's basically the question, is there a "right" way to implement operator&lt;&lt; ? Reading  I can see that something like:  friend bool operator&lt;&lt;(obj const&amp; lhs, obj const&amp; rhs);   is preferred to something like   ostream&amp; operator&lt;&lt;(obj const&amp; rhs);   But I can't quite see why should I use one or the other.  My personal case is:  friend ostream &amp; operator&lt;&lt;(ostream &amp;os, const Paragraph&amp; p) {     return os &lt;&lt; p.to_str(); }   But I could probably do:  ostream &amp; operator&lt;&lt;(ostream &amp;os) {     return os &lt;&lt; paragraph; }   What rationale should I base this decision on?  Note:   Paragraph::to_str = (return paragraph)    where paragraph's a string.
62334
I have an array of values that is passed to my function from a different part of the program that I need to store for later processing.  Since I don't know how many times my function will be called before it is time to process the data, I need a dynamic storage structure, so I chose a std::vector.  I don't want to have to do the standard loop to push_back all the values individually, it would be nice if I could just copy it all using something similar to memcpy.
98262
Why won't this work?  I'm trying to make an instance of a class delete itself.  &gt;&gt;&gt; class A():     def kill(self):         del self   &gt;&gt;&gt; a = A() &gt;&gt;&gt; a.kill() &gt;&gt;&gt; a &lt;__main__.A instance at 0x01F23170&gt;
49084
How do I remove an element from a list by index in Python?  I found the list.remove method, but say I want to remove the last element, how do I do this? It seems like the default remove searches the list, but I don't want any search to be performed.
3035
I have a solid understanding of most OOP theory but the one thing that confuses me a lot is virtual destructors. I thought that the destructor always gets called no matter what and for every object in the chain. When are you meant to make them virtual and why?
11629
Is it possible to delete multiple elements from a list at the same time? If I want to delete elements at index 0 and 2, and try something like del somelist[0], followed by del somelist[2], the second statement will actually delete somelist[3].  I suppose I could always delete the higher numbered elements first but I'm hoping there is a better way.
21198
I'm trying to remove a specific, named, item if it is dropped on the floor. I have the following on my command block:  kill @e[type=Item] {Item:{tag:{display:{Name:"RedFlag"}}}   But it's removing all items, not just the one I want. What am I doing wrong?  I also tried  kill @e[type=Item] {Item:{id:"red_flower",Damage:2}}   But that didn't work either, it's still removing all items, even things that aren't red flowers!
4181
What's the best way to break from nested loops in Javascript?  //Write the links to the page. for (var x = 0; x &lt; Args.length; x++) {    for (var Heading in Navigation.Headings)    {       for (var Item in Navigation.Headings[Heading])       {          if (Args[x] == Navigation.Headings[Heading][Item].Name)          {             document.write("&lt;a href=\""                 + Navigation.Headings[Heading][Item].URL + "\"&gt;"                 + Navigation.Headings[Heading][Item].Name + "&lt;/a&gt; : ");             break; // &lt;---HERE, I need to break out of two loops.          }       }    } }
42562
How could I go about detecting (returning true/false) whether an ArrayList contains more than one of the same element in Java?  Many thanks, Terry  Edit Forgot to mention that I am not looking to compare "Blocks" with each other but their integer values. Each "block" has an int and this is what makes them different. I find the int of a particular Block by calling a method named "getNum" (e.g. table1[0][2].getNum();