basic_type.cpp 983 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright Louis Dionne 2013-2017
  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. #include <boost/hana/for_each.hpp>
  5. #include <boost/hana/tuple.hpp>
  6. #include <boost/hana/type.hpp>
  7. #include <boost/core/demangle.hpp>
  8. #include <cstdlib>
  9. #include <iostream>
  10. #include <string>
  11. namespace hana = boost::hana;
  12. // Using hana::type<T> as a parameter type wouldn't work, since it may be
  13. // a dependent type, in which case template argument deduction will fail.
  14. // Using hana::basic_type<T> is fine, since this one is guaranteed to be
  15. // a non dependent base of hana::type<T>.
  16. template <typename T>
  17. std::string const& name_of(hana::basic_type<T>) {
  18. static std::string name = boost::core::demangle(typeid(T).name());
  19. return name;
  20. }
  21. int main() {
  22. hana::for_each(hana::tuple_t<int, char, void, std::string>, [](auto type) {
  23. std::cout << name_of(type) << std::endl;
  24. });
  25. }