#include <type_traits>
using namespace std;
template < typename T>
class singleton
{
public :
singleton ( ) {
static_assert( ! std:: is_constructible < T> :: value , "the constructor is not private" ) ;
}
static T& instance( ) {
static T inst;
return inst;
}
} ;
class class_with_public_constr : public singleton< class_with_public_constr>
{
friend class singleton< class_with_public_constr> ;
public :
class_with_public_constr( ) { }
} ;
int main( )
{
singleton< class_with_public_constr> :: instance ( ) ;
}
I2luY2x1ZGUgPHR5cGVfdHJhaXRzPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdGVtcGxhdGU8dHlwZW5hbWUgVD4KY2xhc3Mgc2luZ2xldG9uCnsKcHVibGljOgogICAgc2luZ2xldG9uICgpIHsKICAgICAgICBzdGF0aWNfYXNzZXJ0KCFzdGQ6OmlzX2NvbnN0cnVjdGlibGU8VD46OnZhbHVlLCAidGhlIGNvbnN0cnVjdG9yIGlzIG5vdCBwcml2YXRlIik7CiAgICB9CgogICAgc3RhdGljIFQmIGluc3RhbmNlKCkgewogICAgICAgIHN0YXRpYyBUIGluc3Q7CiAgICAgICAgcmV0dXJuIGluc3Q7CiAgICB9ICAgCn07CgpjbGFzcyBjbGFzc193aXRoX3B1YmxpY19jb25zdHIgOiBwdWJsaWMgc2luZ2xldG9uPGNsYXNzX3dpdGhfcHVibGljX2NvbnN0cj4gCnsKICBmcmllbmQgY2xhc3Mgc2luZ2xldG9uPGNsYXNzX3dpdGhfcHVibGljX2NvbnN0cj47ICAgCnB1YmxpYzoKICBjbGFzc193aXRoX3B1YmxpY19jb25zdHIoKSB7fQp9OwoKaW50IG1haW4oKSAKewogIHNpbmdsZXRvbjxjbGFzc193aXRoX3B1YmxpY19jb25zdHI+OjppbnN0YW5jZSgpOwp9Cg==
compilation info
prog.cpp: In instantiation of 'singleton<T>::singleton() [with T = class_with_public_constr]':
prog.cpp:22:30: required from here
prog.cpp:9:9: error: static assertion failed: the constructor is not private
static_assert(!std::is_constructible<T>::value, "the constructor is not private");
^
stdout