Skip to content

Latest commit

 

History

History
66 lines (50 loc) · 1.22 KB

File metadata and controls

66 lines (50 loc) · 1.22 KB

end

  • ranges[meta header]
  • std::ranges[meta namespace]
  • to_input_view[meta class]
  • function[meta id-type]
  • cpp26[meta cpp]
constexpr auto end()
  requires (!simple-view<V>); // (1) C++26

constexpr auto end() const
  requires range<const V>;    // (2) C++26

概要

番兵を取得する。

効果

以下と等価:

return ranges::end(base_);

備考

  • to_input_viewcommon_rangeコンセプトを満たさないため、イテレータ型と番兵型は異なる型となる

#include <ranges>
#include <vector>
#include <iostream>

int main() {
  std::vector<int> v = {1, 2, 3, 4, 5};
  
  std::ranges::to_input_view view{v};
  
  auto it = view.begin();
  auto sentinel = view.end();
  static_assert(!std::same_as<decltype(it), decltype(sentinel)>);
  
  int count = 0;
  for (; it != sentinel; ++it) {
    ++count;
  }
  
  std::cout << "size: " << count << std::endl;
}

出力

size: 5

バージョン

言語

  • C++26

処理系

  • Clang: 21 [mark verified]
  • GCC: 15.1 [mark verified]
  • Visual C++: 2022 Update 14 [mark noimpl]