demangle_test.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // Trivial test for core::demangle
  3. //
  4. // Copyright (c) 2014 Peter Dimov
  5. // Copyright (c) 2014 Andrey Semashev
  6. //
  7. // Distributed under the Boost Software License, Version 1.0.
  8. // See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt
  10. //
  11. #include <boost/core/demangle.hpp>
  12. #include <typeinfo>
  13. #include <iostream>
  14. template<class T1, class T2> struct Y1
  15. {
  16. };
  17. void test_demangle()
  18. {
  19. typedef Y1<int, long> T;
  20. std::cout << boost::core::demangle( typeid( T ).name() ) << std::endl;
  21. }
  22. void test_demangle_alloc()
  23. {
  24. typedef Y1<int, long> T;
  25. const char* p = boost::core::demangle_alloc( typeid( T ).name() );
  26. if (p)
  27. {
  28. std::cout << p << std::endl;
  29. boost::core::demangle_free(p);
  30. }
  31. else
  32. {
  33. std::cout << "[demangling failed]" << std::endl;
  34. }
  35. }
  36. void test_scoped_demangled_name()
  37. {
  38. typedef Y1<int, long> T;
  39. boost::core::scoped_demangled_name demangled_name( typeid( T ).name() );
  40. const char* p = demangled_name.get();
  41. if (p)
  42. {
  43. std::cout << p << std::endl;
  44. }
  45. else
  46. {
  47. std::cout << "[demangling failed]" << std::endl;
  48. }
  49. }
  50. int main()
  51. {
  52. test_demangle();
  53. test_demangle_alloc();
  54. test_scoped_demangled_name();
  55. return 0;
  56. }