Questions tagged [std-function]

A C++11 class template that is callable like a function, and wraps another callable type and forwards calls to it.

In the words of the C++11 standard std::function is a polymorphic wrapper class that encapsulates arbitrary callable objects. It is polymorphic because an instance of the type std::function<R (A1, A2)> could wrap an object of many different callable types, including:

  • a function pointer of type R (*)(A1, A2)
  • a function pointer of type R (*)(const A1&, const A2&)
  • a function object (a.k.a functor) with a member function such as R C::operator()(A1, A2)
  • a pointer to member function of type R (A1::*)(A2)
  • a lambda [](A1 a1, A2 a2) -> R {...}

std::function is often used to implement generic callbacks or to support passing arbitrary callable types to a function that cannot be written as function template e.g. because it must be virtual.

Use this tag for questions about std::function and std::tr1::function.

844 questions
-3
votes
1 answer

how to pass > paramater in c++

i'm trying to perform a thread pool design pattern in c++, but i'm stuck on passing a task function parameter in order to push it inside a list here is my code std::list> work_queue; my push function void…
Lyes
  • 400
  • 5
  • 19
-3
votes
1 answer

std::function with templated Argument Types

struct Functor { public: template Functor(std::function Function) { this->Function = Function; } ~Functor() {} void operator()() const { OutputDebugStringA("Hello there,…
Swagov3rflow
  • 25
  • 1
  • 8
-3
votes
1 answer

How to write a std::function with lambda expression in a map container using C#?

How would I rewrite the below C++ code into C#? std::string someVariable; std::map> myMap; myMap.insert(std::make_pair("someText", [&](std::string input){someVariable = input;}); I have tried playing…
Pita
  • 111
  • 7
-3
votes
1 answer

In whats case should use auto type?

I have some questions regarding when use auto Explicit, it is not more clear despite the context? Cases that are better be explicit instead of auto? And with lambda functions use auto how these auto f = [](auto v, auto x)…
user3854612
  • 127
  • 1
  • 1
  • 7
1 2 3
56
57