conststr 0.2.1
Loading...
Searching...
No Matches
Namespaces | Classes | Concepts | Functions | Variables
conststr Namespace Reference

The outermost namespace of this library to avoid identifier pollution. More...

Namespaces

namespace  charutils
 Some constexpr character operating functions.
 
namespace  literal
 Define string literal suffix.
 
namespace  meta
 Some useful template meta.
 

Classes

struct  cstr
 String type that can be evaluated in a constant context. More...
 
struct  sv_selector
 String view type selector. Just an empty struct. More...
 

Concepts

concept  can_construct_cstr_from
 This concept is satisfied if cstr can be constructed from T.
 
concept  can_construct_cstr_t_from
 This concept is satisfied if cstr can be constructed from T and the value_type of the cstr is CharT.
 
concept  can_construct_cstr_t_n_from
 This concept is satisfied if cstr can be constructed from T and the value_type of the cstr is CharT and length is Len.
 

Functions

template<charutils::char_like T, std::size_t N>
 cstr (const T(&)[N]) -> cstr< N - 1, T, std::basic_string_view< T > >
 Deduction guide for cstr with default view type.
 
template<charutils::char_like T, std::size_t N, meta::viewer< T > V>
 cstr (const T(&)[N], const sv_selector< V > &) -> cstr< N - 1, T, V >
 Deduction guide for cstr with string view type selector.
 
template<charutils::char_like T>
 cstr (const T &ch) -> cstr< 1, T, std::basic_string_view< T > >
 Deduction guide for cstr with default view type.
 
template<charutils::char_like T, meta::viewer< T > V>
 cstr (const T &ch, const sv_selector< V > &) -> cstr< 1, T, V >
 Deduction guide for cstr with string view type selector.
 
template<std::size_t Idx, charutils::char_like T, typename U , std::size_t N>
cstr< N, T, U >::reference get (cstr< N, T, U > &str) noexcept
 Tuple-like interface, extracts the Idx-th element from the string. More...
 
template<std::size_t Idx, charutils::char_like T, typename U , std::size_t N>
cstr< N, T, U >::const_reference get (const cstr< N, T, U > &str) noexcept
 Tuple-like interface, extracts the Idx-th element from the string. More...
 
template<std::size_t Idx, charutils::char_like T, typename U , std::size_t N>
cstr< N, T, U >::rreference get (cstr< N, T, U > &&str) noexcept
 Tuple-like interface, extracts the Idx-th element from the string. More...
 
template<std::size_t Idx, charutils::char_like T, typename U , std::size_t N>
const cstr< N, T, U >::const_rreference get (const cstr< N, T, U > &&str) noexcept
 Tuple-like interface, extracts the Idx-th element from the string. More...
 
template<charutils::char_like T, typename V1 , typename V2 , std::size_t N>
constexpr void swap (cstr< N, T, V1 > &lhs, cstr< N, T, V2 > &rhs)
 Satisfy the named requirement Swappable. More...
 
template<can_construct_cstr_from First, can_construct_cstr_from... Str>
requires meta::all_same< typename decltype(cstr(std::declval<First>()))::value_type, typename decltype(cstr(std::declval<Str>()))::value_type...>
constexpr auto flatten (const First &first, const Str &...strs)
 Flatten multiple strings of different lengths. More...
 
template<charutils::char_like T, typename U , std::size_t N>
std::ostream & operator<< (std::ostream &os, const cstr< N, T, U > &str)
 Output string to std::ostream.
 

Variables

template<typename T >
constexpr auto sv = sv_selector<T>{}
 String view type selector. Assist in type deduction of cstr. More...
 

Detailed Description

The outermost namespace of this library to avoid identifier pollution.

Function Documentation

◆ flatten()

template<can_construct_cstr_from First, can_construct_cstr_from... Str>
requires meta::all_same< typename decltype(cstr(std::declval<First>()))::value_type, typename decltype(cstr(std::declval<Str>()))::value_type...>
constexpr auto conststr::flatten ( const First &  first,
const Str &...  strs 
)
constexpr

Flatten multiple strings of different lengths.

Compared to str1.flatten(str2, str3 ...), the form flatten(str1, str2, str3 ...) is more suitable for metaprogramming.

Parameters
firstfirst string to flattened
strsother strings to flattened
Returns
constexpr auto

◆ get() [1/4]

template<std::size_t Idx, charutils::char_like T, typename U , std::size_t N>
const cstr< N, T, U >::const_rreference conststr::get ( const cstr< N, T, U > &&  str)
noexcept

Tuple-like interface, extracts the Idx-th element from the string.

Template Parameters
Idxposition of the character
Parameters
strstring to be operated
Returns
R-value reference to a character.

◆ get() [2/4]

template<std::size_t Idx, charutils::char_like T, typename U , std::size_t N>
cstr< N, T, U >::const_reference conststr::get ( const cstr< N, T, U > &  str)
noexcept

Tuple-like interface, extracts the Idx-th element from the string.

Template Parameters
Idxposition of the character
Parameters
strstring to be operated
Returns
Reference to a character.

◆ get() [3/4]

template<std::size_t Idx, charutils::char_like T, typename U , std::size_t N>
cstr< N, T, U >::rreference conststr::get ( cstr< N, T, U > &&  str)
noexcept

Tuple-like interface, extracts the Idx-th element from the string.

Template Parameters
Idxposition of the character
Parameters
strstring to be operated
Returns
R-value reference to a character.

◆ get() [4/4]

template<std::size_t Idx, charutils::char_like T, typename U , std::size_t N>
cstr< N, T, U >::reference conststr::get ( cstr< N, T, U > &  str)
noexcept

Tuple-like interface, extracts the Idx-th element from the string.

Template Parameters
Idxposition of the character
Parameters
strstring to be operated
Returns
Reference to a character.

◆ swap()

template<charutils::char_like T, typename V1 , typename V2 , std::size_t N>
constexpr void conststr::swap ( cstr< N, T, V1 > &  lhs,
cstr< N, T, V2 > &  rhs 
)
constexpr

Satisfy the named requirement Swappable.

Parameters
lhsthe value to be swapped
rhsthe value to be swapped

Variable Documentation

◆ sv

template<typename T >
constexpr auto conststr::sv = sv_selector<T>{}
constexpr

String view type selector. Assist in type deduction of cstr.

For example:

#include <span>
#include "conststr.hpp"
// View type defaults to `std::string_view`, aka `std::basic_string_view<char>`
constexpr auto s1 = cstr("hello world!");
// View type is `std::span<const char>`
constexpr auto s2 = cstr("hello world!", sv<std::span<const char>>);
// You can also change the view type like this
constexpr auto s3 = cstr("hello world!").with_view<std::span<const char>>();
Main header file for the constant string type.
constexpr auto sv
String view type selector. Assist in type deduction of cstr.
Definition: conststr.hpp:643
String type that can be evaluated in a constant context.
Definition: conststr.hpp:657
constexpr auto with_view() const noexcept -> cstr< N, value_type, V2 >
Change view type.
Definition: conststr.hpp:1128
Template Parameters
Tstring view type