최대 1 분 소요

개요

  • 범위로 정의된 메모리 영역에서 초기화에 의해 객체를 구성


예제

  • 코드
    #include <iostream>
    #include <memory>
    #include <vector>

    using namespace std;

    class Test {
    	public:
    		Test() { cout << "Test()" << endl; }
    		Test(int i) { cout << "Test(int i)" << endl; }
    		~Test() { cout << "~Test()" << endl; };
    };

    int main() {
    	vector<Test> v{Test(1), Test(2), Test(3)};

    	cout << "------" << endl;

    	uninitialized_value_construct(begin(v), end(v));

    	return 0;
    }
  • 실행 결과
    Test(int i)
    Test(int i)
    Test(int i)
    ~Test()
    ~Test()
    ~Test()
    ------
    Test()
    Test()
    Test()
    ~Test()
    ~Test()
    ~Test()