#include <iostream>
using namespace std;
template<class T0> struct value_wrapper {
value_wrapper( T0* data_ ) {
std::cout << "value_wrapper( T0* data_ )" << std::endl;
data = data_;
}
value_wrapper() {
std::cout << "value_wrapper()" << std::endl;
data = new T0{};
}
value_wrapper( const value_wrapper& other ) {
std::cout << "value_wrapper( const value_wrapper& other )" << std::endl;
data = new T0{};
*data = *other.data;
}
value_wrapper& operator=( const value_wrapper& other ) {
std::cout << "value_wrapper& operator=( const value_wrapper& other )" << std::endl;
*data = *other.data;
}
~value_wrapper() {
std::cout << "~value_wrapper()" << std::endl;
delete data;
}
//move construction and assigment, other operators and member functions
T0* data;
};
//test class
struct value {
value() { std::cout << "value()" << std::endl; }
value( const value& other ) { std::cout << "value( const value& other )" << std::endl; }
value& operator=( const value& other ) { std::cout << "value& operator=( const value& other )" << std::endl; }
~value() { std::cout << "~value()" << std::endl; }
};
int main() {
value_wrapper<value> v1{ new value{} };
value_wrapper<value> v2{};
v2 = v1;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKCiAgICB0ZW1wbGF0ZTxjbGFzcyBUMD4gc3RydWN0IHZhbHVlX3dyYXBwZXIgewoKICAgICAgICB2YWx1ZV93cmFwcGVyKCBUMCogZGF0YV8gKSB7CiAgICAgICAgCXN0ZDo6Y291dCA8PCAidmFsdWVfd3JhcHBlciggVDAqIGRhdGFfICkiIDw8IHN0ZDo6ZW5kbDsKICAgICAgICAJZGF0YSA9IGRhdGFfOyAKICAgICAgICB9CgogICAgICAgIHZhbHVlX3dyYXBwZXIoKSB7CiAgICAgICAgCXN0ZDo6Y291dCA8PCAidmFsdWVfd3JhcHBlcigpIiA8PCBzdGQ6OmVuZGw7CiAgICAgICAgCWRhdGEgPSBuZXcgVDB7fTsgCiAgICAgICAgfQoKICAgICAgICB2YWx1ZV93cmFwcGVyKCBjb25zdCB2YWx1ZV93cmFwcGVyJiBvdGhlciApIHsKICAgICAgICAJc3RkOjpjb3V0IDw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