std::basic_...first_not_of(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

✨ NAME ✨

Hey bestie, welcome to the std::basic_...first_not_of(3) page from the C++ Standard Libary β€” yes, the header spells it β€œLibary,” and we are keeping the lore exactly as it is πŸ’….

The name is std::basic_string_view::find_first_not_of β€” and the manpage also repeats it after the dash as std::basic_string_view::find_first_not_of, so both are here, because apparently the name wanted main character energy twice πŸ‘‘.


πŸ“œ Synopsis

Okay so the synopsis in the original is line-wrapped like a group chat at 3 a.m., but here are the exact overloads with every token, number, since C++17, const, and noexcept preserved:

constexpr size_type
    find_first_not_of( basic_string_view v, size_type pos = 0 )
(1) (since C++17)
const noexcept;
constexpr size_type
    find_first_not_of( CharT ch, size_type pos = 0 ) const
(2) (since C++17)
noexcept;
constexpr size_type
    find_first_not_of( const CharT* s, size_type pos, size_type
(3) (since C++17)
count ) const;
constexpr size_type
(4) (since C++17)
    find_first_not_of( const CharT* s, size_type pos = 0 ) const;

The whole vibe: it finds the first character not equal to any of the characters in the given character sequence. It's giving β€œspot the odd one out” πŸ”₯.

  1. Finds the first character not equal to any of the characters of v in this view, starting at position pos.
  2. Equivalent to find_first_not_of(basic_string_view(std::addressof(ch), 1), pos).
  3. Equivalent to find_first_not_of(basic_string_view(s, count), pos).
  4. Equivalent to find_first_not_of(basic_string_view(s), pos).

🧸 Parameters

  • v β€” view to search for. The character crew you're checking against πŸ’–.
  • pos β€” position at which to start the search.
  • count β€” length of the string of characters to compare.
  • s β€” pointer to a string of characters to compare.
  • ch β€” character to compare.

🎁 Return value

Position of the first character not equal to any of the characters in the given string, or std::string_view::npos if no such character is found. No match? You get npos, the official β€œnope” value 😭.


⏱️ Complexity

O(size() * v.size()) at worst. Nested-loop energy, fr fr πŸ’€.


πŸ’» Example

// Run this code

#include <string_view>
using namespace std::literals;

int main()
{
    static_assert(2 == "BCDEF"sv.find_first_not_of("ABC"));
                    //    ^
    static_assert(4 == "BCDEF"sv.find_first_not_of("ABC", 4));
                    //      ^
    static_assert(1 == "BCDEF"sv.find_first_not_of('B'));
                    //   ^
    static_assert(3 == "BCDEF"sv.find_first_not_of('D', 2));
                    //     ^
}

πŸ‘€ See also

  • find β€” find characters in the view (public member function)
  • rfind β€” find the last occurrence of a substring (public member function)
  • find_first_of β€” find first occurrence of characters (public member function)
  • find_last_of β€” find last occurrence of characters (public member function)
  • find_last_not_of β€” find last absence of characters (public member function)
  • find_first_not_of β€” find first absence of characters (public member function of std::basic_string<CharT,Traits,Allocator>)

Cute little sign-off bestie: source/version is http://cppreference.com, dated 2024.06.10, and the manual is std::basic_...first_not_of(3). Go find your first not-of character and slay πŸ’–πŸ¦‹βœ¨.

πŸ“¦ where this page comes from