C++中的boost库提供了许多有用的工具来简化我们的代码。其中boost::fusion::find_if是一个非常有用的算法,可以帮助我们在fusion序列中查找满足某一条件的元素。下面是一个关于boost::fusion::find_if用法的测试程序:
#include <iostream>
#include <string>
#include <boost/fusion/include/find_if.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/at.hpp>
struct is_long_string
{
template<typename T>
bool operator()(const T& t) const
{
return t.size() > 8;
}
};
int main()
{
using namespace boost::fusion;
vector<std::string, int, double, std::string> v("hello", 42, 3.14, "world");
auto it = find_if(v, is_long_string());
if(it != end(v))
{
std::cout &l