c++ - Skip first iteration over unordered_map -


in for loop auto, iterator iterates on unordered_map. this:

using ruleindex = std::unordered_map<uint, symbol*>; ruleindex rule_index; for(const auto & rule_pair : rule_index ) {    std::cout << rule_pair.first << ": ";    printlist(rule_pair.second, 0);    std::cout << std::endl; } 

assume variables defined properly, since code works fine. question, how can exclude first iteration? example, map contains 3 rows , current loop iterates 0, 1, 2. want iterate on 1 , 2 only.

bool is_first_iteration = true; for(const auto & rule_pair : rule_index) {    if (std::exchange(is_first_iteration, false)) continue;    std::cout << rule_pair.first << ": ";    printlist(rule_pair.second, 0);    std::cout << std::endl; } 

the std::exchange call assigns false is_first_iteration , returns previous value. 1 of use cases discussed in the paper proposing std::exchange c++14. paper shows reference implementation can use if stuck c++11.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -