all_of を使ってみる (C++)
C++
Published: 2020-01-26

やったこと

all_of を使ってみます。

確認環境

$ g++ --version
g++ (Homebrew GCC 9.2.0) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

調査

test.cpp

#include <bits/stdc++.h>
using namespace std;

int main() {
    vector<int> v = {2, 9, 3, 5};
    bool ans = all_of(v.begin(), v.end(), [](int x) { return x >= 2; });
    cout << ans << endl;

    bool ans2 = all_of(v.begin(), v.end(), [](int x) { return x >= 5; });
    cout << ans2 << endl;
}

出力結果

1
0

参考