boost::phoenix3

本文探讨了如何使用C++的STL库和Boost Phoenix库在容器中查找第一个奇数元素,通过`std::find_if`函数结合自定义条件来实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <vector>
#include <algorithm>
#include <iostream>
#include <boost/phoenix/core.hpp>
#include <boost/phoenix/operator.hpp>

int
main()
{
    using boost::phoenix::arg_names::arg1;

    int init[] = { 2, 10, 4, 5, 1, 6, 8, 3, 9, 7 };
    std::vector<int> c(init, init + 10);
    typedef std::vector<int>::iterator iterator;

    //  Find the first odd number in container c
    iterator it = std::find_if(c.begin(), c.end(), arg1 % 2 == 1);

    if (it != c.end())
        std::cout << *it << std::endl;    //  if found, print the result
    return 0;
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值