Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::views::istream,std::ranges::basic_istream_view,std::ranges::istream_view,std::ranges::wistream_view

      From cppreference.com
      <cpp‎ |ranges
       
       
      Ranges library
      Range adaptors
       
       
      Defined in header<ranges>
      template<std::movable Val,class CharT,

               class Traits=std::char_traits<CharT>>
          requiresstd::default_initializable<Val>&&
                   /*stream-extractable*/<Val, CharT, Traits>
      class basic_istream_view

         :publicranges::view_interface<basic_istream_view<Val, CharT, Traits>>
      (1)(since C++20)
      Helper templates
      template<class Val>
      using istream_view= ranges::basic_istream_view<Val,char>;
      (2)(since C++20)
      template<class Val>
      using wistream_view= ranges::basic_istream_view<Val,wchar_t>;
      (3)(since C++20)
      Customization point objects
      namespace views{

         template<class T>
         constexpr/* unspecified */ istream=/* unspecified */;

      }
      (4)(since C++20)
      Helper concepts
      template<class Val,class CharT,class Traits>

      concept/*stream-extractable*/=
          requires(std::basic_istream<CharT, Traits>& is, Val& t){
              is>> t;

         };
      (5)(exposition only*)
      1) A range factory that generates a sequence of elements by repeatedly callingoperator>>.
      2,3) Convenience alias templates for character typeschar andwchar_t.
      4)views::istream<T>(e) isexpression-equivalent toranges::basic_istream_view<T,typename U::char_type,typename U::traits_type>(e) for any suitable subexpressionse, whereU isstd::remove_reference_t<decltype(e)>.
      The program is ill-formed ifU is not both publicly and unambiguously derived fromstd::basic_istream<typename U::char_type,typename U::traits_type>, which may result in asubstitution failure.
      5) The exposition-only concept/*stream-extractable*/<Val, CharT, Traits> is satisfied when lvalue of typeVal can be extracted from lvalue of typestd::basic_istream<CharT, Traits>.

      The iterator type ofbasic_istream_view is move-only: it does not meet theLegacyIterator requirements, and thus does not work with pre-C++20algorithms.

      Contents

      Customization point objects

      The nameviews::istream<T> denotes acustomization point object, which is a constfunction object of aliteralsemiregular class type. SeeCustomizationPointObject for details.

      [edit]Data members

      Member Definition
      std::basic_istream<CharT, Traits>*stream_ a pointer to the input stream
      (exposition-only member object*)
      Valvalue_ the stored value
      (exposition-only member object*)

      [edit]Member functions

      constructs abasic_istream_view
      (public member function)
      returns an iterator
      (public member function)
      returnsstd::default_sentinel
      (public member function)
      Inherited fromstd::ranges::view_interface
      (C++23)
      returns a constant iterator to the beginning of the range
      (public member function ofstd::ranges::view_interface<D>)[edit]
      (C++23)
      returns a sentinel for the constant iterator of the range
      (public member function ofstd::ranges::view_interface<D>)[edit]

      Althoughbasic_istream_view is derived fromstd::ranges::view_interface, it cannot use any of inherited member functions.

      (until C++23)

      std::ranges::basic_istream_view::basic_istream_view

      constexprexplicit
          basic_istream_view(std::basic_istream<CharT, Traits>& stream);
      (since C++20)

      Initializesstream_ withstd::addressof(stream), and value-initializesvalue_ .

      std::ranges::basic_istream_view::begin

      constexprauto begin();
      (since C++20)

      Equivalent to*stream_ >> value_ ;return iterator {*this};.

      std::ranges::basic_istream_view::end

      constexprstd::default_sentinel_t end()constnoexcept;
      (since C++20)

      Returnsstd::default_sentinel.

      [edit]Nested classes

      the iterator type ofbasic_istream_view
      (exposition-only member class*)

      [edit]Example

      Run this code
      #include <algorithm>#include <iomanip>#include <iostream>#include <iterator>#include <ranges>#include <sstream>#include <string> int main(){auto words=std::istringstream{"today is yesterday’s tomorrow"};for(constauto& s: std::views::istream<std::string>(words))std::cout<<std::quoted(s,'/')<<' ';std::cout<<'\n'; auto floats=std::istringstream{"1.1  2.2\t3.3\v4.4\f55\n66\r7.7  8.8"};    std::ranges::copy(        std::views::istream<float>(floats),std::ostream_iterator<float>{std::cout,", "});std::cout<<'\n';}

      Output:

      /today/ /is/ /yesterday’s/ /tomorrow/1.1, 2.2, 3.3, 4.4, 55, 66, 7.7, 8.8,

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3568C++20P2325R3 accidentally made the stored value default-initializedrestored to value-initialization
      P2325R3C++20default constructor was provided as
      view must bedefault_initializable
      removed along with
      the requirement
      P2432R1C++20ranges::istream_view was a function template
      and did not follow the naming convention
      made an alias template;
      customization point objects added

      [edit]See also

      input iterator that reads fromstd::basic_istream
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/basic_istream_view&oldid=176950"

      [8]ページ先頭

      ©2009-2025 Movatter.jp