質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

解決済

1回答

1385閲覧

[C++17]std::basic_string_viewのsearch系関数のnoexcept指定について

yumetodo

総合スコア5850

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

2グッド

0クリップ

投稿2018/06/01 07:33

cppreference.comやcpprefjpを見る限り、search系関数のnoexcept指定は例えばfind_first_ofだと

cpp

1constexpr size_type find_first_of(basic_string_view sv, size_type pos = 0) const noexcept; // (1) 2constexpr size_type find_first_of(CharT c, size_type pos = 0) const noexcept; // (2) 3constexpr size_type find_first_of(const CharT* s, size_type pos, size_type n) const; // (3) 4constexpr size_type find_first_of(const CharT* s, size_type pos = 0) const; // (4)

のようになっています。ここで規格書(N4659)によれば

3 Each member function of the form

constexpr return-type F (const charT* s, size_type pos);
is equivalent to return F (basic_string_view(s), pos);

4 Each member function of the form

constexpr return-type F (const charT* s, size_type pos, size_type n);
is equivalent to return F (basic_string_view(s, n), pos);

5 Each member function of the form

constexpr return-type F (charT c, size_type pos);
is equivalent to return F (basic_string_view(&c, 1), pos);

となっており、例えばfind_first_ofだと

cpp

1constexpr size_type find_first_of(basic_string_view str, size_type pos = 0) const noexcept;

のように記述されています。つまりconst noexceptがついています。

is equivalent to

をまっとうに解釈すれば、冒頭のは

cpp

1constexpr size_type find_first_of(basic_string_view sv, size_type pos = 0) const noexcept; // (1) 2constexpr size_type find_first_of(CharT c, size_type pos = 0) const noexcept; // (2) 3constexpr size_type find_first_of(const CharT* s, size_type pos, size_type n) const noexcept; // (3) 4constexpr size_type find_first_of(const CharT* s, size_type pos = 0) const noexcept; // (4)

であるべきではないかと思うのですが、なにか解釈を間違えているでしょうか?

Chironian, KSwordOfHaste👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

おそらく "広い契約(Wide Contracts)とnoexcept指定" に該当する話題かと思います。

いずれのメンバ関数も外部仕様として例外送出するものではありませんが、オーバーロード(3),(4)に限って第1引数にヌルポインタ指定など無効なC文字列を渡したときに未定義動作が生じえます。このエッジケースに対応するため、noexpcet指定の有無が異なるのでしょう。

投稿2018/06/01 08:05

編集2018/06/01 08:07
yohhoy

総合スコア6189

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yumetodo

2018/06/01 09:25

>未定義動作の一つとして“例外送出”という振る舞いを許容するとも解釈できる。 なん・・・だと・・・!?
yumetodo

2018/06/01 16:33

冒頭4ページくらい読みましたが、はえぇぇ・・・
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問