29 public std::runtime_error {
33 std::runtime_error(
"Couldn't initialize the instance") {}
36 std::runtime_error(type +
" could not be initialized") {
42 void deleter(T* obj) {
51 virtual bool init() {
return true; }
52 virtual void clean_up() {
60 bool cleaned_up =
false;
67 typedef std::shared_ptr<T> ptr;
68 typedef std::weak_ptr<T> wptr;
70 template<
typename... Args>
71 static typename RefCounted<T>::ptr create(Args&&... args) {
72 typename RefCounted<T>::ptr instance =
typename RefCounted<T>::ptr(
73 new T(std::forward<Args>(args)...),
74 std::bind(&deleter<T>, std::placeholders::_1)
77 if(!instance->init()) {
83 static typename RefCounted<T>::ptr create() {
84 typename RefCounted<T>::ptr instance =
typename RefCounted<T>::ptr(
86 std::bind(&deleter<T>, std::placeholders::_1)
89 if(!instance->init()) {
99 template<
typename...Args>