#include <iostream>
#include <vector>
#include <memory> // For std::unique_ptr and std::make_unique
struct MyType {
int a;
MyType( int x) : a( x) {
std:: cout << "MyType constructor called with a: " << a << std:: endl ;
}
~MyType( ) {
std:: cout << "MyType destructor called " << a << std:: endl ;
}
} ;
int main( ) {
// Create a vector of unique_ptr to MyType
std:: vector < std:: unique_ptr < MyType>> myVector;
// Insert elements using std::make_unique
for ( int i = 0 ; i < 3 ; ++ i) {
myVector.push_back ( std:: make_unique < MyType> ( i + 1 ) ) ;
}
std:: cout << "Calling clear()..." << std:: endl ;
myVector.clear ( ) ;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWVtb3J5PiAgLy8gRm9yIHN0ZDo6dW5pcXVlX3B0ciBhbmQgc3RkOjptYWtlX3VuaXF1ZQoKc3RydWN0IE15VHlwZSB7CiAgICBpbnQgYTsKICAgIE15VHlwZShpbnQgeCkgOiBhKHgpIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgIk15VHlwZSBjb25zdHJ1Y3RvciBjYWxsZWQgd2l0aCBhOiAiIDw8IGEgPDwgc3RkOjplbmRsOwogICAgfQogICAgfk15VHlwZSgpIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgIk15VHlwZSBkZXN0cnVjdG9yIGNhbGxlZCAiIDw8IGEgPDwgc3RkOjplbmRsOwogICAgfQp9OwoKaW50IG1haW4oKSB7CiAgICAvLyBDcmVhdGUgYSB2ZWN0b3Igb2YgdW5pcXVlX3B0ciB0byBNeVR5cGUKICAgIHN0ZDo6dmVjdG9yPHN0ZDo6dW5pcXVlX3B0cjxNeVR5cGU+PiBteVZlY3RvcjsKCiAgICAvLyBJbnNlcnQgZWxlbWVudHMgdXNpbmcgc3RkOjptYWtlX3VuaXF1ZQogICAgZm9yIChpbnQgaSA9IDA7IGkgPCAzOyArK2kpIHsKICAgICAgICBteVZlY3Rvci5wdXNoX2JhY2soc3RkOjptYWtlX3VuaXF1ZTxNeVR5cGU+KGkgKyAxKSk7CiAgICB9CiAgICBzdGQ6OmNvdXQgPDwgIkNhbGxpbmcgY2xlYXIoKS4uLiIgPDwgc3RkOjplbmRsOwogICAgbXlWZWN0b3IuY2xlYXIoKTsKICAgIHJldHVybiAwOwp9