46
General discussions / Extended API for sf::Thread in SFML 2
« on: November 20, 2010, 02:26:31 pm »
Hi
I changed the sf::Thread class in SFML 2 to make it more flexible. I removed the Run() virtual function (so, no more inheritance from sf::Thread) and added a bunch of template constructors instead.
So now you can do this:
So the previous scenarios are still possible, plus a lot of new ones.
I changed the sf::Thread class in SFML 2 to make it more flexible. I removed the Run() virtual function (so, no more inheritance from sf::Thread) and added a bunch of template constructors instead.
So now you can do this:
Code: [Select]
void f();
sf::Thread t(&f);
Code: [Select]
void f(int arg); // arg type can be anything
sf::Thread t(&f, 5);
Code: [Select]
class Task
{
public:
void run();
};
Task task;
sf::Thread t(&Task::run, &task);
Code: [Select]
struct Functor
{
void operator()();
};
sf::Thread t(Functor());
Code: [Select]
struct Functor
{
void operator()(std::string arg);
};
sf::Thread t(Functor(), "toto");
Code: [Select]
sf::Thread t(boost::bind(...));
So the previous scenarios are still possible, plus a lot of new ones.