#include <iostream>
#include <memory>
template < typename T>
struct Animal {
Animal( ) { std:: cout << "Animal" << std:: endl ; }
~Animal( ) { std:: cout << "~Animal" << std:: endl ; }
} ;
struct Cat {
Cat( ) { std:: cout << "Cat" << std:: endl ; }
~Cat( ) { std:: cout << "~Cat" << std:: endl ; }
} ;
int main( ) {
std:: unique_ptr < Animal< Cat> , void ( * ) ( Animal< Cat> * ) > ptr;
ptr = std:: unique_ptr < Animal< Cat> , void ( * ) ( Animal< Cat> * ) > ( new Animal< Cat> , [ ] ( Animal< Cat> * ls) {
delete ls;
} ) ;
/*
std::unique_ptr<Animal<Cat>, void(*)(Animal<Cat>*)> ptr(new Animal<Cat>, [](Animal<Cat> *ls) {
delete ls;
});
*/
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWVtb3J5PgoKdGVtcGxhdGU8dHlwZW5hbWUgVD4Kc3RydWN0IEFuaW1hbCB7CiAgICBBbmltYWwoKSAgewkJc3RkOjpjb3V0IDw8ICJBbmltYWwiIDw8IHN0ZDo6ZW5kbDsJfQoJfkFuaW1hbCgpIHsJCXN0ZDo6Y291dCA8PCAifkFuaW1hbCIgPDwgc3RkOjplbmRsO30KfTsKCnN0cnVjdCBDYXQgewoJQ2F0KCkgIHsJc3RkOjpjb3V0IDw8ICJDYXQiIDw8IHN0ZDo6ZW5kbDsJfQoJfkNhdCgpIHsJc3RkOjpjb3V0IDw8ICJ+Q2F0IiA8PCBzdGQ6OmVuZGw7CX0KfTsKCmludCBtYWluKCkgewoJc3RkOjp1bmlxdWVfcHRyPEFuaW1hbDxDYXQ+LCB2b2lkKCopKEFuaW1hbDxDYXQ+Kik+IHB0cjsKCXB0ciA9IHN0ZDo6dW5pcXVlX3B0cjxBbmltYWw8Q2F0Piwgdm9pZCgqKShBbmltYWw8Q2F0PiopPihuZXcgQW5pbWFsPENhdD4sIFtdKEFuaW1hbDxDYXQ+ICpscykgewoJCWRlbGV0ZSBsczsKCX0pOwovKgoJc3RkOjp1bmlxdWVfcHRyPEFuaW1hbDxDYXQ+LCB2b2lkKCopKEFuaW1hbDxDYXQ+Kik+IHB0cihuZXcgQW5pbWFsPENhdD4sIFtdKEFuaW1hbDxDYXQ+ICpscykgewoJCWRlbGV0ZSBsczsKCX0pOwoqLwoJcmV0dXJuIDA7Cn0K
compilation info
In file included from /usr/include/c++/4.7/memory:86:0,
from prog.cpp:2:
/usr/include/c++/4.7/bits/unique_ptr.h: In instantiation of ‘constexpr std::unique_ptr<_Tp, _Dp>::unique_ptr() [with _Tp = Animal<Cat>; _Dp = void (*)(Animal<Cat>*)]’:
prog.cpp:16:54: required from here
/usr/include/c++/4.7/bits/unique_ptr.h:116:9: error: static assertion failed: constructed with null function pointer deleter
stdout