Created
July 16, 2015 05:10
-
-
Save takashi1975/25f31b8fadde167a7762 to your computer and use it in GitHub Desktop.
C++ イテレーター 添字の値を取得するには ... std::distance を使用
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //TEST [3] を見つけることを期待 | |
| std::vector<bool> array = {false, false, false, true, false}; | |
| for (std::vector<bool>::iterator it = array.begin(); it != array.end(); it++) | |
| { | |
| if ((*it) == true) | |
| { | |
| auto index = std::distance(array.begin(), it); | |
| CCLOG("%s iterator:%d", __PRETTY_FUNCTION__, index); | |
| break; | |
| } | |
| } | |
| for (std::vector<bool>::reverse_iterator it = array.rbegin(); it != array.rend(); it++) | |
| { | |
| if ((*it) == true) | |
| { | |
| //配列の先頭からの添字 | |
| auto index = std::distance(it, array.rend()) - 1; | |
| auto last = std::distance(array.rbegin(), it); | |
| CCLOG("%s reverse_iterator test:%d, last:%d", __PRETTY_FUNCTION__, index, last); | |
| break; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
出力結果
cocos2d: iterator test:3
cocos2d: reverse_iterator test:3, last:1