Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r59145 - in sandbox/chrono/boost/chrono: . detail
From: vicente.botet_at_[hidden]
Date: 2010-01-19 17:47:20


Author: viboes
Date: 2010-01-19 17:47:19 EST (Tue, 19 Jan 2010)
New Revision: 59145
URL: http://svn.boost.org/trac/boost/changeset/59145

Log:
Boost.Chrono: Version 0.3.1,
* wide characters debug update
* added helper adaptive_string
* separate static_assert
* change BOOST_CONST_EXPR by BOOST_CHRONO_CONST_EXPR
* add static assertions to stopclock and stopclock_accumulator

Added:
   sandbox/chrono/boost/chrono/detail/static_assert.hpp (contents, props changed)
   sandbox/chrono/boost/chrono/detail/wide.hpp (contents, props changed)
Text files modified:
   sandbox/chrono/boost/chrono/chrono.hpp | 63 ++++++++++++---------------------------
   sandbox/chrono/boost/chrono/config.hpp | 11 ++++++
   sandbox/chrono/boost/chrono/digital_time_formatter.hpp | 46 ++++++++++++++++++++++------
   sandbox/chrono/boost/chrono/stopclock.hpp | 22 +++++++++++++
   sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp | 56 ++++++++++++++++++++++------------
   sandbox/chrono/boost/chrono/stopwatch_formatter.hpp | 49 +++++++++++++++++++++++-------
   sandbox/chrono/boost/chrono/time_formatter.hpp | 45 +++++++++++++++++++++------
   7 files changed, 193 insertions(+), 99 deletions(-)

Modified: sandbox/chrono/boost/chrono/chrono.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/chrono.hpp (original)
+++ sandbox/chrono/boost/chrono/chrono.hpp 2010-01-19 17:47:19 EST (Tue, 19 Jan 2010)
@@ -58,18 +58,16 @@
 
 #ifndef BOOST_CHRONO_HPP
 #define BOOST_CHRONO_HPP
+
+#include <boost/chrono/config.hpp>
+#include <boost/chrono/detail/static_assert.hpp>
+
 #include <iostream>
 
 #include <ctime>
 #include <climits>
 #include <limits>
 
-#include <boost/chrono/config.hpp>
-#if defined(BOOST_NO_CONSTEXPR)
-#define BOOST_CONSTEXPR
-#else
-#define BOOST_CONSTEXPR constexpr
-#endif
 
 #include <boost/ratio.hpp>
 #include <boost/type_traits/common_type.hpp>
@@ -86,21 +84,6 @@
 #define BOOST_CHRONO_SECOND_TEMPLATE_PARAMETER_OF_TIME_POINT_MUST_BE_A_BOOST_CHRONO_DURATION "Second template parameter of time_point must be a boost::chrono::duration"
 #endif
 
-#ifndef BOOST_NO_STATIC_ASSERT
-#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES) static_assert(CND,MSG)
-#elif defined(BOOST_CHRONO_USES_STATIC_ASSERT)
-#include <boost/static_assert.hpp>
-#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES) BOOST_STATIC_ASSERT(CND)
-#elif defined(BOOST_CHRONO_USES_MPL_ASSERT)
-#include <boost/mpl/assert.hpp>
-#include <boost/mpl/bool.hpp>
-#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES) \
- BOOST_MPL_ASSERT_MSG(boost::mpl::bool_< (CND) >::type::value, MSG, TYPES)
-#elif defined(BOOST_CHRONO_USES_ARRAY_ASSERT)
-#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES) static char BOOST_JOIN(__boost_chrono_test_,__LINE__)[CND];
-#else
-#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES)
-#endif
 
 #ifdef BOOST_CHRONO_WINDOWS_API
 // The system_clock tick is 100 nanoseconds
@@ -474,12 +457,12 @@
   template <class Rep>
   struct duration_values
   {
- static BOOST_CONSTEXPR Rep m_min_imp(boost::false_type) {return -max();}
- static BOOST_CONSTEXPR Rep m_min_imp(boost::true_type) {return zero();}
+ static BOOST_CHRONO_CONSTEXPR Rep m_min_imp(boost::false_type) {return -max();}
+ static BOOST_CHRONO_CONSTEXPR Rep m_min_imp(boost::true_type) {return zero();}
   public:
- static BOOST_CONSTEXPR Rep zero() {return Rep(0);}
- static BOOST_CONSTEXPR Rep max BOOST_PREVENT_MACRO_SUBSTITUTION () {return (std::numeric_limits<Rep>::max)();}
- static BOOST_CONSTEXPR Rep min BOOST_PREVENT_MACRO_SUBSTITUTION () {return m_min_imp(boost::is_unsigned<Rep>());}
+ static BOOST_CHRONO_CONSTEXPR Rep zero() {return Rep(0);}
+ static BOOST_CHRONO_CONSTEXPR Rep max BOOST_PREVENT_MACRO_SUBSTITUTION () {return (std::numeric_limits<Rep>::max)();}
+ static BOOST_CHRONO_CONSTEXPR Rep min BOOST_PREVENT_MACRO_SUBSTITUTION () {return m_min_imp(boost::is_unsigned<Rep>());}
   };
 
 } // namespace chrono
