Namespaces
Variants

std:: uses_allocator

From cppreference.net
Memory management library
( exposition only* )
Allocators
Uninitialized memory algorithms
Constrained uninitialized memory algorithms
Memory resources
Uninitialized storage (until C++20)
( 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 T, class Alloc >
struct uses_allocator ;
(C++11 이후)

만약 T Alloc 으로부터 변환 가능한 중첩 타입 allocator_type 을 가지고 있다면, 멤버 상수 value true 입니다. 그렇지 않으면 value false 입니다.

목차

헬퍼 변수 템플릿

template < class T, class Alloc >
constexpr bool uses_allocator_v = uses_allocator < T, Alloc > :: value ;
(C++17부터)

std:: integral_constant 에서 상속됨

멤버 상수

value
[static]
true 만약 T 가 할당자 Alloc 를 사용하면, false 그렇지 않으면
(public static member constant)

멤버 함수

operator bool
객체를 bool 로 변환, value 반환
(public member function)
operator()
(C++14)
value 반환
(public member function)

멤버 타입

타입 정의
value_type bool
type std:: integral_constant < bool , value >

Uses-allocator construction

allocator를 어떤 타입 T 의 생성자에 전달하는 세 가지 관례가 있습니다:

  • 만약 T 가 호환되는 할당자를 사용하지 않는 경우 ( std :: uses_allocator_v < T, Alloc > false 인 경우), alloc 은 무시됩니다.
  • 그렇지 않은 경우, std :: uses_allocator_v < T, Alloc > true 이고,
  • 만약 T 선행-할당자 규약 을 사용하는 경우( T ( std:: allocator_arg , alloc, args... ) 로 호출 가능할 때), uses-allocator construction은 이 형식을 사용합니다.
  • 만약 T 후행-할당자 규약 을 사용하는 경우( T ( args..., alloc ) 로 호출 가능할 때), uses-allocator construction은 이 형식을 사용합니다.
  • 그렇지 않으면 프로그램은 ill-formed입니다 (이는 std :: uses_allocator_v < T, Alloc > true 이지만, 해당 타입이 허용된 두 규약 중 어느 것도 따르지 않음을 의미합니다).

유틸리티 함수들 std::make_obj_using_allocator std::uninitialized_construct_using_allocator 는 위 프로토콜에 따라 객체를 명시적으로 생성하는 데 사용될 수 있으며, std::uses_allocator_construction_args 는 해당 타입이 예상하는 uses-allocator construction 방식과 일치하는 인수 목록을 준비하는 데 사용될 수 있습니다.

(C++20부터)

특수화

프로그램 정의 타입 T 에 중첩된 allocator_type 가 없는 경우, 프로그램은 다음 요구 사항 중 하나라도 충족되면 T 에 대해 std::uses_allocator 의 특수화를 std::true_type 에서 파생하도록 지정할 수 있습니다:

  • T 는 첫 번째 인자로 std::allocator_arg_t 를, 두 번째 인자로 Alloc 을 받는 생성자를 가지고 있습니다.
  • T 는 마지막 인자로 Alloc 을 받는 생성자를 가지고 있습니다.

위에서, Alloc 은 다음을 만족하는 타입입니다: Allocator 또는 std::experimental::pmr::memory_resource* 로 변환 가능한 포인터 타입입니다 (library fundamentals TS) .

다음 특수화들은 표준 라이브러리에서 이미 제공됩니다:

std::uses_allocator 타입 특성의 특수화
(클래스 템플릿 특수화)
std::uses_allocator 타입 특성의 특수화
(클래스 템플릿 특수화)
std::uses_allocator 타입 특성의 특수화
(클래스 템플릿 특수화)
std::uses_allocator 타입 특성의 특수화
(클래스 템플릿 특수화)
std::uses_allocator 타입 특성의 특수화
(클래스 템플릿 특수화)
std::uses_allocator 타입 특성의 특수화
(클래스 템플릿 특수화)
std::uses_allocator 타입 특성의 특수화
(클래스 템플릿 특수화)
std::uses_allocator 타입 특성의 특수화
(클래스 템플릿 특수화)
std::uses_allocator 타입 특성의 특수화
(클래스 템플릿 특수화)
std::uses_allocator 타입 특성의 특수화
(클래스 템플릿 특수화)
std::uses_allocator 타입 특성의 특수화
(클래스 템플릿 특수화)

참고 사항

이 타입 특성은 std::tuple , std::scoped_allocator_adaptor , 그리고 std::pmr::polymorphic_allocator 에 의해 사용됩니다. 또한 커스텀 할당자나 래퍼 타입에 의해 객체나 구성 중인 멤버가 자체적으로 할당자를 사용할 수 있는지(예: 컨테이너인 경우) 여부를 판단하는 데 사용될 수 있으며, 이 경우 해당 생성자에 할당자를 전달해야 합니다.

참고 항목

할당자 인식 생성자를 선택하는 데 사용되는 태그
(tag)
주어진 타입에 필요한 uses-allocator 생성 방식에 맞는 인수 목록을 준비함
(function template)
uses-allocator 생성 방식을 통해 주어진 타입의 객체를 생성함
(function template)
지정된 메모리 위치에서 uses-allocator 생성 방식을 통해 주어진 타입의 객체를 생성함
(function template)
다중 수준 컨테이너를 위한 다중 수준 할당자를 구현함
(class template)