std::raw_storage_iterator
| 헤더에 정의됨 <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의 요구 사항을 충족하고 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
|
|
||||
pointer
|
void | ||||
reference
|
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 .
참고 항목
(C++11) |
할당자 유형에 대한 정보를 제공합니다 (클래스 템플릿) |
(C++11) |
다중 수준 컨테이너에 대한 다중 수준 할당자를 구현합니다 (클래스 템플릿) |
(C++11) |
지정된 유형이 uses-allocator 생성을 지원하는지 확인합니다 (클래스 템플릿) |
| 객체 범위를 초기화되지 않은 메모리 영역에 복사합니다 (함수 템플릿 & 알고리즘 함수 객체) | |
(C++20) |