#include <iostream>
#include <type_traits>
#include <memory>

template<typename Derived>
struct PImplMagic
{
	PImplMagic()
	{
		static_assert(std::is_base_of<PImplMagic, Derived>::value,
		              "Template parameter must be deriving class");
	}
//protected: //has to be public, unfortunately
	struct Impl;
};

struct Test : private PImplMagic<Test>, private std::unique_ptr<PImplMagic<Test>::Impl>
{
	Test();
	void f();
};

int main()
{
	Test t;
	t.f();
}

template<>
struct PImplMagic<Test>::Impl
{
	Impl()
	{
		std::cout << "It works!" << std::endl;
	}
	int x = 7;
};

Test::Test()
: std::unique_ptr<Impl>(new Impl)
{
}

void Test::f()
{
	std::cout << (*this)->x << std::endl;
}
