Compile-time string.
Conceptually, a hana::string is like a tuple holding integral_constants 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 chars. The proper way to access the contents of a hana::string as character constants is to use hana::unpack or hana::to<char const*>, as documented below.For most purposes, a hana::string is functionally equivalent to a tuple holding Constants of underlying type char.
ComparableOrderableOrderable is the usual lexicographical comparison of strings. FoldableIterableoperator[] can be used instead of the at function. SearchableHashablechar const* A hana::string can be converted to a constexpr null-delimited string of type char const* by using 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.
Rationale for
hana::stringnot being aConstantThe underlying type held by a
hana::stringcould be eitherchar const*or some other constexpr-enabled string-like container. In the first case,hana::stringcan not be aConstantbecause the models of several concepts would not be respected by the underlying type, causingvaluenot to be structure-preserving. Providing an underlying value of constexpr-enabled string-like container type likestd::string_viewwould 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_constants. More... | |
| constexpr auto | make_string = make<string_tag> |
Alias to make<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 | |
Public Member Functions | |
| template<typename N > | |
| decltype(auto) constexpr | operator[] (N &&n) |
Equivalent to hana::at | |
Create a compile-time hana::string from a parameter pack of char integral_constants.
Given zero or more integral_constants 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 |
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.
|
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.