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

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

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

履歴 編集

class template
<ranges>

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

namespace std::ranges {

  template<forward_range V, forward_range Pattern>
    requires view<V> && view<Pattern> &&
             indirectly_comparable<iterator_t<V>, iterator_t<Pattern>, ranges::equal_to>
  class split_view : public view_interface<split_view<V, Pattern>> { …… };   // (1)

  namespace views {
    inline constexpr /*unspecified*/ split = /*unspecified*/;                // (2)
  }
}

概要

指定した区切り文字(デリミタ)によって、入力文字範囲の分割を行うRangeアダプタ。

  • (1): 入力の文字範囲を、その要素型の文字または文字列からなるパターンをデリミタとして分割し、切り出した文字列(部分Range)を要素とする新たなRangeに変換するview
  • (2): split_viewを生成するRangeアダプタオブジェクト

入力範囲VもデリミタPatternも共にforward_range(かつview)であることしか求められていないため、実際には文字列の分割に限らず、任意のforward_rangeをforward_rangeによって表現されるパターンによって分割することができる。

Rangeコンセプト(split_viewそのもの)

borrowed sized output input forward bidirectional random_access contiguous common viewable view
○ ○ (1) ○ ○
  • (1): Vがcommon_rangeのとき

Rangeコンセプト (split_viewの要素である、切り出した部分文字列を示す各部分Range)

borrowed sized output input forward bidirectional random_access contiguous common viewable view
○ ※ ※ ○ ○ ※ ※ ※ ※ ○ ○
  • ※: Vに従う

テンプレートパラメータ制約

  • V、Patternがviewかつforward_range
  • VのイテレータとPatternのイテレータが等値比較可能である

効果

  • (2): 式views::split(E, F)の効果はsplit_view(E, F)と等しい。

メンバ関数

名前 説明 対応バージョン
(constructor) コンストラクタ C++20
base Vの参照を取得する C++20
begin 先頭を指すイテレータを取得する C++20
end 番兵を取得する C++20

継承しているメンバ関数

名前 説明 対応バージョン
empty Rangeが空かどうかを判定する C++20
operator bool Rangeが空でないかどうかを判定する C++20
front 先頭要素への参照を取得する C++20
cbegin 定数イテレータを取得する C++23
cend 定数イテレータ(番兵)を取得する C++23

推論補助

名前 説明 対応バージョン
(deduction_guide) クラステンプレートの推論補助 C++20

例

#include <ranges>
#include <string_view>
#include <iostream>

int main() {
  using namespace std;
  using namespace std::literals;

  for (auto sv : "hello, world"sv | views::split(", "sv)) {
    std::cout << string_view{sv.begin(), sv.end()} << '\n';
  }
}

パターンとしてC文字列を使うとき、ヌル文字を特別扱いしないため注意。

出力

hello
world

バージョン

言語

  • C++20

処理系

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

参照

  • P2210R2 Superior String Splitting
  • N4861 24 Ranges library
  • C++20 ranges
  • P2367R0 Remove misuses of list-initialization from Clause 24 (本提案文書はC++20に遡って適用されている)
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.