Skip to content

Instantly share code, notes, and snippets.

@odeblic
Last active July 27, 2017 11:29
Show Gist options
  • Save odeblic/54dde952f594fbf609f2d78d62e9fd00 to your computer and use it in GitHub Desktop.
Save odeblic/54dde952f594fbf609f2d78d62e9fd00 to your computer and use it in GitHub Desktop.
Construction of callable objects
#include <iostream>
#include <thread>
#include <list>
struct Object
{
void method(int n) {}
void operator()(int n) {}
};
void function(int n)
{
}
int main()
{
Object obj;
std::list<std::thread> threads;
threads.emplace_back(obj, 7);
threads.emplace_back(std::ref(obj), 7);
threads.emplace_back(std::move(obj), 7);
threads.emplace_back(Object(), 7);
threads.emplace_back(&Object::method, obj, 7);
threads.emplace_back(&Object::method, &obj, 7);
threads.emplace_back([](int n){}, 7);
threads.emplace_back(function, 7);
for (auto& th : threads)
{
th.join();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment