| 1 | // Copyright Louis Dionne 2013-2022 |
|---|---|
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) |
| 4 | |
| 5 | #include <boost/hana/for_each.hpp> |
| 6 | #include <boost/hana/tuple.hpp> |
| 7 | #include <boost/hana/type.hpp> |
| 8 | |
| 9 | #include <boost/core/demangle.hpp> |
| 10 | |
| 11 | #include <cstdlib> |
| 12 | #include <iostream> |
| 13 | #include <string> |
| 14 | namespace hana = boost::hana; |
| 15 | |
| 16 | |
| 17 | // Using hana::type<T> as a parameter type wouldn't work, since it may be |
| 18 | // a dependent type, in which case template argument deduction will fail. |
| 19 | // Using hana::basic_type<T> is fine, since this one is guaranteed to be |
| 20 | // a non dependent base of hana::type<T>. |
| 21 | template <typename T> |
| 22 | std::string const& name_of(hana::basic_type<T>) { |
| 23 | static std::string name = boost::core::demangle(name: typeid(T).name()); |
| 24 | return name; |
| 25 | } |
| 26 | |
| 27 | int main() { |
| 28 | hana::for_each(hana::tuple_t<int, char, void, std::string>, [](auto type) { |
| 29 | std::cout << name_of(type) << std::endl; |
| 30 | }); |
| 31 | } |
| 32 |
