c++11 信号是否等同于增强信号
Are c++11 signals equivalent to boost.signals
正如我所理解的那样,c ++ 11标准中包含许多增强库。将boost::
更改为std::
后,我设法使用 c++11 编译器编译它们。我在编译包含boost::signals
的代码时遇到问题。
#include <iostream>
#include <functional>
#include <csignal>
void func()
{
std::cout << "Hello world" << std::endl;
}
int main()
{
std::signal<void()> s;
s.connect(func);
s();
}
我收到此错误:
prog.cpp: In function ‘int main()’:
prog.cpp:12:19: error: invalid operands of types ‘void (*(int, __sighandler_t)throw ())(int) {aka void (*(int, void (*)(int))throw ())(int)}’ and ‘void’ to binary ‘operator<’
std::signal<void()> s;
^
prog.cpp:12:22: error: ‘s’ was not declared in this scope
std::signal<void()> s;
std::signal
不等于boost::signal
吗?
std::signal 甚至不是一个模板,你不能写std::signal<type>;
http://en.cppreference.com/w/cpp/utility/program/signal
它们是完全不同的东西。 boost::signal 是一个信号槽框架,而 std::signal(它来自 C,而不是来自 C++11)是一个设置操作系统信号处理程序的函数。
std::signal
与boost::signal
无关。但是在不使用boost
的情况下制作像boost::signal
这样的东西并不难
template <typename... T>
struct signal{
typedef std::function<T...> function_type;
typedef std::vector<function_type> container_type;
container_type _slots;
template <typename... Args>
void operator()(Args... args){
for(function_type f: _slots){
f(args...);
}
}
void connect(function_type slot){
_slots.push_back(slot);
}
};
相关文章:
- Qt VTK交互风格的信号到小部件
- 获取日期异步信号安全吗?如果在信号处理程序中使用,它会导致死锁吗
- 无法将结构注册为增强几何体3D点
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- 如何在没有信号的情况下从C++执行QML插槽
- 线程之间的布尔停止信号
- 如何在信号处理程序和普通函数中对全局变量进行互斥读写操作
- 如何将增强MSM与增强信号结合使用?
- 括号内括号内的含义是什么,以获得增强信号
- 连接来自未知类的成员函数以增强信号
- 增强信号2 跟踪
- 增强信号槽概括
- 在地图中存储增强::信号2信号
- c++11 信号是否等同于增强信号
- 增强信号2破坏安全
- 增强信号:在类接口中公开信号本身或连接/断开方法
- 如何使C++增强::信号从封装发出它的物体的物体中捕获
- 增强线程和信号处理
- 用min_element增强信号
- C++具有不同参数的增强信号和插槽