#include <iostream>
#include <thread>
using namespace std;

struct Join {};
struct Detach {};

template <typename Action>
class Thread {
public:

	Thread(thread && t) : th(move(t)) {}

	~Thread()
	{
		if (th.joinable()) action(Action());
	}

private:

	thread th;

	void action(Join)
	{
		th.join();
	}

	void action(Detach)
	{
		th.detach();
	}
};

void work()
{
}

int main()
{
	Thread<Join> t1(thread(work));
	Thread<Detach> t2(thread(work));
}
