GeezerVison is showing cpprefjp.github.io — std::unordered_set::begin - cpprefjp C++日本語リファレンス
最終更新日時:
2026年09月11日 13時06分31秒 (JST)
Akira Takahashi
が更新
履歴
編集
function
<unordered_set>
std:: unordered_set:: begin (C++11)
iterator begin () noexcept ; // (1) C++11
constexpr iterator begin () noexcept ; // (1) C++26
const_iterator begin () const noexcept ; // (2) C++11
constexpr const_iterator begin () const noexcept ; // (2) C++26
概要
先頭の要素を指すイテレータを取得する。
unordered_set は非順序連想コンテナであるため「先頭」に特に意味はないが、begin() で得られたイテレータを end () まで operator++() でイテレートすることで当該コンテナの要素を漏れなくダブりなく走査することができる。
戻り値
先頭の要素を指すイテレータ
例外
投げない
計算量
定数
備考
const 版ではない begin が返す iterator も読み取り専用イテレータである。
(が、iterator と const_iterator が同じ型とは限らない)
例
#include <iostream>
#include <algorithm>
#include <iterator>
#include <unordered_set>
int main ()
{
std::unordered_set < int > us { 1 , 2 , 3 , };
const std::unordered_set < int > cus { us };
std::copy ( us . begin() , us . end() , std::ostream_iterator < int > ( std::cout , ", " ));
std::cout << std::endl ;
std::copy ( cus . begin() , cus . end() , std::ostream_iterator < int > ( std::cout , ", " ));
std::cout << std::endl ;
}
出力例
3, 2, 1,
1, 2, 3,
注:unordered_set は非順序連想コンテナであるため、出力順序は無意味であることに注意
バージョン
言語
処理系
関連項目
参照