将两个变体与Boost static_visitor进行比较
Compare two variant with boost static_visitor
我几天前开始使用boost库,所以我的问题可能很琐碎。我想将两个相同类型的变体与static_visitor进行比较。我尝试了以下内容,但它不想编译。
struct compare:public boost::static_visitor<bool>
{
bool operator()(int& a, int& b) const
{
return a<b;
}
bool operator()(double& a, double& b) const
{
return a<b;
}
};
int main()
{
boost::variant<double, int > v1, v2;
v1 = 3.14;
v2 = 5.25;
compare vis;
bool b = boost::apply_visitor(vis, v1,v2);
cout<<b;
return 0;
}
感谢您的任何帮助或建议!
llonesmiz在评论中告诉我答案,但它消失了。如果某人有类似的问题,它可能会有所帮助:我必须处理不同运算符中INT和双倍组合的所有组合。实施它的最简单方法是使用模板,例如:
struct my_less : boost::static_visitor<bool>
{
template<typename T, typename U>
bool operator()(T a, U b) const
{
return a<b;
}
};
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- boost::进程间消息队列引发错误
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- cmake如何在fedora工作站中找到boost静态库包
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- Boost Graph Library,修复节点大小
- 什么是"#include <boost/functional/hash.hpp> "?
- 基于boost的程序的静态链接——zlib问题
- 为什么即使使用-cudart-static进行编译,库用户仍然需要链接到cuda运行时
- C++:如何在CLion IDE中安装Boost
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 如何在boost beast http请求中设置http头
- Boost Spirit,获取迭代器内部语义动作
- boost::asio::steady_timer()与sleep()我应该使用哪一个
- boost::asio如何生成多个协同程序,然后加入它们
- 当我尝试使用 sstream 和分面将 Boost Time_duration转换为字符串时,我没有得到所需的格式
- 如何处理Boost Spirit X3导致Visual Studio 2019 "static initialization order fiasco"?
- Sig 11在使用-icpc v12使用-static和-openmp编译时使用boost序列化
- "Mixing a dll boost library with a static runtime is a really bad idea..."
- 如何使用boost::expression-static在语义操作中引用可选子匹配