Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::end(std::valarray)

      From cppreference.com
      <cpp‎ |numeric‎ |valarray
       
       
       
      std::valarray
      Member functions
      Non-member functions
      Helper classes
      Deduction guides(C++17)
       
      template<class T>
      /* see below */ end( valarray<T>& v);
      (1)(since C++11)
      template<class T>
      /* see below */ end(const valarray<T>& v);
      (2)(since C++11)

      The overload ofstd::end forvalarray returns an iterator of unspecified type referring to the one past the last element in the numeric array.

      1) The return type must
      (since C++20)
      • have a member typevalue_type, which isT, and
      • have a member typereference, which isT&.
      2) The return type must
      (since C++20)
      • have a member typevalue_type, which isT, and
      • have a member typereference, which isconst T&.

      The iterator returned from this function is invalidated when the member functionresize() is called onv or when the lifetime ofv ends, whichever comes first.

      Contents

      [edit]Parameters

      v - a numeric array

      [edit]Return value

      Iterator to one past the last value in the numeric array.

      [edit]Exceptions

      May throw implementation-defined exceptions.

      [edit]Notes

      Unlike other functions that takestd::valarray arguments,end() cannot accept the replacement types (such as the types produced by expression templates) that may be returned from expressions involving valarrays:std::end(v1+ v2) is not portable,std::end(std::valarray<T>(v1+ v2)) has to be used instead.

      The intent of this function is to allowrange for loops to work with valarrays, not to provide container semantics.

      [edit]Example

      Run this code
      #include <algorithm>#include <iostream>#include <valarray> int main(){conststd::valarray<char> va{'H','e','l','l','o',',',' ','C','+','+','!','\n'}; std::for_each(std::begin(va),std::end(va),[](char c){std::cout<< c;});}

      Output:

      Hello, C++!

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2058C++111.end() was required to support replacement types
      2. it was unspecified when the returned iterators will be invalidated
      1. not required
      2. specified

      [edit]See also

      overloadsstd::begin
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/valarray/end2&oldid=156909"

      [8]ページ先頭

      ©2009-2025 Movatter.jp