std::basic_..._view::npos(3)
okay so bestie, welcome to the C++ Standard Libary manual page for std::basic_string_view::npos β yes, the name is literally the name, and weβre obsessed with the self-referential icon energy π
β¨
πΈ NAME πΈ
std::basic_string_view::npos β std::basic_string_view::npos
β¨ Synopsis β¨
static constexpr size_type npos = size_type(-1); (since C++17)
This is a special value equal to the maximum value representable by the type size_type. The exact meaning depends on context, but it is generally used either as end of view indicator by the functions that expect a view index or as the error indicator by the functions that return a view index. Itβs been in the game since C++17, and itβs lowkey giving max-value main character energy, fr fr π«Άπ₯
π Example π
Run this code, bestie β itβs a whole vibe check for npos:
// Run this code
#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"));
}
π¦ See also π¦
nposβ special value. The exact meaning depends on the context.[static]β public static member constant ofstd::basic_string<CharT,Traits,Allocator>.
kiss kiss, this page came from http://cppreference.com and itβs dated 2024.06.10 π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms