conststr 0.2.1
Loading...
Searching...
No Matches
Concepts | Functions | Variables
conststr::charutils Namespace Reference

Some constexpr character operating functions. More...

Concepts

concept  char_like
 This concept is satisfied if T is a char-like type.
 

Functions

template<char_like T>
constexpr bool islower (T ch)
 constexpr re-implementation of std::islower.
 
template<char_like T>
constexpr bool issuper (T ch)
 constexpr re-implementation of std::issuper.
 
template<char_like T>
constexpr bool isdigit (T ch)
 constexpr re-implementation of std::isdigit.
 
template<char_like T>
constexpr bool isalpha (T ch)
 constexpr re-implementation of std::isalpha.
 
template<char_like T>
constexpr bool isalnum (T ch)
 constexpr re-implementation of std::isalnum.
 
template<char_like T>
constexpr bool isxdigit (T ch)
 constexpr re-implementation of std::isxdigit.
 
template<char_like T>
constexpr bool iscntrl (T ch)
 constexpr re-implementation of std::iscntrl.
 
template<char_like T>
constexpr bool ispunct (T ch)
 constexpr re-implementation of std::ispunct.
 
template<char_like T>
constexpr bool isblank (T ch)
 constexpr re-implementation of std::isblank.
 
template<char_like T>
constexpr bool isspace (T ch)
 constexpr re-implementation of std::isspace.
 
template<char_like T>
constexpr bool isgraph (T ch)
 constexpr re-implementation of std::isgraph.
 
template<char_like T>
constexpr bool isprint (T ch)
 constexpr re-implementation of std::isprint.
 
template<char_like T>
constexpr char toupper (T ch)
 constexpr re-implementation of std::toupper.
 
template<char_like T>
constexpr char tolower (T ch)
 constexpr re-implementation of std::tolower.
 
template<char_like T>
constexpr char invert (T ch)
 Invert case of letter.
 
template<char_like auto... Chs>
requires meta::all_same_of<Chs...> && (sizeof...(Chs) > 1)
constexpr bool is (meta::first_t_of< Chs... > ch)
 Check if input character the same as one of variable template parameters. More...
 
template<char_like auto Ch>
constexpr decltype(Ch) just (decltype(Ch) ignored)
 No matter what the input is, always output Ch. More...
 
template<char_like auto... Chs>
requires meta::all_same_of<Chs...> && (sizeof...(Chs) > 1)
constexpr meta::last_t_of< Chs... > replace (meta::last_t_of< Chs... > ch)
 Replace the input character if it is the same as one of variable template parameters. More...
 
template<char_like auto... Chs>
requires meta::all_same_of<Chs...> && (sizeof...(Chs) > 1)
constexpr meta::last_t_of< Chs... > remain (meta::last_t_of< Chs... > ch)
 Replace the input character if it is NOT one of variable template parameters. More...
 

Variables

template<char_like To>
constexpr auto cast
 Cast input character to the value of another character type. More...
 

Detailed Description

Some constexpr character operating functions.

Function Documentation

◆ is()

template<char_like auto... Chs>
requires meta::all_same_of<Chs...> && (sizeof...(Chs) > 1)
constexpr bool conststr::charutils::is ( meta::first_t_of< Chs... >  ch)
constexpr

Check if input character the same as one of variable template parameters.

This function can be used as a unary predicate parameter for many standard library algorithms in constant context. For example:

constexpr auto iter = std::find_if(start, end, is<'a', 'b', 'c'>);
Template Parameters
Chslist of expected characters
Parameters
chcharacters to be checked
Returns
true if the input character the same as of variable template parameters.
false otherwise.

◆ just()

template<char_like auto Ch>
constexpr decltype(Ch) conststr::charutils::just ( decltype(Ch)  ignored)
constexpr

No matter what the input is, always output Ch.

This function can be used as a unary operation parameter for many standard library algorithms in constant context. For example:

constexpr auto iter = std::transform(start, end, start, just<'0'>);
Template Parameters
Chcharacter to output
Parameters
ignoredany character
Returns
Value of Ch.

◆ remain()

template<char_like auto... Chs>
requires meta::all_same_of<Chs...> && (sizeof...(Chs) > 1)
constexpr meta::last_t_of< Chs... > conststr::charutils::remain ( meta::last_t_of< Chs... >  ch)
constexpr

Replace the input character if it is NOT one of variable template parameters.

It is the opposite function of replace<Chs...>(ch). For example, remain<'a', 'b', 'c', 'z'>(ch) will return 'z' if ch is NOT one of 'a', 'b' or 'c', otherwise return ch itself. This function can be used as a unary operation parameter for many standard library algorithms in constant context. For example:

constexpr auto iter = std::transform(start, end, start, remain<'-', '*'>);
Template Parameters
Chslist of expected characters
Parameters
chcharacters to be checked
Returns
The last value of variable template parameters if ch is NOT one of them, otherwise the value of ch.

◆ replace()

template<char_like auto... Chs>
requires meta::all_same_of<Chs...> && (sizeof...(Chs) > 1)
constexpr meta::last_t_of< Chs... > conststr::charutils::replace ( meta::last_t_of< Chs... >  ch)
constexpr

Replace the input character if it is the same as one of variable template parameters.

For example, replace<'a', 'b', 'c', 'z'>(ch) will return 'z' if ch is 'a', 'b' or 'c', otherwise return ch itself. This function can be used as a unary operation parameter for many standard library algorithms in constant context. For example:

constexpr auto iter = std::transform(start, end, start, replace<'A', 'a'>);
Template Parameters
Chslist of expected characters
Parameters
chcharacters to be checked
Returns
The last value of variable template parameters if ch is one of them, otherwise the value of ch.

Variable Documentation

◆ cast

template<char_like To>
constexpr auto conststr::charutils::cast
constexpr
Initial value:
=
[](char_like auto from) -> To { return static_cast<To>(from); }
This concept is satisfied if T is a char-like type.
Definition: conststr.hpp:354

Cast input character to the value of another character type.

Template Parameters
Tooutput character type
Parameters
frominput character
Returns
Casted character.