c++ - 带有多个参数的 Map.emplace C++ 17
问题描述
使用 C++ 17:拥有
using working_t = bool;
std::map<std::thread, working_t> _pool;
我正在尝试向此地图添加一个新线程,但我找不到合适的语法..
class ThreadPool {
std::map<std::thread, working_t> _pool;
void init() {
_pool.emplace(&ThreadPool::thread_init, this, false);
}
void thread_init();
};
这应该将一个线程添加到地图中,并将 false 作为值,但它无法编译.. 这可能吗?
解决方案
你需要:
_pool.emplace(
std::piecewise_construct,
std::forward_as_tuple(&ThreadPool::thread_init, this),
std::forward_as_tuple(false)
);
...以区分键和值的参数列表。但是,您将遇到std::thread
没有的问题operator <
,但这是另一个问题:)
推荐阅读
- flutter - 如何将标签添加到 DropdownButtonFormField -dropdown-items
- javascript - 如何在 JavaScript 中获取文本之前显示加载 gif
- c# - Visual Studio 是否有类似 Chrome 的“瀑布”调试工具?
- python - 我的货币转换器应用程序有问题
- docker - docker run:invalid reference format error unbricking switch
- python - ImportError:无法从“tensorflow.python.keras.layers.normalization”导入名称“LayerNormalization”
- python - 将 BST 结果打印到 .txt 文件 - 写入问题
- laravel - Laravel 测试 csrf 不匹配
- javascript - querySelectorAll 以获取具有特定名称和值的输入滑块
- javascript - 检测div中的滚动结束