最終更新日時(UTC):
が更新

履歴 編集

function
<ranges>

std::ranges::elements_view::end(C++20)

constexpr auto end()
  requires (!simple-view<V> && !common_range<V>);                       // (1) C++20

constexpr auto end()
  requires (!simple-view<V> && common_range<V>);                        // (2) C++20

constexpr auto end() const
  requires range<const V>;                                              // (3) C++20

constexpr auto end() const
  requires common_range<const V>;                                       // (4) C++20

概要

番兵を取得する。

効果

  • (1) : return sentinel<false>{ranges::end(base_)};
  • (2) : return iterator<false>{ranges::end(base_)};
  • (3) : return sentinel<true>{ranges::end(base_)};
  • (4) : return iterator<true>{ranges::end(base_)};

ここで、sentinelelements_viewの内部で定義される説明専用の番兵クラスであり、iteratorは説明専用のイテレータクラスである。

#include <ranges>
#include <map>
#include <string>
#include <iostream>

int main() {
  std::map<int, std::string> m = {{1, "one"}, {2, "two"}, {3, "three"}};

  // keys_viewを使用
  std::ranges::keys_view kv(m);
  auto begin = kv.begin();
  auto end = kv.end();

  for (auto it = begin; it != end; ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;

  // values_viewを使用
  std::ranges::values_view vv(m);
  for (auto it = vv.begin(); it != vv.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

出力

1 2 3 
one two three 

バージョン

言語

  • C++20

処理系

参照