memory_destroy
memory_destroy (std::destroy)
<memory> 헤더에 정의되어 있어요. 대상 범위 [first, last)의 요소들을 파괴해요. C++17부터 도입됐어요.
출처: cppreference
본문
template< class ForwardIt >
void destroy( ForwardIt first, ForwardIt last ); // (1) since C++17, until C++20
template< class ForwardIt >
constexpr void destroy( ForwardIt first, ForwardIt last ); // since C++20
template< class ExecutionPolicy, class ForwardIt >
void destroy( ExecutionPolicy&& policy, ForwardIt first, ForwardIt last ); // (2) since C++17
-
- 대상 범위
[first, last)의 요소들을 다음과 같이 파괴해요.
- 대상 범위
for (; first != last; ++first)
std::destroy_at(std::addressof(*first));
-
- (1)과 같지만
policy에 따라 실행돼요.
- (1)과 같지만
이 오버로드는 std::is_execution_policy_v<...>가 true일 때만 참여해요. (C++20까지 std::decay_t, 이후 std::remove_cvref_t)
매개변수
first, last: 파괴할 요소 범위를 정의하는 반복자 쌍policy: 사용할 실행 정책
타입 요구사항
ForwardIt은 LegacyForwardIterator 요구사항을 충족해야 해요.
반환값
없음.
미초기화 저장 공간에 placement new로 만든 객체들을 범위 단위로 파괴할 때 써요. std::allocator_traits::destroy를 반복 호출하는 것과 동일한 효과를 내요.
T* buf = ...;
for (int i = 0; i < 10; ++i) ::new (buf + i) T;
std::destroy(buf, buf + 10); // 10개 객체 소멸자 호출