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::enable_view - cpprefjp C++日本語リファレンス

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

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

履歴 編集

variable
<ranges>

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

namespace std::ranges {
  template<class T>
  inline constexpr bool enable_view = derived_from<T, view_base> || is-derived-from-view-interface<T>;
}

概要

enable_view<T>がtrueであることは、Tがviewであるための必要条件である。

viewコンセプトの要件は意味論要件がメインなため、view_baseを基底クラスにするか、enable_viewを特殊化することで、明示的にviewであることを示すようになっている。

要件

  • cv修飾のないプログラム定義型に対して、この変数テンプレートを特殊化することが許可される。
    • そのような特殊化は定数式で使用可能であり、bool型を持つ必要がある。

is-derived-from-view-interface

is-derived-from-view-interface<T>は説明専用のbool型の変数テンプレートである。

namespace std::ranges {
  template<class T>
  inline constexpr bool is-derived-from-view-interface = see below; // 説明専用
}

is-derived-from-view-interface<T>は、Tがある型Uについてただ一つだけview_interface<U>をpublicな基底クラスに持ち、他の型Vについてのview_interface<V>を基底クラスに持たない場合にtrueとなる。

多くの場合U = Tであり、その場合Tはview_interface<T>をpublicで1つだけ継承していればこれを満たすことができる。継承関係が複雑な型などで、view_interfaceを複数継承階層の中に持っているとこれを満たすことができなくなる。

例

#include <ranges>

int main()
{
  using namespace std::ranges;
  static_assert(enable_view<view_base>);
  static_assert(!enable_view<int>);

  struct t : view_base { };

  static_assert(enable_view<t>);
}

出力

バージョン

言語

  • C++20

処理系

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

参照

  • N4861 24 Ranges library
  • C++20 ranges
  • LWG Issue 3549. view_interface is overspecified to derive from view_base
  • LWG Issue 3183. Normative permission to specialize Ranges variable templates
    • C++20で、プログラム定義型に対してこの変数テンプレートを特殊化してよいという規範的な許可が明記された
You are visitor 01402520 — 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.