std::deque<T,Allocator>::begin, std::deque<T,Allocator>::cbegin
提供: cppreference.com
iterator begin(); |
(C++11未満) | |
iterator begin() noexcept; |
(C++11以上) | |
const_iterator begin() const; |
(C++11未満) | |
const_iterator begin() const noexcept; |
(C++11以上) | |
const_iterator cbegin() const noexcept; |
(C++11以上) | |
コンテナの最初の要素を指すイテレータを返します。
コンテナが空の場合は、返されたイテレータは end() と等しくなります。
目次 |
[編集] 引数
(なし)
[編集] 戻り値
最初の要素を指すイテレータ。
[編集] 計算量
一定。
[編集] 例
Run this code
#include <iostream> #include <deque> #include <string> int main() { std::deque<int> ints {1, 2, 4, 8, 16}; std::deque<std::string> fruits {"orange", "apple", "raspberry"}; std::deque<char> empty; // Sums all integers in the deque ints (if any), printing only the result. int sum = 0; for (auto it = ints.cbegin(); it != ints.cend(); it++) sum += *it; std::cout << "Sum of ints: " << sum << "\n"; // Prints the first fruit in the deque fruits, without checking if there is one. std::cout << "First fruit: " << *fruits.begin() << "\n"; if (empty.begin() == empty.end()) std::cout << "deque 'empty' is indeed empty.\n"; }
出力:
Sum of ints: 31 First fruit: orange deque 'empty' is indeed empty.
[編集] 関連項目
終端を指すイテレータを返します (パブリックメンバ関数) |