Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ポインタはイテレータでもある #58

Open
yumetodo opened this issue Nov 24, 2020 · 1 comment
Open

ポインタはイテレータでもある #58

yumetodo opened this issue Nov 24, 2020 · 1 comment

Comments

@yumetodo
Copy link
Contributor

https://rinatz.github.io/cpp-book/ch03-08-iterators/

ポインタはイテレータでもある。実際、std::initializer_listのbegin/end`はポインタを返す。

イテレータを使用できるコンテナにC形式の配列がないのも気になる。そのためのstd::begin()/std::end()であるはず

@yohhoy
Copy link

yohhoy commented Nov 26, 2020

FYI: C++仕様上は「イテレータ == ポインタの一般化」として説明されています。[iterator.requirements.general]/1

Iterators are a generalization of pointers that allow a C++ program to work with different data structures (containers) in a uniform manner. To be able to construct template algorithms that work correctly and efficiently on different types of data structures, the library formalizes not just the interfaces but also the semantics and complexity assumptions of iterators.

配列というデータ構造はポインタを介して要素操作を行うという関係性を一般化し、双方向リスト(list)や可変長配列(vector)など任意のコンテナ・データ構造はイテレータを介して要素操作を行うという解釈になります。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants