deduction guides for
std::forward_list
|
헤더 파일에 정의됨
<forward_list>
|
||
|
template
<
class
InputIt,
class
Alloc
=
std::
allocator
<
|
(1) | (C++17부터) |
|
template
<
ranges::
input_range
R,
class
Alloc
=
std::
allocator
<
ranges::
range_value_t
<
R
>>
>
|
(2) | (C++23부터) |
InputIt
가
LegacyInputIterator
를 만족하고
Alloc
가
Allocator
를 만족할 때에만 오버로드 해결에 참여합니다.
참고: 라이브러리가 특정 타입이
LegacyInputIterator
요구사항을 만족하지 않는다고 판단하는 범위는 명시되지 않았으나, 최소한 정수 타입들은 입력 반복자로 적합하지 않습니다. 마찬가지로, 특정 타입이
Allocator
요구사항을 만족하지 않는다고 판단하는 범위도 명시되지 않았으나, 최소한 멤버 타입
Alloc::value_type
이 존재해야 하며, 표현식
std::
declval
<
Alloc
&
>
(
)
.
allocate
(
std::
size_t
{
}
)
가 평가되지 않은 피연산자로 취급될 때 올바른 형태여야 합니다.
참고 사항
| Feature-test 매크로 | 값 | 표준 | 기능 |
|---|---|---|---|
__cpp_lib_containers_ranges
|
202202L
|
(C++23) | Ranges-aware 생성 및 삽입; 오버로드 (2) |
예제
#include <forward_list> #include <vector> int main() { std::vector<int> v = {1, 2, 3, 4}; // 명시적 deduction guide를 사용하여 std::forward_list<int>로 추론 std::forward_list x(v.begin(), v.end()); // std::forward_list<std::vector<int>::iterator>로 추론 // 목록 초기화를 위한 첫 번째 오버로드 해결 단계에서 // initializer-list 생성자에서 합성된 후보를 선택함 // 두 번째 단계는 수행되지 않으며 deduction guide는 효과가 없음 std::forward_list y{v.begin(), v.end()}; }