C++ Logo

sg16

Advanced search

[isocpp-sg16] P3688R0 ASCII character utilities

From: Cleiton Santoia <cleitonsantoia_at_[hidden]>
Date: Wed, 16 Jul 2025 16:34:25 -0300
Just read P03688 and thought instead of put "ascii" in all names, one could
also implement a type/object/namespace "ascii" and group those functions
there, making easier to implement future ( or custom ) other charcodes like
EBCDIC or even old iso-646;

struct ascii {
   static constexpr bool is_digit(chatacter_type c) noexcept;
   static constexpr bool is_alpha(chatacter_type c) noexcept;
   ...
};

struct ebcdic {
   static constexpr bool is_digit(chatacter_type c) noexcept;
   static constexpr bool is_alpha(chatacter_type c) noexcept;
   ...
};

And use like that :
   auto it = std::ranges::find( str, ascii::is_digit );
   auto it = std::ranges::find( str, ebcdic::is_digit );

   typename< CharCode ccType >
   int parse_int(const std::string& sb) {
      ...
      if ( ccType.is_digit(sb[i]) ) {...}
      ...
   }


Cleiton.

Received on 2025-07-16 19:34:25