최대 1 분 소요

개요

  • 전달된 인자의 주소에 있는 객체에 대한 포인터를 반환


예제

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

    using namespace std;

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

    int main() {
    	constexpr int size = 3;

    	unsigned char pool[sizeof(Test) * size];

    	for (int i = 0; i < size; ++i) {
    		new (pool + (sizeof(Test) * i)) Test;
    	}

    	auto ptr = launder(reinterpret_cast<Test *>(pool));

    	for (int i = 0; i < size; ++i) {
    		destroy_at(ptr + i);
    	}

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