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
// 5. 변수를 거치지 않고 직접 사용 | |
cout << "[TEST 5] in-place through rvalue reference\n"; | |
for (auto &&p : enumerate(range(100, 103))) | |
cout << p.first << ": " << p.second << '\n'; | |
// decltype(p) == pair<size_t, string&>&& | |
for (auto &&p : enumerate(vector<string>{"foo", "bar", "baz"})) | |
cout << p.first << ": " << (p.second += p.second) << '\n'; | |
// 함수 반환값 바로 사용 |
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
// 3. const 예제 | |
cout << "[TEST 3] const\n"; | |
const string E[] = {"foo", "bar", "baz"}; | |
// decltype(p) == pair<size_t, string const&>&& | |
// p 자체는 상수가 아니므로 인덱스 값은 변경 가능, 배열 값은 수정 불가. | |
for (auto &&p : enumerate(E)) | |
cout << (p.first += 1) << ": " << p.second << '\n'; |
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
// 1. Forward iterator를 얻을 수 있는 STL 컨테이너 | |
cout << "[TEST 1] vector<string>\n"; | |
vector<string> A = {"foo", "bar", "baz"}; | |
// 참조자로 직접 A 내용 수정. | |
for (pair<size_t, string&> p : enumerate(A)) | |
cout << p.first << ": " << (p.second += p.second) << '\n'; | |
// 수정 내역 확인: 벡터 원소를 상수 참조자로 받음. | |
for (pair<size_t, const string&> p : enumerate(A)) | |
cout << p.first << ": " << p.second << '\n'; |
NewerOlder