Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::optional<T>::end

      From cppreference.com
      <cpp‎ |utility‎ |optional
       
       
      Utilities library
       
       
      constexpr iterator end()noexcept;
      (since C++26)
      constexpr const_iterator end()constnoexcept;
      (since C++26)

      Returns a past-the-end iterator. Equivalent toreturn begin()+ has_value();.

      range-begin-end.svg

      Contents

      [edit]Return value

      Past-the-end iterator

      [edit]Complexity

      Constant.

      [edit]Notes

      Feature-test macroValueStdFeature
      __cpp_lib_optional_range_support202406L(C++26)Range support forstd::optional

      [edit]Example

      Run this code
      #include <optional>#include <print> int main(){constexprstd::optional<int> none{std::nullopt};// optional @1constexprstd::optional<int> some{42};// optional @2     static_assert(none.begin()== none.end());    static_assert(some.begin()!= some.end()); // ranged-for loop supportfor(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);}

      Output:

      Optional @2 has a value of 42

      [edit]See also

      (C++26)
      returns an iterator to the beginning
      (public member function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/utility/optional/end&oldid=182156"

      [8]ページ先頭

      ©2009-2025 Movatter.jp