Presentation is loading. Please wait.

Presentation is loading. Please wait.

読んだもの P0254R0: Integrating std::string_view and std::string およびその関連スレッド 稲葉 一浩.

Similar presentations


Presentation on theme: "読んだもの P0254R0: Integrating std::string_view and std::string およびその関連スレッド 稲葉 一浩."— Presentation transcript:

1 読んだもの P0254R0: Integrating std::string_view and std::string およびその関連スレッド
稲葉 一浩

2 この提案は何であるか この前の Library Fundamentals TS で入った std::string_view についての改善案
だいたいこういう実装になるであろう物体 「文字列を渡して欲しいが引数を std::string と const char* のどちらにするか迷う」時のお助け用の型 template<typename CharT> class basic_string_view { public: // std::basic_string っぽいインターフェイス private: CharT *begin, *end; };

3 basic_string_view<CharT, ...> を string_view 等と略記しています
簡単のため basic_string_view<CharT, ...> を string_view 等と略記しています この提案は何であるか 現在 TS として受理されている案 namespace std { class string_view { public: string_view(const char*); string_view(const std::string&); std::string to_string() const; }; // std::string には変更なし }

4 この提案は何であるか (1/3) string_view の側では std::string を 特別扱いしない P0254R0
namespace std { class string_view { public: string_view(const char*); }; class string { explicit string(std::string_view sv); operator std::string_view() const; }

5 この提案は何であるか (2/3) string でなく string_view を取れば済む メソッドはそうする
P0254R0 string でなく string_view を取れば済む メソッドはそうする namespace std { class string { public: string& insert(size_t i, std::string_view sv); string& replace(size_t i, size_t n, std::string_view sv); ... } Rationale: null終端文字列や、他のライブラリの文字列型 (QString, CString) を効率的に渡せる

6 この提案は何であるか(3/3) P0254R0 : Future Work 標準ライブラリの他のstd::string引数も置換えたい
例 std::logic_error や std::runtime_error 置き換えたくないもの std::iftream, std::ofstream のファイル名引数 これらは結局 OS の API に渡る可能性が高く、null終端の保証がな いstring_viewで受け取るのは非効率

7 炎上案件 「標準ライブラリの他のstd::string引数も置換えたい」 この部分を C++17 に入れるべきか?
既存のオーバーロードを消して置き換える形にするとABI互換性が かといって単にstring_view版を増やすと曖昧性増えないか fstream のケース(前ページ) どうするのか const char* を string_view にすると長さ求める分遅くなることが こんなややこしい議論を今さらC++17向けに始めるべきでは ない、C++<next> でやろう派 vs そんなことでは標準としての consistency が無くなる派

8 炎上案件 [22cp00:07169] Re: [isocpp-lib] [isocpp-lib-ext] P Integrating string_view into the standard library [22cp00:07196] [Ext] Coherence in the standard Library TS として提案されたものはspec本体には手を加えないとい う不文律だか決まりがあって今回のようなことになりやすい 「TSからの昇格であってもC++次期バージョンの2-meeting前には “feature freeze”する決まりとすべきでは」 H.Sutter:「Suggestion: If anyone wants to see a new feature (core or fundamental library) applied in the standard library as a precondition of the basic feature going into the standard, please speak up early and say so, so we can discuss it and find out whether people generally agree. If there is a consensus for requiring that, then the “applying it to the standard library” part should be part of the proposal’s development.」


Download ppt "読んだもの P0254R0: Integrating std::string_view and std::string およびその関連スレッド 稲葉 一浩."

Similar presentations


Ads by Google