Compile-time string.
Conceptually, a hana::string
is like a tuple holding integral_constant
s of underlying type char
. However, the interface of hana::string
is not as rich as that of a tuple, because a string can only hold compile-time characters as opposed to any kind of object.
Compile-time strings are used for simple purposes like being keys in a hana::map
or tagging the members of a Struct
. However, you might find that hana::string
does not provide enough functionality to be used as a full-blown compile-time string implementation (e.g. regexp matching or substring finding). Indeed, providing a comprehensive string interface is a lot of job, and it is out of the scope of the library for the time being.
hana::string
is implementation-defined. In particular, one should not take for granted that the template parameters are char
s. The proper way to access the contents of a hana::string
as character constants is to use hana::unpack
, .c_str()
or hana::to<char const*>
, as documented below. More details in the tutorial.For most purposes, a hana::string
is functionally equivalent to a tuple holding Constant
s of underlying type char
.
Comparable
Orderable
Orderable
is the usual lexicographical comparison of strings. Monoid
Foldable
Iterable
operator[]
can be used instead of the at
function. Searchable
Hashable
char const*
A hana::string
can be converted to a constexpr
null-delimited string of type char const*
by using the c_str()
method or hana::to<char const*>
. This makes it easy to turn a compile-time string into a runtime string. However, note that this conversion is not an embedding, because char const*
does not model the same concepts as hana::string
does.
char const*
A hana::string
can be created from any Constant
whose underlying value is convertible to a char const*
by using hana::to
. The contents of the char const*
are used to build the content of the hana::string
.
hana::string
not being a Constant
itself The underlying type held by a hana::string
could be either char const*
or some other constexpr-enabled string-like container. In the first case, hana::string
can not be a Constant
because the models of several concepts would not be respected by the underlying type, causing value
not to be structure-preserving. Providing an underlying value of constexpr-enabled string-like container type like std::string_view
would be great, but that's a bit complicated for the time being.
Synopsis of associated functions | |
template<> | |
constexpr auto | make< string_tag > |
Create a compile-time hana::string from a parameter pack of char integral_constant s. More... | |
constexpr auto | make_string = make<string_tag> |
Alias to make<string_tag> ; provided for convenience. More... | |
constexpr auto | to_string = to<string_tag> |
Equivalent to to<string_tag> ; provided for convenience. More... | |
template<char... s> | |
constexpr string< implementation_defined > | string_c {} |
Create a compile-time string from a parameter pack of characters. More... | |
#define | BOOST_HANA_STRING(s) see documentation |
Create a compile-time string from a string literal. More... | |
template<typename CharT , CharT... s> | |
constexpr auto | operator""_s () |
Creates a compile-time string from a string literal. More... | |
Friends | |
template<typename X , typename Y > | |
constexpr auto | operator== (X &&x, Y &&y) |
Equivalent to hana::equal | |
template<typename X , typename Y > | |
constexpr auto | operator!= (X &&x, Y &&y) |
Equivalent to hana::not_equal | |
template<typename X , typename Y > | |
constexpr auto | operator< (X &&x, Y &&y) |
Equivalent to hana::less | |
template<typename X , typename Y > | |
constexpr auto | operator> (X &&x, Y &&y) |
Equivalent to hana::greater | |
template<typename X , typename Y > | |
constexpr auto | operator<= (X &&x, Y &&y) |
Equivalent to hana::less_equal | |
template<typename X , typename Y > | |
constexpr auto | operator>= (X &&x, Y &&y) |
Equivalent to hana::greater_equal | |
template<typename X , typename Y > | |
constexpr auto | operator+ (X &&x, Y &&y) |
Performs concatenation; equivalent to hana::plus | |
Public Member Functions | |
template<typename N > | |
decltype(auto) constexpr | operator[] (N &&n) |
Equivalent to hana::at | |
Static Public Member Functions | |
static constexpr char const * | c_str () |
Returns a null-delimited C-style string. | |
Create a compile-time hana::string
from a parameter pack of char
integral_constant
s.
Given zero or more integral_constant
s of underlying type char
, make<string_tag>
creates a hana::string
containing those characters. This is provided mostly for consistency with the rest of the library, as hana::string_c
is more convenient to use in most cases.
|
related |
Alias to make<string_tag>
; provided for convenience.
|
related |
Equivalent to to<string_tag>
; provided for convenience.
|
related |
Create a compile-time string from a parameter pack of characters.
|
related |
Create a compile-time string from a string literal.
This macro is a more convenient alternative to string_c
for creating compile-time strings. However, since this macro uses a lambda internally, it can't be used in an unevaluated context, or where a constant expression is expected before C++17.
|
related |
Creates a compile-time string from a string literal.
The string literal is parsed at compile-time and the result is returned as a hana::string
. This feature is an extension that is disabled by default; see below for details.
BOOST_HANA_CONFIG_ENABLE_STRING_UDL
config macro is required to get this operator. Hence, if you want to stay safe, just use the BOOST_HANA_STRING
macro instead. If you want to be fast and furious (I do), define BOOST_HANA_CONFIG_ENABLE_STRING_UDL
.