Boost.Hana  1.6.0 Your standard library for metaprogramming
boost::hana::literals Namespace Reference

Namespace containing C++14 user-defined literals provided by Hana. More...

## Functions

template<char ... c>
constexpr auto operator""_c ()
Creates a hana::integral_constant from a literal. More...

template<typename CharT , CharT ... s>
constexpr auto operator""_s ()
Creates a compile-time string from a string literal. More...

## Detailed Description

Namespace containing C++14 user-defined literals provided by Hana.

## ◆ operator""_c()

template<char ... c>
 constexpr auto boost::hana::literals::operator""_c ( )

Creates a hana::integral_constant from a literal.

The literal is parsed at compile-time and the result is returned as a llong<...>.

Note
We use llong<...> instead of ullong<...> because using an unsigned type leads to unexpected behavior when doing stuff like -1_c. If we used an unsigned type, -1_c would be something like ullong<-1> which is actually ullong<something huge>.

## Example

using namespace hana::literals; // contains the _c suffix
BOOST_HANA_CONSTANT_CHECK(1234_c == hana::llong_c<1234>);
BOOST_HANA_CONSTANT_CHECK(-1234_c == hana::llong_c<-1234>);
BOOST_HANA_CONSTANT_CHECK(1_c + (3_c * 4_c) == hana::llong_c<1 + (3 * 4)>);

## ◆ operator""_s()

template<typename CharT , CharT ... s>
 constexpr auto boost::hana::literals::operator""_s ( )

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.

Note
Only narrow string literals are supported right now; support for fancier types of string literals like wide or UTF-XX might be added in the future if there is a demand for it. See this issue if you need this.
Warning
This user-defined literal is an extension which requires a special string literal operator that is not part of the standard yet. That operator is supported by both Clang and GCC, and several proposals were made for it to enter C++17. However, since it is not standard, it is disabled by default and defining the 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.