File indexing completed on 2025-01-18 09:37:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_EXPERIMENTAL_TYPE_NAME_HPP
0011 #define BOOST_HANA_EXPERIMENTAL_TYPE_NAME_HPP
0012
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/string.hpp>
0015
0016 #include <cstddef>
0017 #include <utility>
0018
0019
0020 namespace boost { namespace hana { namespace experimental {
0021 namespace detail {
0022 struct cstring {
0023 char const* ptr;
0024 std::size_t length;
0025 };
0026
0027
0028 template <typename T>
0029 constexpr auto type_name_impl2() {
0030 #if defined(BOOST_HANA_CONFIG_CLANG)
0031 constexpr char const* pretty_function = __PRETTY_FUNCTION__;
0032 constexpr std::size_t total_size = sizeof(__PRETTY_FUNCTION__) - 1;
0033 constexpr std::size_t prefix_size = sizeof("auto boost::hana::experimental::detail::type_name_impl2() [T = ") - 1;
0034 constexpr std::size_t suffix_size = sizeof("]") - 1;
0035 #elif defined(BOOST_HANA_CONFIG_GCC)
0036 constexpr char const* pretty_function = __PRETTY_FUNCTION__;
0037 constexpr std::size_t total_size = sizeof(__PRETTY_FUNCTION__) - 1;
0038 constexpr std::size_t prefix_size = sizeof("constexpr auto boost::hana::experimental::detail::type_name_impl2() [with T = ") - 1;
0039 constexpr std::size_t suffix_size = sizeof("]") - 1;
0040 #else
0041 #error "No support for this compiler."
0042 #endif
0043
0044 cstring s{pretty_function + prefix_size, total_size - prefix_size - suffix_size};
0045 return s;
0046 }
0047
0048 template <typename T, std::size_t ...i>
0049 auto type_name_impl1(std::index_sequence<i...>) {
0050 constexpr auto name = detail::type_name_impl2<T>();
0051 return hana::string<*(name.ptr + i)...>{};
0052 }
0053 }
0054
0055
0056
0057
0058
0059
0060
0061
0062 template <typename T>
0063 auto type_name() {
0064 constexpr auto name = detail::type_name_impl2<T>();
0065 return detail::type_name_impl1<T>(std::make_index_sequence<name.length>{});
0066 }
0067 } }}
0068
0069 #endif