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

  1. リファレンス
  2. iterator
  3. basic_const_iterator
  4. common_type

最終更新日時: 2026年08月18日 11時14分29秒 (JST)
Akira Takahashi が更新

履歴 編集

class template
<iterator>

std::common_type(C++23)

namespace std {
  // (1)
  template<class T, common_with<T> U>
    requires input_iterator<common_type_t<T, U>>
  struct common_type<basic_const_iterator<T>, U> {
    using type = basic_const_iterator<common_type_t<T, U>>;
  };

  // (2)
  template<class T, common_with<T> U>
    requires input_iterator<common_type_t<T, U>>
  struct common_type<U, basic_const_iterator<T>> {
    using type = basic_const_iterator<common_type_t<T, U>>;
  };

  // (3)
  template<class T, common_with<T> U>
    requires input_iterator<common_type_t<T, U>>
  struct common_type<basic_const_iterator<T>, basic_const_iterator<U>> {
    using type = basic_const_iterator<common_type_t<T, U>>;
  };
}

概要

basic_const_iteratorのためのcommon_type特殊化。

  • (1), (2) : basic_const_iteratorとその他のイテレータ型の間の共通の型を取得する
  • (3) : 異なるイテレータ型によるbasic_const_iterator特殊化の間の共通の型を取得する

例

#include <iterator>

int main() {
  using ct1 = std::common_type_t<int*, std::const_iterator<int*>>;

  static_assert(std::same_as<ct1, std::basic_const_iterator<int*>>);

  using ct2 = std::common_type_t<std::const_iterator<int*>, int*>;

  static_assert(std::same_as<ct1, ct2>);

  using ct3 = std::common_type_t<const int*, std::const_iterator<int*>>;

  static_assert(std::same_as<ct3, std::basic_const_iterator<const int*>>);

  using ct4 = std::common_type_t<std::basic_const_iterator<int*>, std::basic_const_iterator<const int*>>;

  static_assert(std::same_as<ct4, std::basic_const_iterator<const int*>>);
}

出力

バージョン

言語

  • C++23

処理系

  • Clang: ??
  • GCC: 13.1 ✅
  • Visual C++: 2022 Update 6 ✅

関連項目

  • common_type

参照

  • P2278R4 cbegin should always return a constant iterator
  • LWG Issue 3862. basic_const_iterator's common_type specialization is underconstrained
    • C++23で、3つのcommon_type特殊化にcommon_type_t<T, U>がinput_iteratorであることの制約が追加された
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.