3 Defines `boost::hana::experimental::type_name`.
5 @copyright Louis Dionne 2013-2017
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_EXPERIMENTAL_TYPE_NAME_HPP
11 #define BOOST_HANA_EXPERIMENTAL_TYPE_NAME_HPP
13 #include <boost/hana/config.hpp>
14 #include <boost/hana/string.hpp>
20 BOOST_HANA_NAMESPACE_BEGIN namespace experimental {
27 // Note: We substract the null terminator from the string sizes below.
29 constexpr cstring type_name_impl2() {
31 #if defined(__clang__)
32 constexpr char const* pretty_function = __PRETTY_FUNCTION__;
33 constexpr std::size_t total_size = sizeof(__PRETTY_FUNCTION__) - 1;
34 constexpr std::size_t prefix_size = sizeof("boost::hana::experimental::detail::cstring boost::hana::experimental::detail::type_name_impl2() [T = ") - 1;
35 constexpr std::size_t suffix_size = sizeof("]") - 1;
37 #error "No support for this compiler."
40 return {pretty_function + prefix_size, total_size - prefix_size - suffix_size};
43 template <typename T, std::size_t ...i>
44 auto type_name_impl1(std::index_sequence<i...>) {
45 constexpr auto name = detail::type_name_impl2<T>();
46 return hana::string<*(name.ptr + i)...>{};
48 } // end namespace detail
50 //! @ingroup group-experimental
51 //! Returns a `hana::string` representing the name of the given type, at
54 //! This only works on Clang (and apparently MSVC, but Hana does not work
55 //! there as of writing this). Original idea taken from
56 //! https://github.com/Manu343726/ctti.
59 constexpr auto name = detail::type_name_impl2<T>();
60 return detail::type_name_impl1<T>(std::make_index_sequence<name.length>{});
62 } BOOST_HANA_NAMESPACE_END
64 #endif // !BOOST_HANA_EXPERIMENTAL_TYPE_NAME_HPP