GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::ranges::common_range - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. ranges
  3. common_range

最終更新日時: 2026年09月11日 13時06分31秒 (JST)
Akira Takahashi が更新

履歴 編集

concept
<ranges>

std::ranges::common_range(C++20)

namespace std::ranges {
  template<class T>
  concept common_range = range<T> && same_as<iterator_t<T>, sentinel_t<T>>;
}

概要

common_rangeは、イテレータと番兵の型が等しいRangeを表すコンセプトである。

標準のコンテナはすべてcommon_rangeのモデルである。

モデル

型Tがcommon_rangeのモデルとなるのは、Tがrangeのモデルであり、Tから取得した番兵とイテレータの型が等しい場合である。

例

#include <ranges>

int main() {
  namespace ranges = std::ranges;
  namespace views = std::views;

  // 無限長のiotaはcommon_rangeではない
  // (イテレータと番兵の型が異なる)
  static_assert(!ranges::common_range<decltype(views::iota(0))>);

  // commonを適用するとcommon_rangeになる
  static_assert(ranges::common_range<decltype(views::iota(0) | views::common)>);
}

出力

バージョン

言語

  • C++20

処理系

  • Clang: 13.0.0 ✅
  • GCC: 10.1.0 ✅
  • Visual C++: 2019 Update 10 ✅

関連項目

  • C++17 範囲 for ループの制限緩和
    範囲for文は、C++17の時点で先行してcommon_rangeではない範囲を扱えるようになっている
  • views::common
    任意の範囲をcommon_rangeに変換するRangeアダプタオブジェクト

参照

  • N4861 24 Ranges library
  • C++20 ranges
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.