c++ - 你如何添加两个 boost 任何值?

标签 c++ boost

我希望能够添加两个 boost any 值,如下所示:

boost::any lAnyVar = 5;
boost::any lAnyVar2 = 5;
boost::any lSum;

lSum = lAnyVar + lAnyVar2;

and

lAnyVar = lAnyVar + lAnyVar2;

如果 boost 任何类型 ID 不匹配,则可能会抛出异常。

是否存在 boost 或其他能够做到这一点的东西?

最佳答案

Is there something that exists in boost or other to be able to do this?

不是,因为做起来很简单。 boost::any 应该是通用的。对于您需要的东西,它需要为 boost::any 实现 operator+。

关于c++ - 你如何添加两个 boost 任何值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8714602/

相关文章:

c++ - Boost::Thread - 线程创建问题

c++ - 内存状态c++

c++ - SpinBoxDelegate 和 QItemDelegate

c++ - 派生类序列化 - 'unregistered class' 异常

c++ - Boost Beast 握手 : sslv3 alert handshake failure error

C++ Boost.asio Ping

c++ - 访问 boost::unordered_multimap 或结构时很少出现段错误

c++ - C++ 中的 std::thread 库是否支持嵌套线程?

boost - 如何使用 asio 执行非阻塞读取?

python - 使用 Boost.Python 包装和传递 HWND