Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::split_view<V,Pattern>::begin

      From cppreference.com
      <cpp‎ |ranges‎ |split view
       
       
      Ranges library
      Range adaptors
       
       
      constexpr/*iterator*/ begin();
      (since C++20)

      Returns aniterator to the first found subrange.

      In order to provide the amortized constant time complexity required by therange concept, this function caches the result within thesplit_view (by means ofcached_begin_ member) for use on subsequent calls.

      Letbase_ be the underlying data member. Equivalent to:

      constexpr/*iterator*/ begin(){if(!cached_begin_.has_value())        cached_begin_= this->find_next(ranges::begin(base_));return{*this,ranges::begin(base_), cached_begin_.value()};}

      Contents

      [edit]Return value

      Aniterator.

      [edit]Complexity

      Amortized\(\scriptsize \mathcal{O}(1)\)O(1).

      [edit]Example

      Run this code
      #include <iomanip>#include <iostream>#include <ranges>#include <string_view> int main(){constexprstd::string_view sentence{"Keep..moving..forward.."};constexprstd::string_view delim{".."};    std::ranges::split_view words{sentence, delim}; std::cout<<"begin(): "<<std::quoted(std::string_view{*words.begin()})<<"\nSubstrings: ";for(auto word: words)std::cout<<std::quoted(std::string_view(word))<<' ';     std::ranges::split_view letters{sentence,std::string_view{""}};std::cout<<"\nbegin(): "<<std::quoted(std::string_view{*letters.begin()})<<"\nLetters: ";for(auto letter: letters)std::cout<<std::string_view(letter)<<' ';std::cout<<'\n';}

      Output:

      begin(): "Keep"Substrings: "Keep" "moving" "forward" ""begin(): "K"Letters: K e e p . . m o v i n g . . f o r w a r d . .

      [edit]See also

      returns an iterator or a sentinel to the end
      (public member function)[edit]
      returns an iterator to the beginning
      (public member function ofstd::ranges::lazy_split_view<V,Pattern>)[edit]
      returns an iterator to the beginning of a range
      (customization point object)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/split_view/begin&oldid=179886"

      [8]ページ先頭

      ©2009-2025 Movatter.jp