std::basic_string_view<CharT,Traits>::npos
來自 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),其確切含義取決於上下文 |