小编Xua*_*Lin的帖子

为什么我不能像这样将函数与右值参数绑定?

#include <functional>
#include <iostream>
#include <string>
#include <utility>
using namespace std;

template<typename Func, typename... Args>
void do_task(Func &func, Args &&...args)
{
    auto f = bind(func, forward<Args>(args)...);
    f();
}

int main()
{
    string name = "hello";
    auto test_func = [](string name, string &&arg1, string &&arg2) -> void {
        cout << name << " " << arg1 << " " << arg2 << endl;
    };

    // do_task(test_func,"test_one", "hello", string("world"));     // compile error
    // do_task(test_func, "test_tww", std::move(name), "world");    // compile error
    do_task(test_func, "test_three", …
Run Code Online (Sandbox Code Playgroud)

c++ templates rvalue-reference stdbind stdmove

7
推荐指数
0
解决办法
75
查看次数

标签 统计

c++ ×1

rvalue-reference ×1

stdbind ×1

stdmove ×1

templates ×1