std::basic_string_view<CharT,Traits>:: npos
From cppreference.net
<
cpp
|
string
|
basic string view
C++
Strings library
| Classes | ||||
|
(C++17)
|
||||
std::basic_string_view
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
static
constexpr
size_type npos
=
size_type
(
-
1
)
;
|
(desde C++17) | |
Este es un valor especial igual al valor máximo representable por el tipo
size_type
. El significado exacto depende del contexto, pero generalmente se utiliza como indicador de fin de vista por las funciones que esperan un índice de vista o como indicador de error por las funciones que devuelven un índice de vista.
Ejemplo
Ejecutar este código
#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")); }
Véase también
constexpr
size_type
npos
[static]
|
el valor especial size_type ( - 1 ) , su significado exacto depende del contexto |