Skip to content

Instantly share code, notes, and snippets.

@minjang
Created December 23, 2015 16:36
Show Gist options
  • Save minjang/d248e1d489c064c20c44 to your computer and use it in GitHub Desktop.
Save minjang/d248e1d489c064c20c44 to your computer and use it in GitHub Desktop.
Python's enumerate implementation in C++
// 2. 일반 배열 예
cout << "[TEST 2] array\n";
string C[] = {"foo", "bar", "baz"};
// auto&&로 받는 것이 범위 기반 for 문에서 일반적이고 효율적인 방법
// p 타입: pair<size_t, string&>&&, 원소 타입이 string&로 추론
for (auto &&p : enumerate(C, 100))
cout << p.first << ": " << (p.second += p.second) << '\n';
for (auto &&p : enumerate(C, 100))
cout << p.first << ": " << p.second << '\n';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment