Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::basic_string_view<CharT,Traits>::npos

      From cppreference.com
      <cpp‎ |string‎ |basic string view
       
       
       
      std::basic_string_view
       
      staticconstexpr size_type npos= size_type(-1);
      (since C++17)

      This is a special value equal to the maximum value representable by the typesize_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.

      [edit]Example

      Run this code
      #include <string_view> constexprboolcontains(std::string_viewconst what,std::string_viewconst where)noexcept{return std::string_view::npos!= where.find(what);} int main(){usingnamespace 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"));}

      [edit]See also

      constexpr size_typenpos[static] the special valuesize_type(-1), its exact meaning depends on the context[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/string/basic_string_view/npos&oldid=150244"

      [8]ページ先頭

      ©2009-2025 Movatter.jp