@@ -526,9 +509,9 @@
         rep rep_;
     public:
 
- BOOST_CONSTEXPR duration() { } // = default;
+ BOOST_CHRONO_CONSTEXPR duration() { } // = default;
         template <class Rep2>
- BOOST_CONSTEXPR explicit duration(const Rep2& r,
+ BOOST_CHRONO_CONSTEXPR explicit duration(const Rep2& r,
             typename boost::enable_if_c
                 <
                 ( boost::is_convertible<Rep2, rep>::value
@@ -549,7 +532,7 @@
 
         // conversions
         template <class Rep2, class Period2>
- BOOST_CONSTEXPR duration(const duration<Rep2, Period2>& d,
+ BOOST_CHRONO_CONSTEXPR duration(const duration<Rep2, Period2>& d,
             typename boost::enable_if_c
                 <
                 ( treat_as_floating_point<rep>::value
@@ -570,7 +553,7 @@
 
         // observer
 
- BOOST_CONSTEXPR rep count() const {return rep_;}
+ BOOST_CHRONO_CONSTEXPR rep count() const {return rep_;}
 
         // arithmetic
 
@@ -590,9 +573,9 @@
         duration& operator%=(const duration& rhs) {rep_ %= rhs.count(); return *this;};
         // 20.9.3.4 duration special values [time.duration.special]
 
- static BOOST_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());}
- static BOOST_CONSTEXPR duration min BOOST_PREVENT_MACRO_SUBSTITUTION () {return duration((duration_values<rep>::min)());}
- static BOOST_CONSTEXPR duration max BOOST_PREVENT_MACRO_SUBSTITUTION () {return duration((duration_values<rep>::max)());}
+ static BOOST_CHRONO_CONSTEXPR duration zero() {return duration(duration_values<rep>::zero());}
+ static BOOST_CHRONO_CONSTEXPR duration min BOOST_PREVENT_MACRO_SUBSTITUTION () {return duration((duration_values<rep>::min)());}
+ static BOOST_CHRONO_CONSTEXPR duration max BOOST_PREVENT_MACRO_SUBSTITUTION () {return duration((duration_values<rep>::max)());}
     };
 
 //----------------------------------------------------------------------------//
@@ -865,8 +848,8 @@
 
       // special values
 
- static BOOST_CONSTEXPR time_point min BOOST_PREVENT_MACRO_SUBSTITUTION () {return time_point((duration::min)());}
- static BOOST_CONSTEXPR time_point max BOOST_PREVENT_MACRO_SUBSTITUTION () {return time_point((duration::max)());}
+ static BOOST_CHRONO_CONSTEXPR time_point min BOOST_PREVENT_MACRO_SUBSTITUTION () {return time_point((duration::min)());}
+ static BOOST_CHRONO_CONSTEXPR time_point max BOOST_PREVENT_MACRO_SUBSTITUTION () {return time_point((duration::max)());}
   };
 
 //----------------------------------------------------------------------------//
@@ -1075,7 +1058,7 @@
     // see comment above in section 20.9.3 Class template duration [time.duration]
     template <class Rep, class Period>
     template <class Rep2, class Period2>
- BOOST_CONSTEXPR duration<Rep, Period>::duration(const duration<Rep2, Period2>& d,
+ BOOST_CHRONO_CONSTEXPR duration<Rep, Period>::duration(const duration<Rep2, Period2>& d,
         typename boost::enable_if_c
             <
             ( treat_as_floating_point<rep>::value
@@ -1091,12 +1074,4 @@
 
 #include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
 
-#ifdef BOOST_CONSTEXPR
-#undef BOOST_CONSTEXPR
-#endif
-
-#ifdef BOOST_CHRONO_STATIC_ASSERT
-#undef BOOST_CHRONO_STATIC_ASSERT
-#endif
-
 #endif // BOOST_CHRONO_HPP

Modified: sandbox/chrono/boost/chrono/config.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/config.hpp (original)
+++ sandbox/chrono/boost/chrono/config.hpp 2010-01-19 17:47:19 EST (Tue, 19 Jan 2010)
@@ -81,6 +81,17 @@
 #define BOOST_CHRONO_DECL
 #endif
 
+// define constexpr related macros ------------------------------//
+
+#include <boost/chrono/config.hpp>
+#if defined(BOOST_NO_CONSTEXPR)
+#define BOOST_CHRONO_CONSTEXPR
+#define BOOST_CHRONO_CONST_REF const&
+#else
+#define BOOST_CHRONO_CONSTEXPR constexpr
+#define BOOST_CHRONO_CONST_REF
+#endif
+
 // enable automatic library variant selection ------------------------------//
 
 #if !defined(BOOST_CHRONO_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_CHRONO_NO_LIB)

Added: sandbox/chrono/boost/chrono/detail/static_assert.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/detail/static_assert.hpp 2010-01-19 17:47:19 EST (Tue, 19 Jan 2010)
@@ -0,0 +1,30 @@
+// static_assert.hpp --------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0.
+// See http://www.boost.org/LICENSE_1_0.txt
+
+
+#ifndef BOOST_CHRONO_DETAIL_STATIC_ASSERT__HPP
+#define BOOST_CHRONO_DETAIL_STATIC_ASSERT__HPP
+
+#include <boost/chrono/config.hpp>
+
+#ifndef BOOST_NO_STATIC_ASSERT
+#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES) static_assert(CND,MSG)
+#elif defined(BOOST_CHRONO_USES_STATIC_ASSERT)
+#include <boost/static_assert.hpp>
+#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES) BOOST_STATIC_ASSERT(CND)
+#elif defined(BOOST_CHRONO_USES_MPL_ASSERT)
+#include <boost/mpl/assert.hpp>
+#include <boost/mpl/bool.hpp>
+#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES) \
+ BOOST_MPL_ASSERT_MSG(boost::mpl::bool_< (CND) >::type::value, MSG, TYPES)
+#elif defined(BOOST_CHRONO_USES_ARRAY_ASSERT)
+#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES) static char BOOST_JOIN(__boost_chrono_test_,__LINE__)[CND];
+#else
+#define BOOST_CHRONO_STATIC_ASSERT(CND, MSG, TYPES)
+#endif
+
+#endif // BOOST_CHRONO_DETAIL_STATIC_ASSERT__HPP

Added: sandbox/chrono/boost/chrono/detail/wide.hpp
==============================================================================
--- (empty file)
+++ sandbox/chrono/boost/chrono/detail/wide.hpp 2010-01-19 17:47:19 EST (Tue, 19 Jan 2010)
@@ -0,0 +1,73 @@
+// boost/chrono/stopwatch_formatter.hpp ------------------------------------------------------------//
+
+// Copyright 2009-2010 Vicente J. Botet Escriba
+
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// See http://www.boost.org/libs/system for documentation.
+
+#ifndef BOOST_CHRONO_DETAIL_ADAPTIVE_STRING__HPP
+#define BOOST_CHRONO_DETAIL_ADAPTIVE_STRING__HPP
+
+#include <string>
+
+namespace boost { namespace chrono {
+
+namespace detail {
+
+ /**
+ * this class is a shim between std::string type and wchar_t type.
+ * it accepts a std::string type and returns a std::string or
+ * std::wstring according to the context(e.g. type on the left side
+ * of '=' operator):
+ * - in case of a string type, it forwards the passed-in std::string
+ * - in case of a wstring type, it widens it passed-in std::string
+ * before forwarding
+ *
+ * typical usage:
+ * std::string s = adaptive_string("hello"); // s = "hello"
+ * std::wstring ws = adaptive_string("hello"); // ws = L"hello"
+ * N.B. it doe not do any code conversion like: MBCS <--> UNICODE
+ */
+
+ struct adaptive_string
+ {
+ adaptive_string(const std::string& s):str_(s)
+ {}
+
+ // implicit convert to string
+ template <
+ typename Traits,
+ class Alloc
+ >
+ operator std::basic_string<char, Traits, Alloc>() const
+ {
+ //return str_;
+ std::basic_string<char, Traits, Alloc> s;
+ s.assign(str_.begin(), str_.end());
+ return s;
+ }
+ // implicit convert to wstring
+ template <
+ typename Traits,
+ class Alloc
+ >
+ operator std::basic_string<wchar_t, Traits, Alloc>() const
+ {
+ std::basic_string<wchar_t, Traits, Alloc> ws;
+ ws.assign(str_.begin(), str_.end());
+ return ws;
+ }
+
+ private:
+ const std::string& str_;
+ };
+
+
+} // namespace detail
+} // namespace chrono
+} // namespace boost
+
+
+#endif

Modified: sandbox/chrono/boost/chrono/digital_time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/digital_time_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/digital_time_formatter.hpp 2010-01-19 17:47:19 EST (Tue, 19 Jan 2010)
@@ -14,6 +14,7 @@
 #include <boost/chrono/digital_time.hpp>
 #include <boost/current_function.hpp>
 #include <boost/chrono/detail/default_out.hpp>
+#include <boost/chrono/detail/wide.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/cstdint.hpp>
 #include <string>
@@ -24,6 +25,7 @@
 
 #include <boost/config/abi_prefix.hpp> // must be the last #include
 
+#define BOOST_CHRONO_DIGITAL_TIME_FORMAT_DEFAULT "%d day(s) %h:%m:%s.%n\n"
 
 namespace boost { namespace chrono {
 
@@ -47,15 +49,15 @@
         typedef std::basic_ostream<CharT,Traits> ostream_type;
 
         static ostream_type & default_os();
- static const int m_default_places = 3;
- static const char_type* m_default_format;
- static const char_type* default_format() { return m_default_format; }
+ static const char_type* default_format();
         static string_type format(const char_type* s) {
             string_type res(s);
- res += " tokes %d day(s) %h:%m:%s.%n\n";
+ res += boost::chrono::detail::adaptive_string(" : ");
+ res += default_format();
+ //res += boost::chrono::detail::adaptive_string(" tokes %d day(s) %h:%m:%s.%n\n");
             return res;
         }
- static int default_places() { return m_default_places; }
+ static int default_places() { return 3; }
 
         template <class Stopwatch >
         static void show_time( Stopwatch & stopwatch_
@@ -64,10 +66,11 @@
         // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
         // be as low as 10, although will be 15 for many common platforms.
         {
- typedef typename Stopwatch::duration duration;
- duration d = stopwatch_.elapsed( ec );
+ typedef typename Stopwatch::duration duration_t;
+ duration_t d = stopwatch_.elapsed( ec );
+ duration_t d0((0));
 
- if ( d < duration(0) ) return;
+ if ( d < d0 ) return;
 
             boost::io::ios_flags_saver ifs( os );
             os.setf( std::ios_base::fixed, std::ios_base::floatfield );
@@ -119,13 +122,34 @@
             }
         }
     };
+
+namespace detail {
+ template <typename CharT>
+ struct basic_digital_time_formatter_default_format;
+ template <>
+ struct basic_digital_time_formatter_default_format<char> {
+ static const char* apply() {return BOOST_CHRONO_DIGITAL_TIME_FORMAT_DEFAULT; }
+ };
+#ifndef BOOST_NO_STD_WSTRING
+ template <>
+ struct basic_digital_time_formatter_default_format<wchar_t> {
+ static const wchar_t* apply() {return L"%d day(s) %h:%m:%s.%n\n"; }
+ };
+
+#endif
+}
+
     template <typename CharT,typename Traits, class Alloc>
     const typename basic_digital_time_formatter<CharT,Traits,Alloc>::char_type*
- basic_digital_time_formatter<CharT,Traits,Alloc>::m_default_format ="%d day(s) %h:%m:%s.%n\n";
+ basic_digital_time_formatter<CharT,Traits,Alloc>::default_format() {
+ return detail::basic_stopwatch_formatter_default_format<CharT>::apply();
+ }
 
     template <typename CharT,typename Traits, class Alloc>
     typename basic_digital_time_formatter<CharT,Traits,Alloc>::ostream_type &
- basic_digital_time_formatter<CharT,Traits,Alloc>::default_os() { return detail::default_out<CharT,Traits>::apply(); }
+ basic_digital_time_formatter<CharT,Traits,Alloc>::default_os() {
+ return detail::default_out<CharT,Traits>::apply();
+ }
 
     typedef basic_digital_time_formatter<char> digital_time_formatter;
     typedef basic_digital_time_formatter<wchar_t> wdigital_time_formatter;
@@ -133,7 +157,7 @@
   } // namespace chrono
 } // namespace boost
 
-#define BOOST_CHRONO_DIGITAL_TIME_FORMAT(F) F " tokes %d day(s) %h:%m:%s.%n\n"
+#define BOOST_CHRONO_DIGITAL_TIME_FORMAT(F) boost::chrono::detail::adaptive_string(F " : " BOOST_CHRONO_DIGITAL_TIME_FORMAT_DEFAULT)
 #ifdef __GNUC__
 #define BOOST_CHRONO_DIGITAL_TIME_FUNCTION_FORMAT boost::chrono::digital_time_formatter::format(BOOST_CURRENT_FUNCTION)
 #else

Modified: sandbox/chrono/boost/chrono/stopclock.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopclock.hpp (original)
+++ sandbox/chrono/boost/chrono/stopclock.hpp 2010-01-19 17:47:19 EST (Tue, 19 Jan 2010)
@@ -10,13 +10,21 @@
 #ifndef BOOST_CHRONO_STOPCLOCK_HPP
 #define BOOST_CHRONO_STOPCLOCK_HPP
 
+#include <boost/chrono/config.hpp>
+#include <boost/chrono/detail/static_assert.hpp>
 #include <boost/chrono/stopwatch_reporter.hpp>
 #include <boost/chrono/stopwatch.hpp>
+//#include <boost/chrono/chrono.hpp>
 #include <boost/chrono/process_cpu_clocks.hpp>
 #include <boost/chrono/time_formatter.hpp>
+#include <boost/type_traits/is_same.hpp>
 
 #include <boost/config/abi_prefix.hpp> // must be the last #include
 
+#ifndef BOOST_CHRONO_USES_MPL_ASSERT
+#define BOOST_CHRONO_S_STOPWATCH_CLOCK_MUST_BE_CLOCK "Stopwatch::clock must be the same as Clock"
+#endif
+
 namespace boost { namespace chrono {
 
 //--------------------------------------------------------------------------------------//
@@ -40,7 +48,18 @@
 //--------------------------------------------------------------------------------------//
 
     template <class Clock=process_cpu_clock, class Stopwatch=stopwatch<Clock>, class Formatter=typename stopwatch_reporter_default_formatter<Stopwatch>::type>
+ class stopclock;
+
+ template <class Clock, class Stopwatch, class Formatter>
+ struct stopwatch_reporter_default_formatter<stopclock<Clock,Stopwatch, Formatter> > {
+ typedef typename stopwatch_reporter_default_formatter<Stopwatch>::type type;
+ };
+
+ template <class Clock, class Stopwatch, class Formatter>
     class stopclock : public stopwatch_reporter<Stopwatch, Formatter> {
+ BOOST_CHRONO_STATIC_ASSERT((boost::is_same<typename Stopwatch::clock, Clock>::value),
+ BOOST_CHRONO_S_STOPWATCH_CLOCK_MUST_BE_CLOCK, (Stopwatch)(Stopwatch::clock)(Clock));
+
         typedef stopwatch_reporter<Stopwatch, Formatter> base_type;
     public:
         typedef Clock clock;
@@ -49,7 +68,7 @@
         typedef typename Formatter::string_type string_type;
         typedef typename Formatter::char_type char_type;
         typedef typename Formatter::ostream_type ostream_type;
-
+
         explicit stopclock( system::error_code & ec = system::throws )
         : base_type(ec) { }
         explicit stopclock( ostream_type & os,
@@ -104,6 +123,7 @@
     typedef stopclock< boost::chrono::process_system_cpu_clock > process_system_cpu_stopclock;
     //typedef stopclock< boost::chrono::process_cpu_clock > process_cpu_stopclock;
 
+
   } // namespace chrono
 } // namespace boost
 

Modified: sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_accumulator_formatter.hpp 2010-01-19 17:47:19 EST (Tue, 19 Jan 2010)
@@ -14,6 +14,7 @@
 #include <boost/system/error_code.hpp>
 #include <boost/current_function.hpp>
 #include <boost/chrono/detail/default_out.hpp>
+#include <boost/chrono/detail/wide.hpp>
 #include <boost/accumulators/accumulators.hpp>
 #include <boost/accumulators/statistics.hpp>
 #include <boost/accumulators/framework/accumulator_set.hpp>
@@ -21,7 +22,6 @@
 #include <boost/accumulators/statistics/min.hpp>
 #include <boost/accumulators/statistics/max.hpp>
 #include <boost/accumulators/statistics/mean.hpp>
-//#include <boost/chrono/stopwatch_accumulator.hpp>
 #include <boost/cstdint.hpp>
 #include <string>
 #include <iostream>
@@ -31,6 +31,8 @@
 
 #include <boost/config/abi_prefix.hpp> // must be the last #include
 
+#define BOOST_CHRONO_ACCUMULATOR_FORMAT_DEFAULT "%c times, sum=%ss, min=%ms, max=%Ms, mean=%as\n"
+
 
 namespace boost { namespace chrono {
 
@@ -43,25 +45,20 @@
         class Alloc=std::allocator<CharT>
>
     class basic_stopwatch_accumulator_formatter {
- public:
- //~ typedef std::string string_type;
- //~ typedef string_type::value_type char_type;
- //~ typedef std::ostream ostream_type;
-
+ public:
         typedef std::basic_string<CharT,Traits,Alloc> string_type;
         typedef CharT char_type;
         typedef std::basic_ostream<CharT,Traits> ostream_type;
     
         static ostream_type & default_os();
- static const int m_default_places = 3;
- static const char_type* m_default_format;
- static const char_type* default_format() { return m_default_format; }
+ static const char_type* default_format();
         static string_type format(const char_type* s) {
             string_type res(s);
- res += " called %c times, sum=%ss, min=%ms, max=%Ms, mean=%as\n";
+ res += boost::chrono::detail::adaptive_string(" : ");
+ res += default_format();
             return res;
         }
- static int default_places() { return m_default_places; }
+ static int default_places() { return 3; }
 
         template <class Stopwatch >
         static void show_time( Stopwatch & stopwatch_, const char_type* format, int places, ostream_type & os, system::error_code & ec)
@@ -69,10 +66,11 @@
         // be as low as 10, although will be 15 for many common platforms.
         {
             typedef typename Stopwatch::accumulator accumulator;
- typedef typename Stopwatch::duration duration;
+ typedef typename Stopwatch::duration duration_t;
             accumulator& acc = stopwatch_.accumulated();
+ //duration_t d0((0));
 
- //if ( d < duration(0) ) return;
+ //if ( d < d0 ) return;
             if ( places > 9 )
                 places = 9; // sanity check
             else if ( places < 0 )
@@ -91,17 +89,17 @@
                     ++format;
                     switch ( *format ) {
                     case 's':
- os << boost::chrono::duration<double>(duration(accumulators::sum(acc))).count();
+ os << boost::chrono::duration<double>(duration_t(accumulators::sum(acc))).count();
                         break;
                     case 'm':
- os << boost::chrono::duration<double>(duration((accumulators::min)(acc))).count();
+ os << boost::chrono::duration<double>(duration_t((accumulators::min)(acc))).count();
                         break;
                     case 'M':
- os << boost::chrono::duration<double>(duration((accumulators::max)(acc))).count();
+ os << boost::chrono::duration<double>(duration_t((accumulators::max)(acc))).count();
                         break;
                     case 'a':
                         os << ((accumulators::count(acc)>0)
- ? (boost::chrono::duration<double>(duration(accumulators::sum(acc))).count())/accumulators::count(acc)
+ ? (boost::chrono::duration<double>(duration_t(accumulators::sum(acc))).count())/accumulators::count(acc)
                                 : 0);
                         break;
                     case 'c':
@@ -114,10 +112,28 @@
             }
         }
     };
-
+
+namespace detail {
+ template <typename CharT>
+ struct basic_stopwatch_accumulator_formatter_default_format;
+ template <>
+ struct basic_stopwatch_accumulator_formatter_default_format<char> {
+ static const char* apply() {return BOOST_CHRONO_ACCUMULATOR_FORMAT_DEFAULT; }
+ };
+#ifndef BOOST_NO_STD_WSTRING
+ template <>
+ struct basic_stopwatch_accumulator_formatter_default_format<wchar_t> {
+ static const wchar_t* apply() {return L"%c times, sum=%ss, min=%ms, max=%Ms, mean=%as\n"; }
+ };
+
+#endif
+}
+
     template <typename CharT,typename Traits, class Alloc>
     const typename basic_stopwatch_accumulator_formatter<CharT,Traits,Alloc>::char_type*
- basic_stopwatch_accumulator_formatter<CharT,Traits,Alloc>::m_default_format ="%c times, sum=%ss, min=%ms, max=%Ms, mean=%as\n";
+ basic_stopwatch_accumulator_formatter<CharT,Traits,Alloc>::default_format() {
+ return detail::basic_stopwatch_accumulator_formatter_default_format<CharT>::apply();
+ }
 
     template <typename CharT,typename Traits, class Alloc>
     typename basic_stopwatch_accumulator_formatter<CharT,Traits,Alloc>::ostream_type &
@@ -129,7 +145,7 @@
 } // namespace chrono
 } // namespace boost
 
-#define BOOST_CHRONO_ACCUMULATOR_FORMAT(F) F" called %c times, sum=%ss, min=%ms, max=%Ms, mean=%as\n"
+#define BOOST_CHRONO_ACCUMULATOR_FORMAT(F) boost::chrono::detail::adaptive_string(F " : " BOOST_CHRONO_ACCUMULATOR_FORMAT_DEFAULT)
 #ifdef __GNUC__
 #define BOOST_CHRONO_ACCUMULATOR_FUNCTION_FORMAT boost::chrono::stopwatch_accumulator_formatter::format(BOOST_CURRENT_FUNCTION)
 #else

Modified: sandbox/chrono/boost/chrono/stopwatch_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/stopwatch_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/stopwatch_formatter.hpp 2010-01-19 17:47:19 EST (Tue, 19 Jan 2010)
@@ -14,6 +14,7 @@
 #include <boost/system/error_code.hpp>
 #include <boost/current_function.hpp>
 #include <boost/chrono/detail/default_out.hpp>
+#include <boost/chrono/detail/wide.hpp>
 #include <boost/cstdint.hpp>
 #include <string>
 #include <iostream>
@@ -23,6 +24,8 @@
 
 #include <boost/config/abi_prefix.hpp> // must be the last #include
 
+#define BOOST_CHRONO_STOPWATCH_FORMAT_DEFAULT "%ds\n"
+
 namespace boost { namespace chrono {
 
 //--------------------------------------------------------------------------------------//
@@ -45,25 +48,26 @@
         typedef std::basic_ostream<CharT,Traits> ostream_type;
         
         static ostream_type & default_os();
- static const int m_default_places = 3;
- static const char_type* m_default_format;
- static const char_type* default_format() { return m_default_format; }
+ static const char_type* default_format();
         static string_type format(const char_type* s) {
             string_type res(s);
- res += " tokes %ds\n";
+ //res += boost::chrono::detail::adaptive_string(" tokes %ds\n");
+ res += boost::chrono::detail::adaptive_string(" : ");
+ res += default_format();
             return res;
         }
- static int default_places() { return m_default_places; }
+ static int default_places() { return 3; }
 
         template <class Stopwatch >
         static void show_time( Stopwatch & stopwatch_, const char_type* format, int places, ostream_type & os, system::error_code & ec)
         // NOTE WELL: Will truncate least-significant digits to LDBL_DIG, which may
         // be as low as 10, although will be 15 for many common platforms.
         {
- typedef typename Stopwatch::duration duration;
- duration d = stopwatch_.elapsed( ec );
+ typedef typename Stopwatch::duration duration_t;
+ duration_t d = stopwatch_.elapsed( ec );
+ duration_t d0((0));
 
- if ( d < duration(0) ) return;
+ if ( d < d0 ) return;
             if ( places > 9 )
                 places = 9; // sanity check
             else if ( places < 0 )
@@ -90,13 +94,34 @@
             }
         }
     };
+
+namespace detail {
+ template <typename CharT>
+ struct basic_stopwatch_formatter_default_format;
+ template <>
+ struct basic_stopwatch_formatter_default_format<char> {
+ static const char* apply() {return BOOST_CHRONO_STOPWATCH_FORMAT_DEFAULT; }
+ };
+#ifndef BOOST_NO_STD_WSTRING
+ template <>
+ struct basic_stopwatch_formatter_default_format<wchar_t> {
+ static const wchar_t* apply() {return L"%ds\n"; }
+ };
+
+#endif
+}
+
     template <typename CharT,typename Traits, class Alloc>
     const typename basic_stopwatch_formatter<CharT,Traits,Alloc>::char_type*
- basic_stopwatch_formatter<CharT,Traits,Alloc>::m_default_format ="%ds\n";
-
+ basic_stopwatch_formatter<CharT,Traits,Alloc>::default_format() {
+ return detail::basic_stopwatch_formatter_default_format<CharT>::apply();
+ }
+
     template <typename CharT,typename Traits, class Alloc>
     typename basic_stopwatch_formatter<CharT,Traits,Alloc>::ostream_type &
- basic_stopwatch_formatter<CharT,Traits,Alloc>::default_os() { return detail::default_out<CharT,Traits>::apply(); }
+ basic_stopwatch_formatter<CharT,Traits,Alloc>::default_os() {
+ return detail::default_out<CharT,Traits>::apply();
+ }
 
     typedef basic_stopwatch_formatter<char> stopwatch_formatter;
     typedef basic_stopwatch_formatter<wchar_t> wstopwatch_formatter;
@@ -104,7 +129,7 @@
   } // namespace chrono
 } // namespace boost
 
-#define BOOST_CHRONO_STOPWATCH_FORMAT(F) F " tokes %ds\n"
+#define BOOST_CHRONO_STOPWATCH_FORMAT(F) boost::chrono::detail::adaptive_string(F " : " BOOST_CHRONO_STOPWATCH_FORMAT_DEFAULT)
 #ifdef __GNUC__
 #define BOOST_CHRONO_STOPWATCH_FUNCTION_FORMAT boost::chrono::stopwatch_formatter::format(BOOST_CURRENT_FUNCTION)
 #else

Modified: sandbox/chrono/boost/chrono/time_formatter.hpp
==============================================================================
--- sandbox/chrono/boost/chrono/time_formatter.hpp (original)
+++ sandbox/chrono/boost/chrono/time_formatter.hpp 2010-01-19 17:47:19 EST (Tue, 19 Jan 2010)
@@ -14,6 +14,7 @@
 #include <boost/chrono/process_cpu_clocks.hpp>
 #include <boost/current_function.hpp>
 #include <boost/chrono/detail/default_out.hpp>
+#include <boost/chrono/detail/wide.hpp>
 #include <boost/system/error_code.hpp>
 #include <boost/cstdint.hpp>
 #include <string>
@@ -25,6 +26,8 @@
 #include <boost/config/abi_prefix.hpp> // must be the last #include
 
 
+#define BOOST_CHRONO_TIME_FORMAT_DEFAULT "real %rs, cpu %cs (%p%), user %us, system %ss\n"
+
 
 namespace boost { namespace chrono {
 
@@ -48,15 +51,15 @@
         typedef std::basic_ostream<CharT,Traits> ostream_type;
 
         static ostream_type & default_os();
- static const int m_default_places = 3;
- static const char_type* m_default_format;
- static const char_type* default_format() { return m_default_format; }
+ static const char_type* default_format();
         static string_type format(const char_type* s) {
             string_type res(s);
- res += " spent real %rs, cpu %cs (%p%), user %us, system %ss\n";
+ res += boost::chrono::detail::adaptive_string(" : ");
+ res += default_format();
+ //res += boost::chrono::detail::adaptive_string(" spent real %rs, cpu %cs (%p%), user %us, system %ss\n");
             return res;
         }
- static int default_places() { return m_default_places; }
+ static int default_places() { return 3; }
 
         template <class Stopwatch >
         static void show_time( Stopwatch & stopwatch_
@@ -122,27 +125,47 @@
           }
 
     };
+
+namespace detail {
+ template <typename CharT>
+ struct basic_time_formatter_default_format;
+ template <>
+ struct basic_time_formatter_default_format<char> {
+ static const char* apply() {return BOOST_CHRONO_TIME_FORMAT_DEFAULT; }
+ };
+#ifndef BOOST_NO_STD_WSTRING
+ template <>
+ struct basic_time_formatter_default_format<wchar_t> {
+ static const wchar_t* apply() {return L"real %rs, cpu %cs (%p%), user %us, system %ss\n"; }
+ };
+
+#endif
+}
+
     template <typename CharT,typename Traits, class Alloc>
     const typename basic_time_formatter<CharT,Traits,Alloc>::char_type*
- basic_time_formatter<CharT,Traits,Alloc>::m_default_format = "real %rs, cpu %cs (%p%), user %us, system %ss\n";
+ basic_time_formatter<CharT,Traits,Alloc>::default_format() {
+ return detail::basic_time_formatter_default_format<CharT>::apply();
+ }
 
     template <typename CharT,typename Traits, class Alloc>
     typename basic_time_formatter<CharT,Traits,Alloc>::ostream_type &
- basic_time_formatter<CharT,Traits,Alloc>::default_os() { return detail::default_out<CharT,Traits>::apply(); }
-
+ basic_time_formatter<CharT,Traits,Alloc>::default_os() {
+ return detail::default_out<CharT,Traits>::apply();
+ }
+
     typedef basic_time_formatter<char> time_formatter;
     typedef basic_time_formatter<wchar_t> wtime_formatter;
-
+
     template <>
     struct stopwatch_reporter_default_formatter<stopwatch<process_cpu_clock> > {
         typedef time_formatter type;
     };
 
-
   } // namespace chrono
 } // namespace boost
 
-#define BOOST_CHRONO_TIME_FORMAT(F) F" spent real %rs, cpu %cs (%p%), user %us, system %ss\n"
+#define BOOST_CHRONO_TIME_FORMAT(F) boost::chrono::detail::adaptive_string(F " : " BOOST_CHRONO_TIME_FORMAT_DEFAULT)
 #ifdef __GNUC__
 #define BOOST_CHRONO_TIME_FUNCTION_FORMAT boost::chrono::time_formatter::format(BOOST_CURRENT_FUNCTION)
 #else


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk