Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hana::experimental::type_name - MSVC support? #410

Open
014972304505347 opened this issue Jun 8, 2018 · 0 comments
Open

hana::experimental::type_name - MSVC support? #410

014972304505347 opened this issue Jun 8, 2018 · 0 comments

Comments

@014972304505347
Copy link

014972304505347 commented Jun 8, 2018

With the recent fork provided by Microsoft for Boost Hana / MSVC compiler compatibility, Hana now builds with the MSVC compiler. However, the experimental method hana::experimental::type_name has a hardcoded switch in its helper "type_name_impl2()" that only supports Clang:

// Note: We substract the null terminator from the string sizes below.
template <typename T>
constexpr cstring type_name_impl2() {

#if defined(__clang__)
	constexpr char const* pretty_function = __PRETTY_FUNCTION__;
	constexpr std::size_t total_size = sizeof(__PRETTY_FUNCTION__) - 1;
	constexpr std::size_t prefix_size = sizeof("boost::hana::experimental::detail::cstring boost::hana::experimental::detail::type_name_impl2() [T = ") - 1;
	constexpr std::size_t suffix_size = sizeof("]") - 1;
#else
        #error "No support for this compiler."
#endif

There exist pseudo-equivalent MSVC predefined-macros (see this doc) to __PRETTY_FUNCTION__ : __FUNCSIG__, __FUNCDNAME__, __func__, and __FUNCTION__. See this and this for reference. It is also worth looking at BOOST_CURRENT_FUNCTION. These could possibly make type_name compatible with MSVC by replacing the __PRETTY_FUNCTION__ macro.

I tried adding this switch in the type_name.hpp header file, which allows MSVC to hit the switch and use type_name:

	#if defined (__clang__)
	...
	#elif defined(_MSC_VER)
		constexpr char const* pretty_function = __FUNCSIG__;
		constexpr std::size_t total_size = sizeof(__FUNCSIG__) - 1;
		constexpr std::size_t prefix_size = sizeof("boost::hana::experimental::detail::cstring boost::hana::experimental::detail::type_name_impl2() [T = ") - 1;
		constexpr std::size_t suffix_size = sizeof("]") - 1;
	#else
            #error "No support for this compiler."
	#endif

type_name then yields typename strings like this:

        int -> "e_impl2<int>(void"
        "myStruct" user-defined struct -> "e_impl2<struct myStruct>(void"
        std::string -> "e_impl2<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >>(void"

Using BOOST_CURRENT_FUNCTION gives the same result.
This sort of output is messy, but can be interpreted and processed to give a better result.

__FUNCDNAME__, __func__, and __FUNCTION__ all cause compilation errors when used like above, though I suspect they would provide better output "out-of-the-box" if they can be worked out.

Would you consider adding something like the above so that MSVC can have type_name support? I may be interested in writing some code myself for solving the problem, though I think the fix is not complicated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant