std::optional<T>:: end
From cppreference.net
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::optional
| Member functions | ||||
| Observers | ||||
| Iterators | ||||
|
(C++26)
|
||||
|
optional::end
(C++26)
|
||||
| Monadic operations | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
| Modifiers | ||||
| Non-member functions | ||||
| Deduction guides | ||||
| Helper classes | ||||
| Helper objects | ||||
|
constexpr
iterator end
(
)
noexcept
;
|
(C++26以降) | |
|
constexpr
const_iterator end
(
)
const
noexcept
;
|
(C++26以降) | |
終端イテレータを返します。次と等価です: return begin ( ) + has_value ( ) ; 。
目次 |
戻り値
末尾イテレータの次
計算量
定数。
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_optional_range_support
|
202406L
|
(C++26) | std::optional の範囲サポート |
例
このコードを実行
#include <optional> #include <print> int main() { constexpr std::optional<int> none{std::nullopt}; // optional @1 constexpr std::optional<int> some{42}; // optional @2 static_assert(none.begin() == none.end()); static_assert(some.begin() != some.end()); // 範囲ベースforループのサポート for (int i : none) std::println("Optional @1 has a value of {}", i); for (int i : some) std::println("Optional @2 has a value of {}", i); }
出力:
Optional @2 has a value of 42
関連項目
|
(C++26)
|
先頭を指すイテレータを返す
(公開メンバ関数) |