uses_allocator — std::uses_allocator
uses_allocator — std::uses_allocator
std::uses_allocator는 어떤 타입이 할당자 인식(allocator-aware) 타입인지 판별하는 특성(trait) 템플릿이에요. <memory> 헤더에 제공돼요.
타입 T가 할당자를 사용한다는 것을 표준에 알리고, 제네릭 코드가 T를 생성할 때 할당자를 전달할지 결정하는 데 쓰여요. std::scoped_allocator_adaptor나 std::pmr 컨테이너 같은 곳이 활용해요.
출처: cppreference
본문
std::uses_allocator는 타입이 할당자를 사용하는지 나타내는 특성 템플릿이에요.
template<class T, class Alloc> struct uses_allocator;
T가 allocator_type이라는 타입 멤버를 선언했거나, T가 Alloc 타입을 인자로 받는 생성자를 가지면 true로 평가돼요. std::vector, std::map 같은 표준 컨테이너는 allocator_type을 가지므로 uses_allocator가 true가 돼요.
이 특성을 바탕으로, 예를 들어 중첩 컨테이너를 만들 때 할당자를 전파할지(uses_allocator_construction_args), 아니면 기본 생성자를 쓸지를 결정할 수 있어요. 할당자 인식 타입을 구성할 때 사용되는 핵심 메커니즘이에요.
같이 보기
std::uses_allocator_construction_argsstd::scoped_allocator_adaptorstd::allocator