040902fyn's blog

By 040902fyn, history, 5 years ago, In English

Some contests have allowed participants to use C++11/14, so I want to know some excellent features C++11/14 has. Pls give me some advice!Thanks!

  • Vote: I like it
  • -10
  • Vote: I do not like it

»
5 years ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

Iterate over a vector using auto:

std::vector<int> a = {1, 2, 3};
for (auto item : a)
    printf("%d\n", a);

or

for (auto it = a.begin(); it != a.end(); ++it)
    printf("%d\n", *it);
  • »
    »
    5 years ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    Not only the vector, set/map/unordered_set/unordered_map/multiset/... can also be used in this way.

»
5 years ago, hide # |
Rev. 3  
Vote: I like it +11 Vote: I do not like it

And the optimize of loops:

Example

Lambda also became available:

Example

As I don't use these features much, if you find mistakes in my code, please comment me.

»
5 years ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Auto comment: topic has been updated by 040902fyn (previous revision, new revision, compare).