Namespaces
Variants

std:: raw_storage_iterator

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
raw_storage_iterator
( until C++20* )
( until C++20* )
( until C++20* )

Garbage collector support (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
(C++11) (until C++23)
헤더 파일에 정의됨 <memory>
template < class OutputIt, class T >

class raw_storage_iterator

: public std:: iterator < std:: output_iterator_tag , void , void , void , void > ;
(C++17까지)
template < class OutputIt, class T >
class raw_storage_iterator ;
(C++17부터)
(C++17부터 사용 중단됨)
(C++20에서 제거됨)

출력 반복자 std::raw_storage_iterator 는 표준 알고리즘이 초기화되지 않은 메모리에 결과를 저장할 수 있게 합니다. 알고리즘이 역참조된 반복자에 T 타입의 객체를 쓸 때마다, 해당 객체는 반복자가 가리키는 초기화되지 않은 저장 공간의 위치에 복사 생성됩니다. 템플릿 매개변수 OutputIt LegacyOutputIterator 요구사항을 충족하고 operator * 가 객체를 반환하도록 정의된 모든 타입이며, 이 객체에 대해 operator & T* 타입의 객체를 반환합니다. 일반적으로 T* 타입이 OutputIt 로 사용됩니다.

목차

타입 요구사항

-
OutputIt LegacyOutputIterator 요구사항을 충족해야 합니다.

멤버 함수

새로운 raw_storage_iterator 를 생성함
(public member function)
버퍼 내 지정된 위치에 객체를 생성함
(public member function)
반복자를 역참조함
(public member function)
반복자를 전진시킴
(public member function)
(since C++17)
래핑된 반복자에 접근을 제공함
(public member function)

멤버 타입

멤버 타입 정의
iterator_category std:: output_iterator_tag
value_type void
difference_type

void

(C++20 이전)

std::ptrdiff_t

(C++20 이후)
pointer void
reference void

멤버 타입 iterator_category , value_type , difference_type , pointer reference std:: iterator < std:: output_iterator_tag , void , void , void , void > 로부터 상속받아 얻어야 합니다.

(C++17 이전)

참고

std::raw_storage_iterator 가 주로 폐기된 이유는 예외 안전하지 않은 동작 때문입니다. std::uninitialized_copy 와 달리, 이는 std::copy 와 같은 연산 중 발생하는 예외를 안전하게 처리하지 못해, 성공적으로 생성된 객체의 수와 예외 발생 시 이들의 적절한 소멸을 추적하지 못함으로 인해 자원 누수가 발생할 가능성이 있습니다.

예제

#include <algorithm>
#include <iostream>
#include <memory>
#include <string>
int main()
{
    const std::string s[] = {"This", "is", "a", "test", "."};
    std::string* p = std::allocator<std::string>().allocate(5);
    std::copy(std::begin(s), std::end(s),
              std::raw_storage_iterator<std::string*, std::string>(p));
    for (std::string* i = p; i != p + 5; ++i)
    {
        std::cout << *i << '\n';
        i->~basic_string<char>();
    }
    std::allocator<std::string>().deallocate(p, 5);
}

출력:

This
is
a
test
.

참고 항목

할당자 타입에 대한 정보를 제공함
(클래스 템플릿)
다중 수준 컨테이너를 위한 다중 수준 할당자를 구현함
(클래스 템플릿)
지정된 타입이 uses-allocator 생성 방식을 지원하는지 확인함
(클래스 템플릿)