typeinfo.qbk 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. [/
  2. Copyright 2014 Peter Dimov
  3. Distributed under the Boost Software License, Version 1.0.
  4. See accompanying file LICENSE_1_0.txt
  5. or copy at http://boost.org/LICENSE_1_0.txt
  6. ]
  7. [section:typeinfo typeinfo]
  8. [simplesect Authors]
  9. * Peter Dimov
  10. [endsimplesect]
  11. [section Header <boost/core/typeinfo.hpp>]
  12. The header `<boost/core/typeinfo.hpp>` defines a class
  13. `boost::core::typeinfo`, which is an alias for `std::type_info`
  14. when RTTI is enabled, and is a reasonable substitute when RTTI
  15. is not supported.
  16. The macro `BOOST_CORE_TYPEID`, when applied to a type `T`, is the
  17. equivalent of `typeid(T)` and produces a reference to a const
  18. `typeinfo` object.
  19. The function `boost::core::demangled_name` takes a
  20. `boost::core::typeinfo const & ti` and either returns `ti.name()`,
  21. when that string doesn't need to be demangled, or
  22. `boost::core::demangle(ti.name())`, when it does. The return type
  23. of `boost::core::demangled_name` is `char const*` in the first case
  24. and `std::string` in the second.
  25. [section Synopsis]
  26. ``
  27. namespace boost
  28. {
  29. namespace core
  30. {
  31. class typeinfo;
  32. /* char const* or std::string */ demangled_name( typeinfo const & ti );
  33. }
  34. }
  35. #define BOOST_CORE_TYPEID(T) /*unspecified*/
  36. ``
  37. [endsect]
  38. [section Example]
  39. ``
  40. #include <boost/core/typeinfo.hpp>
  41. #include <iostream>
  42. template<class T1, class T2> struct X
  43. {
  44. };
  45. int main()
  46. {
  47. typedef X<void const*, void(*)(float)> T;
  48. boost::core::typeinfo const & ti = BOOST_CORE_TYPEID(T);
  49. std::cout << boost::core::demangled_name( ti ) << std::endl;
  50. }
  51. ``
  52. [endsect]
  53. [endsect]
  54. [endsect]