std::basic_string_view<CharT,Traits>::npos
来自 zh.cppreference.net
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 ) ,其具体含义取决于上下文 |