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

  1. リファレンス
  2. algorithm
  3. in_value_result

最終更新日時: 2026年09月19日 21時31分51秒 (JST)
rotarymars が更新

履歴 編集

class template
<algorithm>

std::ranges::in_value_result(C++23)

namespace std::ranges {
  // (1)
  template<class I, class T>
  struct in_value_result {
    [[no_unique_address]] I in;
    [[no_unique_address]] T value;

    template<class I2, class T2>
      requires convertible_to<const I&, I2> &&
               convertible_to<const T&, T2>
    constexpr operator in_value_result<I2, T2>() const & {
      return {in, value};
    }

    template<class I2, class T2>
      requires convertible_to<I, I2> &&
               convertible_to<T, T2>
    constexpr operator in_value_result<I2, T2>() && {
      return {std::move(in), std::move(value)};
    }
  };

  // (2)
  template<class I, class T>
  using fold_left_with_iter_result = in_value_result<I, T>;

  // (3)
  template<class I, class T>
  using fold_left_first_with_iter_result = in_value_result<I, T>;   
}

概要

  • (1): イテレータと値を格納する型
  • (2): ranges::fold_left_with_iterで使用するエイリアス
  • (3): ranges::fold_left_first_with_iterで使用するエイリアス

この型は、関数が入力用に範囲を受け取る場合に、処理した範囲の末尾と、それとは別の出力を返すために使用される。

標準アルゴリズム関数ではこの型を直接返す代わりに、関数毎にエイリアスを定義している。

メンバ変数

名前 説明 対応バージョン
[[no_unique_address]] I in 読み込んだ範囲の終端位置 C++23
[[no_unique_address]] T value イテレータとは別の値 C++23

メンバ関数

名前 説明 対応バージョン
operator in_value_result<I2, T2> 変換演算子 C++23

変換演算子は、各テンプレートパラメーターが変換できる場合のみオーバーロード解決に参加する。

例

#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>

int main() {
  std::vector<int> v = {1, 2, 3, 4};

  // fold_left_with_iterはin_value_result(fold_left_with_iter_result)を返す
  const std::ranges::in_value_result result = std::ranges::fold_left_with_iter(v, 0, std::plus<>{});

  assert(result.in == v.end()); // 走査し終えた終端イテレータ
  assert(result.value == 10);   // 畳み込み結果
}

出力

バージョン

言語

  • C++23

処理系

  • Clang: 18.1.8 ✅
  • GCC: 13.1 ✅
  • Visual C++: 2022 Update 5 ✅

参照

  • P2322R6 ranges::fold
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.