I have a for loop with a map like this.  std::map&lt;int,std::string&gt; mymap = {{1,"a"},{2,"b"},{3,"c"}};  for(std::map&lt;int,std::string&gt;::iterator it = mymap.begin(); it!=mymap.end(); ++it) {     if(it-&gt;first==3)     {         mymap.erase(it);     } }  std::cout &lt;&lt; mymap.rbegin()-&gt;second &lt;&lt; std::endl;   The output is "b" as expected. The question is: Can this lead to an infinite loop (or a crash) somehow? I mean after  erase(it)   the iterator it is invalid. If the erased item was not the last one, it should be ok, because "it" is incremented after the erasion and when the condition is evaluated it points to mymap.end() at max. But if I erase the last one, after erasion mymap.end() should be after the last remaining item, and then it is incremented anyways. Can't it somehow run out of range? Shouldn't I use something like  for(std::map&lt;int,std::string&gt;::iterator it = mymap.begin(); it!=mymap.end(); ++it) {     std::map&lt;int,std::string&gt;::const_iterator tempit = it;     const bool lastItemErased = ++tempit == mymap.end();      if(it-&gt;first==3)     {         mymap.erase(it);     }      if(lastItemErased) break; }   to be safe?  note: both of the above runs and behaves as expected if I try to erase the element with key 3 and 2. I don't see how is this possible and why doesn't it crash. How can I increment an invalid iterator?  update: It has to work with c++03. I initialized the map like this, to post the question more easily.
In the following code I loop through a map and test if an element needs to be erased.  Is it safe to erase the element and keep iterating or do I need to collect the keys in another container and do a second loop to call the erase()?  map&lt;string, SerialdMsg::SerialFunction_t&gt;::iterator pm_it; for (pm_it = port_map.begin(); pm_it != port_map.end(); pm_it++) {     if (pm_it-&gt;second == delete_this_id) {         port_map.erase(pm_it-&gt;first);     } }   UPDATE: Of course, I then  which I didn't think would be related but answers my question.
Example of a finite non-commutative ring without a unity Give an example of a finite, non-commutative ring, which does not have a unity.    I can't think of any thing which fits this question. I was thinking $M_2(\mathbb{R})$ but it has the identity. Any help is appreciated. What's a good beginner resource to learn group theory? Can one of Newton's Laws of motion be derived from other Newton's Laws of motion? Can one derive Newton's  second and third laws from the first law or   first and third laws from the second law or  first and second  laws from the third  law  I think Newton's laws of motions are independent to each other. They can not be derived from one another. Please share the idea. I am looking for a way to clean up the mess when my top-level script exits.  Especially if I want to use set -e, I wish the background process would die when the script exits. How to install applications to a separate hdd? I was so good with windows, now I’m feeling like a complete idiot.  I have an SSD for ubuntu and want to install the majority of my programs to a separate HDD but I have no clue how. All searches I have tried only turn up with dual-boot installations.   (RESOLVED -> ) I am also having trouble locating "/etc/". Specifically, to modify Conky. Searching for this term only turns up instances where people are telling you to access this file, not how to get to it. Can't indent heredoc to match code block's indentation If there's a "First World Problems" for scripting, this would be it.   I have the following code in a script I'm updating:  if [ $diffLines -eq 1 ]; then         dateLastChanged=$(stat --format '%y' /.bbdata | awk '{print $1" "$2}' | sed 's/\.[0-9]*//g')          mailx -r "Systems and Operations &lt;sysadmin@[redacted].edu&gt;" -s "Warning Stale BB Data" jadavis6@[redacted].edu &lt;&lt;EOI         Last Change: $dateLastChanged          This is an automated warning of stale data for the UNC-G Blackboard Snapshot process. EOI  else         echo "$diffLines have changed" fi   The script sends email without issues, but the mailx command is nested within an if statement so I appear to be left with two choices:    Put EOI on a new line and break indentation patterns or Keep with indentation but use something like an echo statement to get mailx to suck up my email.   I'm open to alternatives to heredoc, but if there's a way to get around this it's my preferred syntax. Give a sequence such that root test works while ratio test fails Write this equation I want to write this equation in this way down but I have been unsuccessful. How can I improve this codes in order to get the equation below?  \[ DeltaC{t} = \left\{ \begin{array}{ll}  -1.40- 0.588w_{t-1} - 0.5351\DeltaC_{t-1}+ 0.169\DeltaBC_{t-1} &amp; \mbox{ if $w_{t-1}&lt;- 0.62$} \\ -1.40 - 0.588w_{t-1} - 0.5351\DeltaC_{t-1} + 0.169\DeltaBC_{t-1} &amp; \mbox{$w_{t-1}&gt;0.62$} \end{array} \right. \] If $n\ne 4$ is composite, then $n$ divides $(n-1)!$. I have a proof and need some feedback. It seems really obvious that the statement is true but it is always the obvious ones that are a little trickier to prove. So I would appreciate any feedback. Thank you!  Here is what I am asked to prove:     If $n$ is composite then $(n-1)! \equiv 0 \pmod n$.   Proof:  $n$ is composite $\implies n=ab$ where $a,b \in \mathbb{Z}$ and $0&lt;a,b&lt;n$.  Case 1: If $a=b$ then $n=a^{2}$. Now $n \mid (n-1)! \implies a \mid (n-1)!$, so $$\begin{aligned} (n-1)! &amp;\equiv 1\times 2\times \dotsb \times a \times\dotsb\times (n-a)\times\dotsb\times (n-1) \\ &amp;\equiv 1\times 2\times \dotsb\times a \times\dotsb\times -a\times\dotsb\times -1 \\ &amp;\equiv 0 \pmod n \end{aligned}$$  Case 2: $0&lt;a&lt;b&lt;n$.  Then, since $a \mid n$, $b \mid n$ and $n \mid (n-1)!$ we have that $a \mid (n-1)!$ and $b \mid (n-1)!$.  So this implies $(n-1)! \equiv 1\times 2\times \dotsb\times a \times\dotsb\times b\times\dotsb\times (n-1) \equiv 0 \pmod n$, Q.E.D. Can space expand with unlimited speed? just after the Big Bang and before inflation the currently observable universe was the size of a coin. One millionth of a second later the universe was the size of the Solar System, which is an expansion much much faster than speed of light. Can space expand with unlimited speed? What is this electronics symbol (four triangles?) The below image is from a service manual for a mobile radio. Note the small symbols that appear to be four triangles, point to point. I've searched far and wide and cannot identify that symbol. I have a nagging feeling that I've seen something like it in hydraulics, but never in an electronics diagram. I know that my radio doesn't have a bunch of stars of David printed inside it, so what could this symbol be?  Some of them have a line through the middle, others don't. Compare for example the ones near the labels "mic int" and "mic ext". Does this represent something, or is it a typo? Why don't the Ubuntu repositories have the latest versions of software? Why use a z test rather than a t test with proportional data? When testing the difference between 2 proportions why do we use a z-test rather than a t-test?    Further, is there a simple way to conduct an omnibus test for significant differences between more than 2 proportions (in the form of percentages). Is there an equivalent to a one-way ANOVA for this?  I imagine that you could use logistic regression (assuming you have the original data for the proportions in the form of 0s and 1s) Are there other options? How to only append to clipboard (but not overwrite current data)? I can't understand where the final keyword is really handy when it is used on method parameters.    If we exclude the usage of anonymous classes, readability and intent declaration then it seems almost worthless to me.   Enforcing that some data remains constant is not as strong as it seems.    If the parameter is a primitive then it will have no effect since the parameter is passed to the method as a value and changing it will have no effect outside the scope.  If we are passing a parameter by reference, then the reference itself is a local variable and if the reference is changed from within the method, that would not have any effect from outside of the method scope.    Consider the simple test example below. This test passes although the method changed the value of the reference given to it, it has no effect.  public void testNullify() {     Collection&lt;Integer&gt; c  = new ArrayList&lt;Integer&gt;();           nullify(c);     assertNotNull(c);            final Collection&lt;Integer&gt; c1 = c;     assertTrue(c1.equals(c));     change(c);     assertTrue(c1.equals(c)); }  private void change(Collection&lt;Integer&gt; c) {     c = new ArrayList&lt;Integer&gt;(); }  public void nullify(Collection&lt;?&gt; t) {     t = null; } I have a script myscript.sh  #!/bin/sh  echo $1 $2   which is used something like ...  ./myscript.sh foo bar   which gives me an output of ...  foo bar     but how can i make this script include custom command options? for example ...  ./myscript.sh -a foo and corespond to $1   and  ./myscript.sh -b bar and corespond to $2 I have two independent groups: from one I have drawn a sample of size less than 30 due to its small population, while the second group has sample size 100.  Is it appropriate to use an independent samples t-test in this case? Find directories and files with permissions other than 775 / 664 What version of Ubuntu should I pick? I'm just a simple user frustrated with Windows 10 and I want to leave Windows altogether.  However, I don't want to spend three weeks learning how to install the new system and then get all my current programs to work.  I am not setting up a server, I am not a developer and I do not want all my stuff on a cloud. LED light needs replacing every few weeks I have two GU5.3 bulbs in my bathroom - one of them went off a month or so ago so I bought the following 3 pack:   I've gone through 2 of the new bulbs in the space of weeks. I have never seen the bulbs fade out while being on, it's only when we turn the light switch on that they don't come back on (like this morning, I was first in the bathroom and the bulb was off again). No fuses blown or any indication of tripping.  How should I approach this?