std::uses_allocator

std::uses_allocator (std::stack 특수화)

std::uses_allocator 형질을 std::stack에 대해 투명하게 특수화한 구조체예요. 기본 컨테이너가 할당자를 사용할 때(그리고 그때만) 컨테이너 어댑터도 할당자를 사용해요. C++11부터 있어요.

출처: cppreference

본문

<stack> 헤더에 정의돼 있고, std::uses_allocator의 특수화예요.

template< class T, class Container, class Alloc >
struct uses_allocator<std::stack<T, Container>, Alloc>
    : std::uses_allocator<Container, Alloc>::type {};

std::stack에 대한 std::uses_allocator 형질의 투명한 특수화를 제공해요. 기본 컨테이너가 할당자를 사용할 때(그리고 그때만) 컨테이너 어댑터도 할당자를 사용해요.

std::integral_constant에서 상속된 멤버들:

  • 멤버 상수 value [static]: true (기본 컨테이너가 Alloc을 사용할 때).
  • 멤버 함수 operator bool: 객체를 bool로 변환해 value를 돌려줘요.
  • 멤버 함수 operator() (C++14): value를 돌려줘요.
  • 멤버 타입 value_type = bool, type = std::integral_constant<bool, value>.

예제를 보면요.

#include <memory>
#include <stack>

static_assert(
    std::uses_allocator<std::stack<int>, void>::value == false &&
    std::uses_allocator<std::stack<int>, std::allocator<int>>::value == true
);

int main() {}

기본 컨테이너(Container)가 Alloc 할당자를 사용하는지에 따라 stack이 할당자 인식을 지원하는지를 알려줘요. scoped allocator 모델에서 컨테이너가 자식 컨테이너로 할당자를 전파할 때 필요한 형질이에요.

더 알아보기 (Learn more)

cppreference