user_config.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright Antony Polukhin, 2016-2019.
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See
  4. // accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. //[getting_started_user_config
  7. #ifndef USER_CONFIG_HPP
  8. #define USER_CONFIG_HPP
  9. #include <boost/stacktrace/stacktrace_fwd.hpp>
  10. #include <iosfwd>
  11. namespace boost { namespace stacktrace {
  12. template <class CharT, class TraitsT, class Allocator>
  13. std::basic_ostream<CharT, TraitsT>& do_stream_st(std::basic_ostream<CharT, TraitsT>& os, const basic_stacktrace<Allocator>& bt);
  14. template <class CharT, class TraitsT>
  15. std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const stacktrace& bt) {
  16. return do_stream_st(os, bt);
  17. }
  18. }} // namespace boost::stacktrace
  19. #endif // USER_CONFIG_HPP
  20. //]
  21. #ifndef USER_CONFIG2_HPP
  22. #define USER_CONFIG2_HPP
  23. #include <ios> // std::streamsize
  24. //[getting_started_user_config_impl
  25. namespace boost { namespace stacktrace {
  26. template <class CharT, class TraitsT, class Allocator>
  27. std::basic_ostream<CharT, TraitsT>& do_stream_st(std::basic_ostream<CharT, TraitsT>& os, const basic_stacktrace<Allocator>& bt) {
  28. const std::streamsize w = os.width();
  29. const std::size_t frames = bt.size();
  30. for (std::size_t i = 0; i < frames; ++i) {
  31. os.width(2);
  32. os << i;
  33. os.width(w);
  34. os << "# ";
  35. os << bt[i].name();
  36. os << '\n';
  37. }
  38. return os;
  39. }
  40. }} // namespace boost::stacktrace
  41. //]
  42. #endif // USER_CONFIG2_HPP