Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
std::basic_..._view::npos(3)  C++ Standard Libary std::basic_..._view::npos(3)

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.

Example
       // 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 of
		   std::basic_string<CharT,Traits,Allocator>)

http://cppreference.com		  2022.07.31	  std::basic_..._view::npos(3)

Want to link to this manual page? Use this URL:
<https://man.freebsd.org/cgi/man.cgi?query=std::string_view::npos&sektion=3&manpath=FreeBSD+Ports+15.0>

home | help