template<typename T> class value_ptr { struct Base { virtual T& get() = 0; virtual const T& get() const = 0; virtual ~Base() {} virtual std::unique_ptr<Base> clone() const = 0; }; template<typename Der> struct Derived : public Base { Der d; template<typename... args> Derived(args...&& arg) : d(std::forward<args>(arg)...) {} // Plus copy/move constructor virtual T& get() { return d; } virtual const T& get() const { return d; } virtual std::unique_ptr<Base> clone() const { return make_unique<Derived>(d); } }; std::unique_ptr<Base> base; public: value_ptr() = delete; value_ptr(const value_ptr& other) : base(other.base->clone()) {} value_ptr(value_ptr&& other) : base(std::move(other.base)) {} template<typename Der> value_ptr(Der t) { base = make_unique<Derived<Der>(std::move(t)); } T* operator->() { return base->get(); } const T* operator->() const { return base->get(); } T& operator*() { return *base->get(); } const T& operator*() const { return *base->get(); } void swap(value_ptr& other) { base.swap(other.base); } value_ptr& operator=(value_ptr other) { this->swap(other); } };
Standard input is empty
prog.cpp:6:17: error: 'unique_ptr' in namespace 'std' does not name a type prog.cpp:10:51: error: expected ',' or '...' before '&&' token prog.cpp:15:17: error: 'unique_ptr' in namespace 'std' does not name a type prog.cpp:19:5: error: 'unique_ptr' in namespace 'std' does not name a type prog.cpp: In constructor 'value_ptr<T>::Derived<Der>::Derived(args ...)': prog.cpp:11:17: error: 'forward' is not a member of 'std' prog.cpp:11:34: error: expected primary-expression before '>' token prog.cpp:11:36: error: 'arg' was not declared in this scope prog.cpp: In copy constructor 'value_ptr<T>::value_ptr(const value_ptr<T>&)': prog.cpp:23:11: error: class 'value_ptr<T>' does not have any field named 'base' prog.cpp: In constructor 'value_ptr<T>::value_ptr(value_ptr<T>&&)': prog.cpp:25:11: error: class 'value_ptr<T>' does not have any field named 'base' prog.cpp:25:16: error: 'move' is not a member of 'std' prog.cpp: In constructor 'value_ptr<T>::value_ptr(Der)': prog.cpp:27:9: error: 'base' was not declared in this scope prog.cpp:27:16: error: 'make_unique' was not declared in this scope prog.cpp:27:41: error: 'move' is not a member of 'std' prog.cpp: In member function 'T* value_ptr<T>::operator->()': prog.cpp:30:30: error: 'base' was not declared in this scope prog.cpp: In member function 'const T* value_ptr<T>::operator->() const': prog.cpp:31:42: error: 'base' was not declared in this scope prog.cpp: In member function 'T& value_ptr<T>::operator*()': prog.cpp:32:30: error: 'base' was not declared in this scope prog.cpp: In member function 'const T& value_ptr<T>::operator*() const': prog.cpp:33:42: error: 'base' was not declared in this scope prog.cpp: In member function 'void value_ptr<T>::swap(value_ptr<T>&)': prog.cpp:36:9: error: 'base' was not declared in this scope
Standard output is empty