#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
// 奇数の判定
//bool is_odd(int x) {
// return x % 2 > 0;
//}
class is_odd : public unary_function<int, bool>
{
public:
result_type operator() (argument_type k)
{
return (result_type)(k % 2);
}
};
int main()
{
// 初期設定
vector<int> v {4, 1, 4, 3, 4};
printf("vector v :");
for (auto x : v)
printf(" %d", x);
printf("\n");
// 4 である要素の数
int n = count(v.begin(), v.end(), 4);
printf("4 である要素数: %d\n", n);
// 奇数である要素の数
n = count_if(v.begin(), v.end(), is_odd()); // 単項関数オブジェクト
// n = count_if(v.begin(), v.end(), is_odd); // 関数
// n = count_if(v.begin(), v.end(), [](int x){ return x%2 > 0; }); // ラムダ式
printf("奇数の要素数: %d\n", n);
return 0;
}