Last active
July 27, 2017 11:29
-
-
Save odeblic/54dde952f594fbf609f2d78d62e9fd00 to your computer and use it in GitHub Desktop.
Construction of callable objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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