How to copy keys from map to vector. Specifically I have a map&lt;int, int&gt; and I want keys of the map to form a new vector (vector&lt;int&gt;).  So a map (&lt;1,100&gt;; &lt;2,99&gt;) should give a vector of (1,2).   Question , describes exactly what I need but for values, but the response is too cryptic to understand. I cannot understand how the unary operator function is written. Can somebody explain how it is written?
This is one of the possible ways I come out:  struct RetrieveKey {     template &lt;typename T&gt;     typename T::first_type operator()(T keyValuePair) const     {         return keyValuePair.first;     } };  map&lt;int, int&gt; m; vector&lt;int&gt; keys;  // Retrieve all keys transform(m.begin(), m.end(), back_inserter(keys), RetrieveKey());  // Dump all keys copy(keys.begin(), keys.end(), ostream_iterator&lt;int&gt;(cout, "\n"));   Of course, we can also retrieve all values from the map by defining another functor RetrieveValues.  Is there any other way to achieve this easily? (I'm always wondering why std::map does not include a member function for us to do so.)
The difficulty is that it should be cross platform. Windows 2000, XP, Vista, OSX, Linux, other unix variants. I am looking for a snippet of code that can accomplish this for all platforms, and a way to detect the platform.  Now, you should be aware of  that user.home does not work correctly, so please do not provide me of textbook answers, I can find these myself in the manuals. how to get the last character of a string? The cartesian product $\mathbb{N} \times \mathbb{N}$ is countable I'm examining a proof I have read that claims to show that the Cartesian product $\mathbb{N} \times \mathbb{N}$ is countable, and as part of this proof, I am looking to show that the given map is surjective (indeed bijective), but I'm afraid that I can't see why this is the case. I wonder whether you might be able to point me in the right direction?  Indeed, the proof begins like this:  "For each $n \in \mathbb{N}$, let $k_n, l_n$ be such that $n = 2^{k_n - 1} \left(2l_n - 1 \right)$; that is, $k_n - 1$ is the power of $2$ in the prime factorisation of $n$, and $2 l_n - 1$ is the (necessarily odd) number $\frac{n}{2^{k_n - 1}}$."  It then states that $n \mapsto \left(k_n , l_n \right)$ is a surjection from $\mathbb{N}$ to $\mathbb{N} \times \mathbb{N}$, and so ends the proof.  I can intuitively see why this should be a bijection, I think, but I'm not sure how to make these feelings rigorous?   I suppose I'd say that the map is surjective since given any $\left(k_n , l_n \right) \in \mathbb{N} \times \mathbb{N}$ we can simply take $n$ indeed to be equal to $2^{k_n - 1} \left(2l_n - 1 \right)$ and note that $k_n - 1 \geq 0$ and thus $2^{k_n - 1}$  is both greater or equal to one so is a natural number (making the obvious inductive argument, noting that multiplication on $\mathbb{N}$ is closed), and similarly that $2 l_n - 1 \geq 2\cdot 1 - 1 = 1$ and is also a natural number, and thus the product of these two, $n$ must also be a natural number. Is it just as simple as this?  I suppose my gut feeling in the proving that the map is injective would be to assume that $2^{k_n - 1} \left(2 l_n - 1 \right) = 2^{k_m - 1} \left(2 l_m - 1 \right)$ and then use the Fundamental Theorem of Arithmetic to conclude that $n = m$. Is this going along the right lines? The 'implicit' definition of the mapping has me a little confused about the approach.    On a related, but separate note, I am indeed aware that if $K$ and $L$ are any countable sets, then so is $K \times L$, so trivially, taking the identity mapping we see trivially that this map is bijective and therefore that $\mathbb{N}$ is certainly countable (!), and thus so is $\mathbb{N} \times \mathbb{N}$. Hence, it's not really the statement that I'm interested in, but rather the exciting excursion into number theory that the above alternative proof provides. I was looking for a possible duplicated question about  in , then looked using the Big G! since the integrated search didn't give me any useful result (laugs) then I found the , but in Stackoverflow! Then, I proceed to flag as off-topic, but since "It's too old to migrate" I don't have the option to do so...  So, my question is, should I leave it like that? Or the question is better in UL (also on topic, just read the question)? Any guidance to this young pada-wan is greatly appreciated. Difference between might and could What could cause exposure problems after my camera got wet? I had an unfortunate accident where my DSLR camera (and me) briefly ended up in a river. The camera wasn't fully submerged but it did get very wet. It still works, sort of, although the electrics are doing some random things. I'm hoping that's just a bit of dampness doing that, that will fix itself when it dries out fully.  More concerning is that the documents exposure metering seems to be all wrong when using the viewfinder. Pictures are extremely overexposed and nearly white. But if I use live view, then they are fine.  Why could cause this? I assume the light is routed a different way when using the viewfinder and maybe it is going through something with water/condensation on it? I've tried to set -g mouse on, and it works pretty well, but standard mouse behaviour (select, copy &amp; paste) is disabled. But, it enables if I press "Shift" button, and while I hold it, I can select, copy &amp; paste text from/to terminal. Can I inverse this behaviour? I want to use mouse inside tmux (for example to select panes or resize them) only with shift pressed. Connect Java to a MySQL database For a multiclass imbalanced problem, accuracy is not a good metric to evaluate model performance. Equally, accuracy is a global metric, so nothing like accuracy per-class (doesn't make sense). Scikit-learn provides the classification_report  function so one can evaluate model's precision/recall per class, e.g: classification_report(y_true, y_pred, target_names=target_names)               precision    recall  f1-score   support       Class:0      0.703     0.896     0.788      4491      Class:1      0.048     0.147     0.072        75      Class:2      0.368     0.503     0.425      1097      Class:3      0.937     0.850     0.892     17162      Class:4      0.529     0.177     0.265       311      accuracy                          0.832     23136    macro avg      0.517     0.515     0.488     23136 weighted avg      0.856     0.832     0.838     23136  Are there other metrics that evaluate per-class so I can evaluate my model across more metrics than precision/recall/f1? The goal is to assess the model on a per-class basis. I changed permissions of a file (chmod g+w testfile) and running ls -l testfile gives:  -rwxrwxr-x 1 user1 user1 0 2011-01-24 20:36 testfile   I then added a user to that group ("/etc/group" has user1:x:1000:user2 line), but am failing to edit that file as user2. Why is this so? Am I correct to say the difference between a signed and unsigned integer is:  Unsigned can hold a larger positive value and no negative value. Unsigned uses the leading bit as a part of the value, while the signed version uses the left-most-bit to identify if the number is positive or negative. Signed integers can hold both positive and negative numbers.  Any other differences? How to prevent page breaking for lstinputlistings? The movie "Die Hard" or The "Die Hard" Movie? Sometime like this case I don't know if I can put the name before or after the label (movie in this sentence)...  The movie &quot;Die Hard&quot; or The &quot;Die Hard&quot; Movie? The variable &quot;X&quot; or The &quot;X&quot; variable?  Are they both correct? What is their difference? What is the application of each? My question is not about &quot;the&quot; (), but the order of the &quot;movie&quot; and &quot;Die Hard&quot; Traverse a list in reverse order in Python So I can start from len(collection) and end in collection[0].  I also want to be able to access the loop index. I'm currently a Combinatorics student trying to parse through this solution. I do not understand the proof currently. Any help understanding it is greatly appreciated.    Question Let the number of partitions be given by the function $p(n)$, i.e. the number of ways of writing the integer $n$ as a sum of positive integers. Prove that that if $g$ is any polynomial function in $n$, then there exists an integer $N$ such that $g(n)&lt;p(n)$ for all $n&gt;N$. Do not use the asymptotic Hardy-Ramanujan formula.    Provided Proof.    Enough to show $n^a&lt;p(n)$ for fixed positive integer $a$. (This is just saying that we want to show $p(n)$ grows faster than any degree polynomial of $n$, right?) We have that $(i_1,i_2,\ldots,i_{a+1},1^{n-i_1-\cdots -i_{a+1}})$ is a partition of $n$ as long as $i_{a+1}\leq i_a\leq \cdots i_1 \leq \lfloor\frac{n}{a+1}\rfloor$. (I really don't understand this step. What is this partition? Of the coefficients or terms of polynomial $p(n)$? And how do we know this is $\leq \lfloor\frac{n}{a+1}\rfloor$?) The number of partitions $n$ of this form is multiset binomial coefficient $$\left(\dbinom{\lfloor \frac{n}{a+1}\rfloor}{a+1}\right)=\frac{\lfloor\frac{n}{a+1}\rfloor(\lfloor\frac{n}{a+1}\rfloor+1)\cdots(\lfloor\frac{n}{a+1}\rfloor+a-1)}{(a+1)!}$$ (I'm assuming that if I can understand (2.) then I can understand this line) This means $p(n)&gt;\left(\binom{\lfloor \frac{n}{a+1}\rfloor}{a+1}\right)$ for all $n&gt;0$. Since $a$ is constant, the given fraction grows with order $n^{a+1}$, which means $p(n)&gt;n^a$ for $n$ sufficiently large. (Why does it grow with order $n^{a+1}$?)   Thanks all again in advance! How can I randomize order of elements in a list? Show that $d_b(x,y)=\frac{d(x,y)}{1+d(x,y)}$ is a metric. where $(X,d)$ is a metric and $x,y \in X$.  I know we need to show:   non-negativity: $d(x,y)\geq$ 0 $d(x,y)=0$ if and only if $x=y$ symmetry: $d(x,y)=d(y,x)$ $d(x,z)\leq d(x,y) + d(y,z)$   I think we need to consider the derivative of $f(t)=\frac{t}{1+t}$ however I am not sure what to do next. How do I prompt for Yes/No/Cancel input in a Linux shell script? I want to pause input in a shell script, and prompt the user for choices. The standard Yes, No, or Cancel type question. How do I accomplish this in a typical bash prompt? Books to learn physics, being a math major I've a Skype interview for PhD application (it will make me miss  today.) I've been asked, in advance, to prepare a short presentation and then there would be some discussion with the panel (I guess.) I expect that they will ask if I have some questions so, I'm wondering what are the best (type of) questions one might consider?