std::basic_string
に対する推定ガイド
ヘッダ <string> で定義 | ||
template<class InputIt, class Alloc =std::allocator< typenamestd::iterator_traits<InputIt>::value_type>> | (1) | (C++17以上) |
template<class CharT, class Traits, | (2) | (C++17以上) |
template<class CharT, class Traits, | (3) | (C++17以上) |
InputIt
が LegacyInputIterator を満たし、 Alloc
が Allocator を満たす場合にのみ、オーバーロード解決に参加します。Alloc
が Allocator を満たす場合にのみ、オーバーロード解決に参加します。ノート: ある型が LegacyInputIterator を満たさないとライブラリが判断する範囲は、少なくとも整数型が入力イテレータとして適合しないことを除いて、未規定です。 同様に、ある型が Allocator を満たさないと判断される範囲も、少なくともメンバ型 Alloc::value_type
が存在しなければならず、式 std::declval<Alloc&>().allocate(std::size_t{}) が評価されない被演算子として扱われたときに well-formed でなければならないことを除いて、未規定です。
[編集] ノート
ガイド (2-3) は、 std::basic_string_view のための std::basic_string のコンストラクタが既存のコードに曖昧性が生じるのを回避するためにテンプレート化され、それらのテンプレートがクラステンプレート引数推定をサポートしないために、必要です。
[編集] 欠陥報告
以下の動作変更欠陥報告は以前に発行された C++ 標準に遡って適用されました。
DR | 適用先 | 発行時の動作 | 正しい動作 |
---|---|---|---|
LWG 3075 | C++17 | deduction from basic_string_view was unsupported (exacerbated by LWG issue 2946) | deduction guides added |
[編集]例
#include <string>#include <vector>int main(){std::vector<char> v ={'a', 'b', 'c'};std::basic_string s(v.begin(), v.end());// uses explicit deduction guide}