c++ - 可调用到 std::bind 的类型

标签 c++ function templates c++11 bind

在一个函数中,我需要将一个可调用的 std::bind 作为参数传递。 我应该使用的正确类型/模板是什么?

void foo(std::function<void(KnownType)> function, WhatShouldThisBe target)
{
    std::bind(function, target);
}

预期用途将是:

std::shared_ptr<SomeType> bar = std::make_shared<SomeType>();
foo(&SomeType::function, bar);

最佳答案

有点像

template <class T>
void foo(std::function<void(KnownType)> function, T&& target)
{
    std::bind(function, std::forward<T>(target));
}

关于c++ - 可调用到 std::bind 的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33483939/

相关文章:

C 函数和 char *

C++,将两个参数包传递给构造函数

c++ - 有没有人见过这种对快速排序的改进?

c++ - 在 Linux 和 Eclipse IDE 中使用 FFTW 库的问题

c++ - 如何递归到 "print list from tail to head"?

C:返回行中的 OR 运算符?

c++ - 使用未定义的宏构建一个库

c++ - 将文件拖动到窗口中时设置光标

django - Django 中的 'article_set' 来自哪里?

c++ 不是类模板