std::deque の推論ガイド
From cppreference.com
| ヘッダー <deque> で定義 |
||
| 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から) |
1) この 推論ガイド は deque に提供されており、イテレータ範囲からの推論を可能にします。このオーバーロードは、
InputIt が LegacyInputIterator を満たし、Alloc が Allocator を満たす場合にのみ、オーバーロード解決に参加します。注: ライブラリが型が LegacyInputIterator を満たさないと判断する範囲は未指定ですが、最小限として、整数型は入力イテレータとして適格ではありません。同様に、型が Allocator を満たさないと判断する範囲は未指定ですが、最小限として、メンバ型 Alloc::value_type が存在し、式 std::declval<Alloc&>().allocate(std::size_t{}) が評価されないオペランドとして well-formed である必要があります。
[編集] 注記
| 機能テストマクロ | 値 | 規格 | 機能 |
|---|---|---|---|
__cpp_lib_containers_ranges |
202202L |
(C++23) | レンジ対応の構築と挿入。オーバーロード (2) |
[編集] 例
このコードを実行
#include <deque> #include <vector> int main() { std::vector<int> v = {1, 2, 3, 4}; // uses explicit deduction guide to deduce std::deque<int> std::deque x(v.begin(), v.end()); // deduces std::deque<std::vector<int>::iterator> // first phase of overload resolution for list-initialization selects the candidate // synthesized from the initializer-list constructor; second phase is not performed // and deduction guide has no effect std::deque y{v.begin(), v.end()}; }