名前空間
変種
操作

std::multiset<Key,Compare,Allocator>::begin, std::multiset<Key,Compare,Allocator>::cbegin

提供: cppreference.com
< cpp‎ | container‎ | multiset
 
 
 
 
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() と等しくなります。

range-begin-end.svg

目次

[編集] 引数

(なし)

[編集] 戻り値

最初の要素を指すイテレータ。

[編集] 計算量

一定。

[編集] ノート

iteratorconst_iterator はどちらも定数イテレータである (実際には同じ型かもしれない) ため、これらのメンバ関数のいずれによって返されたイテレータを通してもコンテナの要素を変更することはできません。

[編集]

#include <iostream>
#include <iterator>
#include <set>
#include <string>
 
int main()
{
    const std::multiset<std::string> words = {
        "some", "not", "sorted", "words",
        "will", "come", "out", "sorted",
    };
 
    for (auto it = words.begin(); it != words.end(); ) {
        auto cnt = words.count(*it);
        std::cout << *it << ":\t" << cnt << '\n';
        std::advance(it, cnt); // all cnt elements have equivalent keys
    }
}

出力例:

come:	1
not:	1
out:	1
some:	1
sorted:	2
will:	1
words:	1

[編集] 関連項目

終端を指すイテレータを返します
(パブリックメンバ関数) [edit]