mercredi 23 janvier 2019

Unable to bind function to std::function

Trying to compile this following snippet of code:

#include <iostream>
#include <future>
#include <functional> 

void print_num(std::promise<bool>&& result, int i )
{
    std::cout << i << " " << '\n' ;
    result.set_value(true);
}

int main()
{
   std::promise<bool> Promise0;
   std::future<bool> Result0 = Promise0.get_future();      
   std::function<void()> f_display_31337 = std::bind(print_num, std::move(Promise0), 31337);

}

Getting the following error:

In function 'int main()': 15:90: error: conversion from 'std::_Bind_helper&&, int), std::promise, int>::type {aka std::_Bind, int))(std::promise&&, int)>}' to non-scalar type 'std::function' requested

I know it has something to do with the function argument std::promise&& and the need for std::move, but I'm stuck.

Aucun commentaire:

Enregistrer un commentaire