Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::ranges::view_interface<D>::empty

      From cppreference.com
      <cpp‎ |ranges‎ |view interface
       
       
      Ranges library
      Range adaptors
       
       
      constexprbool empty()
          requiresranges::sized_range<D>||ranges::forward_range<D>;
      (1)(since C++20)
      constexprbool empty()const
          requiresranges::sized_range<const D>||ranges::forward_range<const D>;
      (2)(since C++20)

      The default implementation ofempty() member function checks whether the object of the derived type's size is0 (if valid), or whether the beginning iterator and the sentinel compare equal.

      1) Letderived be a reference bound tostatic_cast<D&>(*this). Equivalent toreturnranges::size(derived)==0; ifD satisfiessized_range. Otherwise, equivalent toreturnranges::begin(derived)==ranges::end(derived);.
      2) Same as(1), except thatderived isstatic_cast<const D&>(*this).

      Contents

      [edit]Return value

      true if the size of the object of the derived type is0 (ifD satisfiesstd::ranges::sized_range), or its beginning iterator and the sentinel compare equal,false otherwise.

      [edit]Notes

      Following derived types may use the default implementation ofempty:

      (since C++23)
      (since C++26)

      Althoughstd::ranges::basic_istream_view inherits fromstd::ranges::view_interface and does not declare theempty() member function, it cannot use the default implementation, because it never satisfies neitherstd::ranges::sized_range norstd::ranges::forward_range.

      [edit]Example

      Run this code
      #include <array>#include <ranges> int main(){constexprstd::array a{0,1,2,3,4};    static_assert(!std::ranges::single_view(a).empty());    static_assert((a| std::views::take(0)).empty());    static_assert(!(a| std::views::take(5)).empty());    static_assert((a| std::views::drop(5)).empty());    static_assert(!(a| std::views::drop(3)).empty());    static_assert(std::views::iota(0,0).empty());    static_assert(!std::views::iota(0).empty());}

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3715C++20empty() only supportedforward_range typessized_range-only types are also supported

      [edit]See also

      (C++17)
      checks whether the container is empty
      (function template)[edit]
      checks whether a range is empty
      (customization point object)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/ranges/view_interface/empty&oldid=182216"

      [8]ページ先頭

      ©2009-2025 Movatter.jp