mardi 29 janvier 2019

Can you use std::bind (or something else) to change return type?

Say I've got a function,

bool my_func(bool input_val) { return !input_val; }

and I want to pass it around as a function that returns void and takes nothing, so it would be something like:

bool the_truth = true;
func_taking_a_void_func([the_truth]() -> void { my_func(the_truth); });

I tried using std::bind, but the compiler says something about the function returning a value, and being unable to convert.

func_taking_a_void_func(std::bind(my_func, the_truth));

Is it possible to do something like this without a lambda? I'm using C++11 on VS2013, but anything else is good too.

Aucun commentaire:

Enregistrer un commentaire