libsemigroups  v3.0.0
C++ library for semigroups and monoids
Loading...
Searching...
No Matches
libsemigroups::literals Namespace Reference

Defined in word-range.hpp.

This namespace contains some functions for creating word_type objects in a compact form.

Example
012_w // same as word_type({0, 1, 2})
"abc"_w // also same as word_type({0, 1, 2})
"(ab)^3"_p // same as "ababab"

Functions

std::string operator""_p (const char *w)
 Literal for defining word_type by parsing an algebraic expression.
 
std::string operator""_p (const char *w, size_t n)
 Literal for defining std::string by parsing an algebraic expression.
 
word_type operator""_w (const char *w)
 Literal for defining word_type over integers less than 10.
 
word_type operator""_w (const char *w, size_t n)
 Literal for defining word_type over integers less than 10.
 

Function Documentation

◆ operator""_p() [1/2]

std::string operator""_p ( const char * w)

See operator""_p for details.

◆ operator""_p() [2/2]

std::string operator""_p ( const char * w,
size_t n )

This operator provides a convenient concise means of constructing a std::string from an algebraic expression. For example, "((ab)^3cc)^2"_p equals "abababccabababcc" and "a^0"_p equals the empty string "".

This function has the following behaviour:

  • arbitrarily nested brackets;
  • spaces are ignored;
  • redundant matched brackets are ignored;
  • only the characters in "()^ " and in a-zA-Z0-9 are allowed.
Parameters
wthe letters of the word.
nthe length of w (defaults to the length of w).
Returns
A value of type string.
Exceptions
LibsemigroupsExceptionif the string cannot be parsed.

◆ operator""_w() [1/2]

word_type operator""_w ( const char * w)

See operator""_w for details.

◆ operator""_w() [2/2]

word_type operator""_w ( const char * w,
size_t n )

This operator provides a convenient brief means of constructing a word_type from an sequence of literal integer digits or a string. For example, 0123_w produces the same output as word_type({0, 1, 2, 3}) and so too does "abcd"_w.

There are some gotchas and this operator should be used with some care:

  • the parameter w must consist of the integers \(\{0, \ldots, 9\}\) or the characters in a-zA-Z but not both.
  • if w starts with 0 and is follows by a value greater than 7, then it is necessary to enclose w in quotes. For example, 08_w will not compile because it is interpreted as an invalid octal. However "08"_w behaves as expected.
  • if w consists of characters in a-zA-Z, then the output is the same as that of ToWord::operator()(w), see operator()()
Parameters
wthe letters of the word.
nthe length of w (defaults to the length of w).
Returns
A value of type word_type.
Exceptions
LibsemigroupsExceptionif the input contains a mixture of integers and non-integers.