From ed6afc7ead4e77032ca4e52b6baeecf403a91ae9 Mon Sep 17 00:00:00 2001 From: Michael Jones Date: Sun, 15 Mar 2020 03:49:23 -0500 Subject: [PATCH] Add function to hana::string to get the storage as a reference-to-array. I want to use hana::string to construct the function name provided to the boost::log macro BOOST_LOG_NAMED_SCOPE, but that macro ultimately constructs an object who's constructor has this signature: ```cpp template< typename T, size_type LenV > BOOST_CONSTEXPR basic_string_literal(T(&p)[LenV]) BOOST_NOEXCEPT; ``` Adding the "c_str_ref()" function to hana::string provides a very straightforward way to resolve this need. For example: ```cpp BOOST_LOG_NAMED_SCOPE(BOOST_HANA_STRING("my_function_name_here").c_str_ref()); ``` Of course, the example above is a very simplified example. The real use case is to to support passing the result of compile-time string manipulation logic into the macro. --- include/boost/hana/string.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/boost/hana/string.hpp b/include/boost/hana/string.hpp index aea19bd2ed..294f27eaf8 100644 --- a/include/boost/hana/string.hpp +++ b/include/boost/hana/string.hpp @@ -64,6 +64,10 @@ BOOST_HANA_NAMESPACE_BEGIN static constexpr char const* c_str() { return &detail::string_storage[0]; } + + static constexpr auto const& c_str_ref() { + return detail::string_storage; + } }; //! @endcond