std::basic_string_view<CharT,Traits>::npos
From cppreference.com
< cpp | string | basic string view
| static constexpr size_type npos = size_type(-1); |
(C++17以降) | |
これは、型 size_type で表現できる最大値に等しい特別な値です。正確な意味は文脈によって異なりますが、一般的には、ビューのインデックスを期待する関数によるビューの終端を示すインジケーターとして、またはビューのインデックスを返す関数によるエラーを示すインジケーターとして使用されます。
[編集] 例
このコードを実行
#include <string_view> constexpr bool contains(std::string_view const what, std::string_view const where) noexcept { return std::string_view::npos != where.find(what); } int main() { using namespace std::literals; static_assert(contains("water", "in a bottle of water")); static_assert(!contains("wine", "in a bottle of champagne")); static_assert(""sv.npos == "haystack"sv.find("needle")); }
[編集] 関連項目
constexpr size_type npos [static] |
特別な値 size_type(-1)。その正確な意味は文脈によって異なります。 |