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

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

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

履歴 編集

function template
<algorithm>

std::all_of(C++11)

namespace std {
  template <class InputIterator, class Predicate>
  bool all_of(InputIterator first,
              InputIterator last,
              Predicate pred);               // (1) C++11

  template <class InputIterator, class Predicate>
  constexpr bool all_of(InputIterator first,
                        InputIterator last,
                        Predicate pred);     // (1) C++20

  template <class ExecutionPolicy, class ForwardIterator, class Predicate>
  bool all_of(ExecutionPolicy&& exec,
              ForwardIterator first,
              ForwardIterator last,
              Predicate pred);               // (2) C++17
}

概要

イテレータ範囲[first, last)の全ての要素が条件を満たすかを判定する。

戻り値

[first,last) が空であったり、[first,last) 内の全てのイテレータ i について pred(*i) が true である場合は true を返し、そうでない場合は false を返す。

計算量

最大で last - first 回 pred を実行する。

例

#include <algorithm>
#include <iostream>
#include <vector>

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

  std::cout << std::boolalpha;

  // 全ての要素が 5 より小さいか
  bool result1 = std::all_of(v.begin(), v.end(), [](int x) { return x < 5; });
  std::cout << result1 << std::endl;

  // 全ての要素が 1 であるか
  bool result2 = std::all_of(v.begin(), v.end(), [](int x) { return x == 1; });
  std::cout << result2 << std::endl;
}

出力

true
false

実装例

template <class InputIterator, class Predicate>
bool all_of(InputIterator first, InputIterator last, Predicate pred) {
  for ( ; first != last; ++first)
    if (!bool(pred(*first))) return false;
  return true;
}

バージョン

言語

  • C++11

処理系

  • Clang: 3.0 ✅
  • GCC: 4.4.7 ✅
  • Visual C++: 2010 ✅, 2012 ✅, 2013 ✅, 2015 ✅

関連項目

  • any_of
  • none_of
  • ranges::all_of

参照

  • N2569 More STL algorithms
  • N2666 More STL algorithms (revision 2)
  • P0202R3 Add Constexpr Modifiers to Functions in <algorithm> and <utility> Headers
  • P0467R2 Iterator Concerns for Parallel Algorithms
  • LWG Issue 1205. Some algorithms could more clearly document their handling of empty ranges
    • C++11で、空のイテレータ範囲を渡した場合の戻り値が明記された
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.