std::isalnum(std::locale)(3)

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

πŸ’– NAME πŸ’–

okay bestie, welcome to the std::isalnum(std::locale) page from the C++ Standard Libary manual, section 3. That's the whole title-and-manual-name situation, folded in cute so we can get to the good stuff. ✨

🌸 Synopsis 🌸

Defined in header <locale>:

template< class CharT >
bool isalnum( CharT ch, const locale& loc );

This function checks whether the character you pass in is classified as an alphanumeric character by the given locale's std::ctype facet. It's giving "vibe check for alphanumeric-ness, but make it locale-aware" πŸ’…

πŸ¦‹ Parameters πŸ¦‹

  • ch β€” character
  • loc β€” locale

πŸŽ€ Return value πŸŽ€

Returns true if the character is classified as alphanumeric, and false otherwise. Periodt. ✨

🧚 Possible implementation 🧚

template<class CharT>
bool isalnum(CharT ch, const std::locale& loc)
{
    return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::alnum, ch);
}

πŸ’œ Example πŸ’œ

This example demonstrates the use of isalnum() with different locales (OS-specific). The original page has the little // Run this code marker, so here's the code in all its glory:

#include <iostream>
#include <locale>

int main()
{
    const wchar_t c = L'\u2135'; // mathematical symbol aleph

    std::locale loc1("C");
    std::cout << "isalnum('β„΅', C locale) returned "
              << std::boolalpha << std::isalnum(c, loc1) << '\n';

    std::locale loc2("en_US.UTF-8");
    std::cout << "isalnum('β„΅', Unicode locale) returned "
              << std::boolalpha << std::isalnum(c, loc2) << '\n';
}

⭐ Possible output ⭐

isalnum('β„΅', C locale) returned false
isalnum('β„΅', Unicode locale) returned true

🌈 See also 🌈

  • isalnum β€” checks if a character is alphanumeric (function)
  • iswalnum β€” checks if a wide character is alphanumeric (function)

okay that's the page, bestie 🫢. Shoutout to the source and version/date in the footer: http://cppreference.com, 2024.06.10. slay πŸ’–

πŸ“¦ where this page comes from