From 7c31b83360d44e742b488a9cefb022b751a46348 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Sat, 30 Sep 2017 07:23:16 +0900 Subject: [PATCH] fix testspr trace implementation --- testspr/print.hpp | 31 +++++++++++++++++++++++++++---- testspr/trace.hpp | 6 +++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/testspr/print.hpp b/testspr/print.hpp index 8530e622..8eaabfb7 100644 --- a/testspr/print.hpp +++ b/testspr/print.hpp @@ -24,6 +24,28 @@ #include namespace testspr { + namespace detail { + inline SPROUT_NON_CONSTEXPR std::ostream& + to_string_impl(std::ostream& os) { + return os; + } + template + inline SPROUT_NON_CONSTEXPR std::ostream& + to_string_impl(std::ostream& os, Head const& head, Tail const&... tail) { + return testspr::detail::to_string_impl(os << head, tail...); + } + } // namespace detail + // + // to_string + // + template + inline SPROUT_NON_CONSTEXPR std::string + to_string(Head const& head, Tail const&... tail) { + std::ostringstream os; + testspr::detail::to_string_impl(os, head, tail...); + return os.str(); + } + // // print // @@ -144,12 +166,13 @@ namespace testspr { template inline SPROUT_NON_CONSTEXPR void print_hl(T const& t) { - std::ostringstream oss; - oss << t; - std::string s(oss.str()); - for (std::string::size_type i = 0, last = 80 / s.size(); i != last; ++i) { + std::string s(testspr::to_string(t)); + for (std::string::size_type i = 0, n = 80 / s.size(); i != n; ++i) { std::cout << s; } + for (std::string::const_iterator it = s.begin(), last = s.begin() + 80 % s.size(); it != last; ++it) { + std::cout << *it; + } std::cout << std::endl; } diff --git a/testspr/trace.hpp b/testspr/trace.hpp index 0fc6d666..6fa195b7 100644 --- a/testspr/trace.hpp +++ b/testspr/trace.hpp @@ -488,12 +488,12 @@ namespace testspr { // TESTSPR_TRACE_BLOCK // # define TESTSPR_TRACE_BLOCK(name) \ - testspr::block_tracer SPROUT_PP_CAT(testspr_block_tracer_, __LINE__)(__FILE__, __LINE__, name) + testspr::block_tracer SPROUT_PP_CAT(testspr_block_tracer_, __LINE__)(__FILE__, __LINE__, testspr::to_string(name)) // // TESTSPR_TRACE_BLOCK_EXPR // # define TESTSPR_TRACE_BLOCK_EXPR(name) \ - ((void)testspr::block_tracer(__FILE__, __LINE__, name)) + ((void)testspr::block_tracer(__FILE__, __LINE__, testspr::to_string(name))) namespace detail { inline SPROUT_NON_CONSTEXPR bool @@ -545,7 +545,7 @@ namespace testspr { // TESTSPR_TRACE_MARK // # define TESTSPR_TRACE_MARK(name) \ - ((void)testspr::trace_stack::instance().notify_mark(name, __FILE__, __LINE__)) + ((void)testspr::trace_stack::instance().notify_mark(testspr::to_string(name), __FILE__, __LINE__)) // // TESTSPR_PRINT_TRACE_STACK