Diferente pentru blog/cpp11 intre reviziile #45 si #52

Nu exista diferente intre titluri.

Diferente intre continut:

auto c = vector<int>(10);
==
$auto$ can also be used with $const auto$ or $const auto&$. It works in the same way other types would work. In most cases, $auto$ cannot be used in function signatures.
$auto$ can also be used with $const auto$ or $const auto&$. In most cases, $auto$ cannot be used in function signatures.
h3. 2. range-based for loops
In $C++11$, you can iterate over each element in a list with less code:
In $C++11$, you can write less code to iterate over every element in a list of elements:
== code(cpp) |
int array[5] = {1, 2, 3, 4, 5};
}
==
If you want to modify the elements in the list, you need to get a reference to the current element like this:
If you want to modify the elements in the list, you need to get a reference to the current element:
== code(cpp) |
double array[5] = {1.5, 2.7, 3.9};
vector<pair<int, int>> dirs = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
==
Note that since $C++11$ you no longer need to introduce a space between closing right angle brackets $(>>)$.
Note that in $C++11$ you no longer need to introduce a space between closing right angle brackets $(>>)$.
h3. 4. unordered_set, unordered_map
cout << "Anna is " << age["anna"] << " years old." << endl;
==
Using STL vectors, pairs or user defined objects as keys is a little trickier because you also need to provide the hash function.
Using STL vectors, pairs or user defined objects as keys is a little trickier because you also need to provide a hash function.
== code(cpp) |
#include <unordered_set>
(Often, a cleaner alternative to using lambda functions for sorting is to define a class holding all the data for each entry and to implement the $<$ operator.)
_Please let us know in the comments section what other $C++11$ features do you use for programming contests. Code snippets illustrating your favorite tricks would be beneficial for us all._
_Let us know in the comments section what are the $C++11$ features that you use for programming contests. Code snippets illustrating your favorite tricks are welcome._

Diferente intre securitate:

private
protected

Diferente intre topic forum:

 
8918