|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r63337 - in sandbox/chrono/libs/chrono/doc: . html html/boost_chrono html/boost_chrono/appendices html/boost_chrono/examples html/boost_chrono/overview html/boost_chrono/reference html/boost_chrono/users_guide
From: vicente.botet_at_[hidden]
Date: 2010-06-25 22:51:41
Author: viboes
Date: 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
New Revision: 63337
URL: http://svn.boost.org/trac/boost/changeset/63337
Log:
* Overview rewriting
* Added missing thread_clock reference.
* How to implement a thread_clock tutorial removed.
* References section renamed to External Resources.
* Added links to source examples.
* Added links between Models and Concepts.
* Added macros descriptions.
* Cleanup.
Added:
sandbox/chrono/libs/chrono/doc/html/boost_chrono/overview/caveat.html (contents, props changed)
sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/examples.html (contents, props changed)
Text files modified:
sandbox/chrono/libs/chrono/doc/chrono.qbk | 6216 ++++++++++++++++++++-------------------
sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices.html | 16
sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/faq.html | 14
sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/history.html | 109
sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/perf.html | 4
sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/rationale.html | 8
sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/todo.html | 4
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/a_tiny_program_that_times_how_long_until_a_key_is_struck.html | 3
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/cycle_count.html | 2
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/how_you_override_the_duration_s_default_constructor.html | 2
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/howard_hinnant_s_original_demonstration_program.html | 2
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/min_utility.html | 3
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/runtime_resolution.html | 2
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/saturating.html | 2
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/si_units.html | 3
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/simulated_thread_interface_demonstration_program.html | 3
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/stopclock_example2_cpp.html | 3
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/stopclock_example_cpp.html | 3
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/time_command.html | 3
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/xtime_clock.html | 3
sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/xtime_conversions.html | 3
sandbox/chrono/libs/chrono/doc/html/boost_chrono/overview.html | 162
sandbox/chrono/libs/chrono/doc/html/boost_chrono/overview/motivation.html | 145
sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference.html | 21
sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/cpp0x.html | 61
sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/deprecated_headers.html | 8
sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/other_clocks.html | 396 ++
sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/stopwatch_reporters.html | 36
sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/stopwatches.html | 56
sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide.html | 56
sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/ext_references.html | 10
sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/getting_started.html | 53
sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/tutorial.html | 415 +-
sandbox/chrono/libs/chrono/doc/html/index.html | 30
sandbox/chrono/libs/chrono/doc/html/standalone_HTML.manifest | 18
35 files changed, 4443 insertions(+), 3432 deletions(-)
Modified: sandbox/chrono/libs/chrono/doc/chrono.qbk
==============================================================================
--- sandbox/chrono/libs/chrono/doc/chrono.qbk (original)
+++ sandbox/chrono/libs/chrono/doc/chrono.qbk 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -44,42 +44,50 @@
[heading Description]
[/==================]
-The Boost Chrono library provides:
+The __Boost_Chrono__ library provides:
-* The C++0x Standard Library's `common_type`.
-* The C++0x Standard Library's compile-time rational arithmetic.
-* The C++0x Standard Library's time utilities, including:
- * Class template `duration`
- * Class template `time_point`
- * Clocks:
- * `system_clock`
- * `monotonic_clock`
- * `high_resolution_clock`
- * typeof registration for classes `duration` and `time_point`
+* One facility for representing time durations: `duration`. Examples of time durations include seconds, minutes and nanoseconds. All of these units of time duration are united with a generic interface by the duration facility.
+* One facility for representing points in time: `time_point`. A time_point represents an epoch plus or minus a duration. This paper leaves epochs unspecified. A time_point is associated with a clock.
+* Several clocks, some of which may not be available on any given platform: `system_clock`, `monotonic_clock` and `high_resolution_clock`. A clock is a symbolic bundle of a native `time_point` and `duration`, and a function which returns a `time_point` representing ['now].
-* Process clocks:
- * `process_real_CPU_clocks`, capturing real-CPU times.
- * `process_user_CPU_clocks`, capturing user-CPU times.
- * `process_system_CPU_clocks`, capturing system-CPU times.
- * `process_cpu_clock`, tuple-like class capturing at once real, user-CPU, and system-CPU times.
+Additionally, a minimal amount of general purpose infrastructure is provided which will support both the interface and implementation of the clocks, time_points and durations proposed herein. It is expected that these general purpose facilities will also find utility in far ranging user applications as well.
-* Thread clock
+* common_type is a facility which is useful in specifying the type of the result of functions and operators which take a variety of types (e.g. "mixed mode" complex arithmetic).
+* ratio is a facility which is useful in specifying compile time rational constants. Compile time rational arithmetic is supported with protection against overflow and divide by zero. Such a facility is very handy when needing to efficiently represent 1/3 of a nanosecond, or specifying an inch in terms of meters (for example 254/10000 meters - which ratio will reduce to 127/5000 meters).
-* Suspendible Clock
- * Suspendible Clock concept
- * template class suspendible_clock<>
- * Added scope_suspend which do suspend/resume if the Clock is a model of Suspendible Clock concept, and nothing otherwise.
+Knowing how long a program takes to execute is useful in both test and production environments. On top of the standard facilities __Boost_Chrono__ includes:
-* Stopwatches:
- * `stopwatch`, capturing elapsed Clock times.
- * `stopwatch_accumulator`, capturing cummulated elapsed Clock times.
- * scoped helper classes allowing to pairwise start/stop operations, suspend/resume and resume/suspend a Stopwatch.
+* a Stopwatch middle layer: providing operations to start, stop, suspend or resume a `Stopwatch` to measure the elapsed time.
+ * `Stopwatch` concept
+ * Scoped helper classes allowing to pairwise start/stop operations, suspend/resume and resume/suspend a `Stopwatch`.
+ * `stopwatch`, model of `Stopwatch` capturing elapsed Clock times.
+ * `stopwatch_accumulator`, model of `Stopwatch` capturing cummulated elapsed Clock times.
-* Stopclocks or Stopwatch reporters:
+* a Stopclocks higher layer: provide a complete stopclock reporting package that can be invoked in a single line of code.
* `stopwatch_reporter`, convenient reporting of models of Stopwatch results.
* `stopclock<Clock>` shortcut of `stopwatch_reporter<stopwatch<Clock>>`
* Allows wide characters
+It is also helpful if such timing information is broken down into real (wall clock) time, CPU time spent by the user, and CPU time spent by the operating system servicing user requests. process clocks provide a thin wrapper around the operating system's process timer API. For POSIX-like systems, that's the times() function, while for Windows, it's the GetProcessTimes() function.
+
+* `process_real_CPU_clocks`, capturing real-CPU times.
+* `process_user_CPU_clocks`, capturing user-CPU times.
+* `process_system_CPU_clocks`, capturing system-CPU times.
+* `process_cpu_clock`, tuple-like class capturing at once real, user-CPU, and system-CPU times.
+
+To complete the clocks __Boost_Chrono__ provides, in platforms support them, thread clocks.
+
+
+[/
+
+* Suspendible clock
+ * `SuspendibleClock` concept
+ * scope_suspend which do suspend/resume if the Clock is a model of SuspendibleClock concept, and nothing otherwise.
+ * template class suspendible_clock<>
+]
+
+Last, __Boost_Chrono__ include typeof registration for classes `duration` and `time_point` so you can used auto emulated on C++03 compilers.
+
[/====================================]
[heading How to Use This Documentation]
@@ -110,7 +118,16 @@
[section Motivation]
[/=================]
-See [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]] which is very informative and provides motivation for key design decisions for `common_type`, `ratio` and `chrono`. The following sections are an extract from this document.
+We all deal with time every day of our lives. We've intuitively known it since birth. Thus we are all very familiar with it and believe it to be a simple matter. The modeling of time in computer programs should be similarly simple.
+
+The unfortunate truth is that this perceived simplicity is only skin deep. Fortunately however, we do not need a terribly complicated solution to meet the bulk of our needs. However, overly simplistic solutions are fraught with danger, inherent inefficiency, and lack the ability to adapt as the computer industry evolves over decades.
+
+__Boost_Chrono__ proposes a solution that is precision neutral, with a very simple end user interface which supports multiple clocks, multiple precisions (both coarser and finer than we will ever need), separate types for points in time and time durations, efficiency, and compile time enforced safety.
+
+In addition to the clocks provided by the standard proposal, __Boost_Chrono__ provides specific process clocks and a thread clock.
+
+See [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]] which is very informative and provides motivation for key design decisions for `common_type`, `ratio` and `chrono`. This documentation contains a lot of extracts from this document.
+
[section Common type]
@@ -147,7 +164,7 @@
`ratio` is a general purpose utility inspired by Walter Brown allowing one to easily and safely compute rational values at compile time. The `ratio` class catches all errors (such as divide by zero and overflow) at compile time. It is used in the `duration` and `time_point` classes to efficiently create units of time. It can also be used in other "quantity" libraries (both std-defined and user-defined), or anywhere there is a rational constant which is known at compile time. The use of this utility can greatly reduce the chances of run time overflow because the `ratio` (and any ratios resulting from `ratio` arithmetic) are always reduced to lowest terms.
-`ratio` is a template taking two intmax_ts, with the second defaulted to 1. In addition to cop^y constructors and assignement, it only has two public members, both of which are static const intmax_t. One is the numerator of the `ratio` and the other is the denominator. The `ratio` is always normalized such that it is expressed in lowest terms, and the denominator is always positive. When the numerator is 0, the denominator is always 1.
+`ratio` is a template taking two intmax_ts, with the second defaulted to 1. In addition to copy constructors and assignement, it only has two public members, both of which are static const intmax_t. One is the numerator of the `ratio` and the other is the denominator. The `ratio` is always normalized such that it is expressed in lowest terms, and the denominator is always positive. When the numerator is 0, the denominator is always 1.
[*Example:]
@@ -322,7 +339,7 @@
# A concrete `time_point` type.
# A function called now() which returns the concrete `time_point`.
-__Boost_Chrono__ provides 3 concrete clocks:
+__Boost_Chrono__ provides the standard concrete clocks:
# system_clock
# monotonic_clock
@@ -412,9 +429,9 @@
[section Stopwatches]
Knowing how long a program, a function or a specific block takes to execute is useful in both test and production environments.
-__Boost_Chrono__ introduces the Stopwatch concept which captures the mechanism to measure the elapsed time.
+__Boost_Chrono__ introduces the `Stopwatch` concept which captures the mechanism to measure the elapsed time.
A Stopwatch allows to start, stop, suspend and resume the measure of the eleapsed time.
-`stopwatch<>` is the basic model of Stopwatch allowing to make a single measure.
+`stopwatch<>` is the basic model of `Stopwatch` allowing to make a single measure.
At the user level, the main use case of measuring the elapsed time is to report these measures on the display.
`stopwatch_reporter<>` provides a run time reporting package that can be invoked in a single line of code to report the usage of a Clock.
@@ -507,28 +524,31 @@
[heading How reliable are these measures?]
-[info this section need to be reworked, the ideas are there, but ...]
+[note this section need to be reworked, the ideas are there, but ...]
There are three context on which you can get unreliable measures:
-# the precission of your clock. If the precission of your clock is 10ms you can not be able to measure the time spent by blocks of code that takes the same order of magnitude. The library provides a hig_resolution_clock that gives you the higher resolution available on your platform. Respect to the precission, nothing to do except to take the clock with the highest resolution and measures blocks of code that will spent time having more than one order of magnitude the precission of the clock.
+* Precission of your clock. If the precission of your clock is 10ms you can not be able to measure the time spent by blocks of code that takes the same order of magnitude. The library provides a hig_resolution_clock that gives you the higher resolution available on your platform. Respect to the precission, nothing to do except to take the clock with the highest resolution and measures blocks of code that will spent time having more than one order of magnitude the precission of the clock.
- #include <boost/chrono/thread_clock.hpp>
+```
+#include <boost/chrono/chrono.hpp>
...
- stopclock<high_resolution_clock> _;
+ stopclock<high_resolution_clock> _;
+```
+* When your application is multithreaded, and you use a process clock, the time you get is the delay during which your block has been executed, in concurrency with the other threads of execution. If what you want is the time spent by this specific thread another clock is needed. The library provide a `thread_clock` that returns the time spent by the thread on platforms providing this kind of data. It can be used as follows
-# When your application is multithreaded, and you use a process clock, the time you get is the delay during which your block has been executed, in concurrency with the other threads of execution. If what you want is the time spent by this specific thread another clock is needed. The library provide a thread_clock that returns the time spent by the thread on platforms providing this kind of data. It can be used as follows
-
- #include <boost/chrono/thread_clock.hpp>
- ...
- #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
- stopclock<thread_clock> _;
- #else
- stopclock<process_real_cpu_clock> _;
- #endif
+```
+#include <boost/chrono/thread_clock.hpp>
+...
+#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
+ stopclock<thread_clock> _;
+#else
+ stopclock<process_real_cpu_clock> _;
+#endif
+```
-# Nested stopclocks (usually nested function calls where each function contains a stopclock). When the nesting is deep enough, the cumulative overhead of all the stopclock functionality make the data unreliable except for the inner-most trace points. The question is, how much time is related to the application code we want to measure and how much to the fact we are meassuring and logging in inner blocks?
+* Nested stopclocks (usually nested function calls where each function contains a stopclock). When the nesting is deep enough, the cumulative overhead of all the stopclock functionality make the data unreliable except for the inner-most trace points. The question is, how much time is related to the application code we want to measure and how much to the fact we are meassuring and logging in inner blocks?
Some measures let us think that most of the time spent by the stopclock mechanism is associated to the logging part. There are two things we can do to make the difference :
@@ -544,7 +564,7 @@
[endsect]
[endsect]
-[section Caveat emptor]
+[section:caveat Caveat emptor]
The underlying clocks provided by operating systems are subject to many seemingly arbitrary policies and implementation irregularities. That's a polite way of saying they tend to be flakey, and each operating system or even each clock has its own cruel and unusual forms of flakiness. Don't bet the farm on their accuracy, unless you have become deeply familiar with exactly what the specific operating system is guaranteeing, which is often very little.
@@ -571,7 +591,7 @@
You can get the last stable release of __Boost_Chrono__ by downloading [^chrono.zip] from the
[@http://www.boost-consulting.com/vault/index.php?directory=System Boost Vault]
-You can also access the latest (unstable?) state from the [@https://svn.boost.org/svn/boost/sandbox/chrono Boost Sandbox].
+You can also access the latest (unstable?) state from the [@https://svn.boost.org/svn/boost/sandbox/chrono Boost Sandbox]. Just go to [@http://svn.boost.org/trac/boost/wiki/BoostSubversion here] and follow the instructions there for anonymous SVN access.
[/==========================================]
[heading Where to install __Boost_Chrono__? ]
@@ -593,15 +613,12 @@
[heading Requirements]
[/===================]
-[*Boost.Bitfield] depends on some Boost libraries. For these specific parts you must use either Boost version 1.39.0 or the version in SVN trunk (even if older version should works also).
+[*Boost.Chrono] depends on some Boost libraries. For these specific parts you must use either Boost version 1.39.0 or the version in SVN trunk (even if older versions should works also).
In particular, __Boost_Chrono__ depends on:
[variablelist
[
- [[@http://www.boost.org/libs/accumulator [*Boost.Accumulator]]] [for accumulator_set, and statistics features]
-]
-[
[[@http://www.boost.org/libs/config [*Boost.Config]]] [for configuration purposes, ...]
]
[
@@ -617,10 +634,21 @@
[[@http://www.boost.org/libs/type_traits [*Boost.TypeTraits]]] [for is_base, ...]
]
[
- [[@http://www.boost.org/libs/typeof [*Boost.Typeof]]] [for typeof, ...]
+ [[@http://www.boost.org/libs/utility [*Boost.UtiliTy/EnableIf]]] [for enable_if, ...]
+]
+]
+
+__Boost_Chrono__ depends optionaly on:
+
+[variablelist
+[
+ [[@http://www.boost.org/libs/accumulator [*Boost.Accumulator]]] [for accumulator_set, and statistics features when stopwatch_accumulator.hpp is included]
]
[
- [[@http://www.boost.org/libs/utility [*Boost.UtiliTy/EnableIf]]] [for enable_if, ...]
+ [[@http://www.boost.org/libs/thread [*Boost.Thread]]] [for thread_specific_ptr when suspendible_clock.hpp is included]
+]
+[
+ [[@http://www.boost.org/libs/typeof [*Boost.Typeof]]] [for duration and time_point registration when typeof/boost/chrono/chrono.hpp is include]
]
]
@@ -723,6 +751,73 @@
[section Tutorial]
+[note If you have not read yet the [@boost_chrono/overview/motivation.html motivation section], please read it now.]
+
+[section Common Type]
+
+[section How to get the common type of inter-type with explicit conversions?]
+
+The default definition of `common_type` demands the conversion be implicit. However the trait can be specialized for user-defined types which want to limit their inter-type conversions to explicit, and yet still want to interoperate with the `common_type` facility.
+
+
+
+[endsect]
+[endsect]
+
+[section Ratio]
+[endsect]
+
+[section Clocks, time_point and duration]
+
+
+[section How to get the actual CPU milliseconds (or other units?) used by the current thread between end and start?]
+
+You can use `duration_cast<>` to convert the `thread_clock::duration` into whatever units you desire. This facility will round down (truncate) if an exact conversion is not possible. Ex:
+
+ typedef boost::chrono::milliseconds ms;
+ ms d = boost::chrono::duration_cast<ms>(end - start);
+
+ // d now holds the number of milliseconds from start to end.
+
+ std::cout << ms.count() << "ms\n";
+
+As `boost::chrono::thread_clock::duration` is nanoseconds, we can convert to `nanoseconds`, or some integral-based duration which `nanoseconds` will always exactly convert to, then `duration_cast<>` is unnecessary:
+
+ typedef boost::chrono::nanoseconds ns;
+ ns d = end - start;
+ std::cout << ns.count() << "ns\n";
+
+If you need seconds with a floating point representation you can also eliminate the `duration_cast<>`:
+
+ typedef boost::chrono::duration<double> sec; // seconds, stored with a double
+ sec d = end - start;
+ std::cout << sec.count() << "s\n";
+
+If you're not sure if you need `duration_cast<>` or not, feel free to try it without. If the conversion is exact, or if the destination has a floating point representation, it will compile. Else it will not compile.
+
+If you would like to programmatically inspect `thread_clock::duration`, you can get the representation type with `thread_clock::rep`, and the tick period with `thread_clock::period` (which should be a type `ratio` which has nested values `ratio::num` and `ratio::den`). The tick period of `thread_clock` is `thread_clock::period::num / thread_clock::period::den` seconds: 1/1000000000 in this case (1 billionth of a second), stored in a long long.
+
+If you need to use `duration_cast<>`, but want to round up, instead of down when the conversion is inexact, here is a handy little helper function to do so. Writing it is actually a good starter project for understanding chrono:
+
+ template <class ToDuration, Rep, Period>
+ ToDuration
+ round_up(boost::chrono::duration<Rep, Period> d)
+ {
+ // first round down
+ ToDuration result = boost::chrono::duration_cast<ToDuration>(d);
+ if (result < d) // comparisons are *always* exact
+ ++result; // increment by one tick period
+ return result;
+ }
+
+ typedef boost::chrono::milliseconds ms;
+ ms d = round_up<ms>(end - start);
+ // d now holds the number of milliseconds from start to end, rounded up.
+ std::cout << ms.count() << "ms\n";
+
+[endsect]
+
+[/
[section How to define a thread clock]
On posix systems for which the macro _POSIX_THREAD_CPUTIME is defined we can get the time associated to a specific thread.
@@ -732,8 +827,8 @@
typedef nanoseconds duration;
typedef duration::rep rep;
typedef duration::period period;
- typedef chrono::time_point<process_real_cpu_clock> time_point;
- static const bool is_monotonic = true;
+ typedef chrono::time_point<thread_clock> time_point;
+ static const bool is_monotonic = BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC;
static time_point now( ) {
// get the current thread
@@ -775,12 +870,18 @@
};
[endsect]
+]
+
+
+[endsect]
+
+[section Stopwatches and Stopclocks]
[section How can I prefix each report with `BOOST_CURRENT_FUNCTION` function signature?]
-You will need to give a specific format to you stopclock. You just need to concatenate the your specific patter to the default_format of the formatter.
+You will need to give a specific format to your stopclock. You just need to concatenate your specific pattern to the default_format of the formatter.
-For example, for a stopclock_accumulator the default formatter is stopwatch_accumulator_formatter, this you will need to do something like:
+For example, for a stopclock_accumulator the default formatter is stopwatch_accumulator_formatter, you will need to do something like:
static stopclock_accumulator<> acc(
std::string(BOOST_CURRENT_FUNCTION) + ": "
@@ -802,7 +903,7 @@
(BOOST_JOIN(_accumulator_, __LINE__))
-With this macro you will just have
+With this macro you will just have to write
void foo()
{
@@ -910,7 +1011,7 @@
return 0;
}
-But wat would hapend if we haven't forced the format:
+But what would hapend if we haven't forced the format:
static my_stopwatch_accumulator_reporter acc;
my_stopwatch_accumulator_reporter::scoped_run _(acc);
@@ -920,9 +1021,12 @@
[endsect]
+[endsect]
+
+[section Formatters]
[section How can I make a specific formatter when the default do not satisfy my expectations]
-Imagine then that we want to report the tag::variance(lazy). We will need to include the specific accumulator file
+Imagine then that we want to report the `tag::variance(lazy)`. We will need to include the specific accumulator file
...
#include <boost/accumulators/statistics/variance.hpp>
@@ -1016,4188 +1120,4338 @@
[endsect]
[endsect]
+[endsect]
+[/===============]
+[section Examples]
+[/===============]
-[/================================]
-[section:ext_references References]
-[/================================]
+[section Clocks]
-[variablelist
+[/===============]
+[section SI-units]
+[/===============]
-[
- [[@http://www.open-std.org/jtc1/sc22/wg21 [*C++ Standards Committee's current Working Paper]]]
- [The most authoritative reference material for the library is the C++ Standards Committee's current Working Paper (WP). 20.9 Time utilities "time", 20.4 Compile-time rational arithmetic "ratio", 20.6.7 Other transformations "meta.trans.other"]
-]
+Type-safe "physics" code interoperating with boost::chrono::duration types and taking advantage of the boost::ratio infrastructure and design philosophy.
-[
- [[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]]]
- [From Howard E. Hinnant, Walter E. Brown, Jeff Garland and Marc Paterno. Is very informative and provides motivation for key design decisions]
-]
+length - mimics boost::chrono::duration except restricts representation to double.
+Uses boost::ratio facilities for length units conversions.
+ template <class Ratio>
+ class length {
+ private:
+ double len_;
+ public:
+ typedef Ratio ratio;
+ length() : len_(1) {}
+ length(const double& len) : len_(len) {}
-[
- [[@http://home.roadrunner.com/~hinnant/issue_review/lwg-defects.html#934 [*LGW 934. duration is missing operator%]]]
- [From Terry Golubiewski. Is very informative and provides motivation for key design decisions]
-]
+ template <class R>
+ length(const length<R>& d)
+ : len_(d.count() * boost::ratio_divide<Ratio, R>::type::den /
+ boost::ratio_divide<Ratio, R>::type::num) {}
-[
- [[@http://home.roadrunner.com/~hinnant/issue_review/lwg-active.html#1281 [*LWG 1281. CopyConstruction and Assignment between ratios having the same normalized form]]]
- [From Vicente Juan Botet Escriba.]
-]
+ double count() const {return len_;}
-]
+ length& operator+=(const length& d) {len_ += d.count(); return *this;}
+ length& operator-=(const length& d) {len_ -= d.count(); return *this;}
-[endsect]
+ length operator+() const {return *this;}
+ length operator-() const {return length(-len_);}
-[endsect]
+ length& operator*=(double rhs) {len_ *= rhs; return *this;}
+ length& operator/=(double rhs) {len_ /= rhs; return *this;}
+ };
-[/=================]
-[section:reference Reference ]
-[/=================]
-[section:cpp0x Included on the C++0x recommendation]
+Sparse sampling of length units
-[/===================================================================]
-[section:common_type_hpp Header `<boost/type_traits/common_type.hpp>`]
-[/===================================================================]
+ typedef length<boost::ratio<1> > meter; // set meter as "unity"
+ typedef length<boost::centi> centimeter; // 1/100 meter
+ typedef length<boost::kilo> kilometer; // 1000 meters
+ typedef length<boost::ratio<254, 10000> > inch; // 254/10000 meters
- namespace boost {
- template <class ...T> struct common_type;
- }
+length takes ratio instead of two integral types so that definitions can be made like so:
-[section:common_type Class Template `common_type`]
+ typedef length<boost::ratio_multiply<boost::ratio<12>, inch::ratio>::type> foot; // 12 inchs
+ typedef length<boost::ratio_multiply<boost::ratio<5280>, foot::ratio>::type> mile; // 5280 feet
-`common_type` is a facility which is useful in specifying the type of the result of functions and operators which take a variety of types (e.g. "mixed mode" complex arithmetic).
+Need a floating point definition of seconds
-The nested typedef `common_type::type` could be defined as follows:
+ typedef boost::chrono::duration<double> seconds; // unity
- template <class T, class U = void, class V = void>
- struct common_type {
- typedef typename common_type<typename common_type<T, U>::type, V>::type type;
- };
+Demo of (scientific) support for sub-nanosecond resolutions
- template <class T>
- struct common_type<T, void, void> {
- typedef T type;
- };
+ typedef boost::chrono::duration<double, boost::pico> picosecond; // 10^-12 seconds
+ typedef boost::chrono::duration<double, boost::femto> femtosecond; // 10^-15 seconds
+ typedef boost::chrono::duration<double, boost::atto> attosecond; // 10^-18 seconds
- template <class T, class U>
- struct common_type<T, U, void> {
- private:
- static T m_t();
- static U m_u();
- static bool m_f(); // workaround gcc bug; not required by std
+A very brief proof-of-concept for SIUnits-like library. Hard-wired to floating point seconds and meters, but accepts other units.
+
+ template <class R1, class R2>
+ class quantity
+ {
+ double q_;
public:
- typedef BOOST_TYPEOF_TPL(m_f() ? m_t() : m_u()) type;
- };
+ typedef R1 time_dim;
+ typedef R2 distance_dim;
+ quantity() : q_(1) {}
-All parameter types must be complete. This trait is permitted to be specialized by a user if at least one template parameter is a user-defined type.
+ double get() const {return q_;}
+ void set(double q) {q_ = q;}
+ };
-[*Note:] Such specializations are required when only explicit conversions are desired among the `common_type` arguments.
+ template <>
+ class quantity<boost::ratio<1>, boost::ratio<0> >
+ {
+ double q_;
+ public:
+ quantity() : q_(1) {}
+ quantity(seconds d) : q_(d.count()) {} // note: only User1::seconds needed here
+ double get() const {return q_;}
+ void set(double q) {q_ = q;}
+ };
-[endsect]
+ template <>
+ class quantity<boost::ratio<0>, boost::ratio<1> >
+ {
+ double q_;
+ public:
+ quantity() : q_(1) {}
+ quantity(meter d) : q_(d.count()) {} // note: only User1::meter needed here
-[endsect]
+ double get() const {return q_;}
+ void set(double q) {q_ = q;}
+ };
+ template <>
+ class quantity<boost::ratio<0>, boost::ratio<0> >
+ {
+ double q_;
+ public:
+ quantity() : q_(1) {}
+ quantity(double d) : q_(d) {}
-[/===========================================]
-[section:ratio_hpp Header `<boost/ratio.hpp>`]
-[/===========================================]
+ double get() const {return q_;}
+ void set(double q) {q_ = q;}
+ };
-`ratio` is a facility which is useful in specifying compile time rational constants. Compile time rational arithmetic is supported with protection against overflow and divide by zero. Such a facility is very handy when needing to efficiently represent 1/3 of a nanosecond, or specifying an inch in terms of meters (for example 254/10000 meters - which `ratio` will reduce to 127/5000 meters).
+Example of SI-Units
- namespace boost {
+ typedef quantity<boost::ratio<0>, boost::ratio<0> > Scalar;
+ typedef quantity<boost::ratio<1>, boost::ratio<0> > Time; // second
+ typedef quantity<boost::ratio<0>, boost::ratio<1> > Distance; // meter
+ typedef quantity<boost::ratio<-1>, boost::ratio<1> > Speed; // meter/second
+ typedef quantity<boost::ratio<-2>, boost::ratio<1> > Acceleration; // meter/second^2
- template <boost::intmax_t N, boost::intmax_t D = 1> class ratio;
+Quantity arithmetics
- // ratio arithmetic
- template <class R1, class R2> struct ratio_add;
- template <class R1, class R2> struct ratio_subtract;
- template <class R1, class R2> struct ratio_multiply;
- template <class R1, class R2> struct ratio_divide;
+ template <class R1, class R2, class R3, class R4>
+ quantity<typename boost::ratio_subtract<R1, R3>::type, typename boost::ratio_subtract<R2, R4>::type>
+ operator/(const quantity<R1, R2>& x, const quantity<R3, R4>& y)
+ {
+ typedef quantity<typename boost::ratio_subtract<R1, R3>::type,
+ typename boost::ratio_subtract<R2, R4>::type> R;
+ R r;
+ r.set(x.get() / y.get());
+ return r;
+ }
- // ratio comparison
- template <class R1, class R2> struct ratio_equal;
- template <class R1, class R2> struct ratio_not_equal;
- template <class R1, class R2> struct ratio_less;
- template <class R1, class R2> struct ratio_less_equal;
- template <class R1, class R2> struct ratio_greater;
- template <class R1, class R2> struct ratio_greater_equal;
+ template <class R1, class R2, class R3, class R4>
+ quantity<typename boost::ratio_add<R1, R3>::type, typename boost::ratio_add<R2, R4>::type>
+ operator*(const quantity<R1, R2>& x, const quantity<R3, R4>& y)
+ {
+ typedef quantity<typename boost::ratio_add<R1, R3>::type,
+ typename boost::ratio_add<R2, R4>::type> R;
+ R r;
+ r.set(x.get() * y.get());
+ return r;
+ }
- // convenience SI typedefs
- typedef ratio<1LL, 1000000000000000000LL> atto;
- typedef ratio<1LL, 1000000000000000LL> femto;
- typedef ratio<1LL, 1000000000000LL> pico;
- typedef ratio<1LL, 1000000000LL> nano;
- typedef ratio<1LL, 1000000LL> micro;
- typedef ratio<1LL, 1000LL> milli;
- typedef ratio<1LL, 100LL> centi;
- typedef ratio<1LL, 10LL> deci;
- typedef ratio< 10LL, 1LL> deca;
- typedef ratio< 100LL, 1LL> hecto;
- typedef ratio< 1000LL, 1LL> kilo;
- typedef ratio< 1000000LL, 1LL> mega;
- typedef ratio< 1000000000LL, 1LL> giga;
- typedef ratio< 1000000000000LL, 1LL> tera;
- typedef ratio< 1000000000000000LL, 1LL> peta;
- typedef ratio<1000000000000000000LL, 1LL> exa;
+ template <class R1, class R2>
+ quantity<R1, R2>
+ operator+(const quantity<R1, R2>& x, const quantity<R1, R2>& y)
+ {
+ typedef quantity<R1, R2> R;
+ R r;
+ r.set(x.get() + y.get());
+ return r;
}
+ template <class R1, class R2>
+ quantity<R1, R2>
+ operator-(const quantity<R1, R2>& x, const quantity<R1, R2>& y)
+ {
+ typedef quantity<R1, R2> R;
+ R r;
+ r.set(x.get() - y.get());
+ return r;
+ }
-[section:ratio Class Template `ratio<>`]
+Example type-safe physics function
- template <boost::intmax_t N, boost::intmax_t D>
- class ratio {
- public:
- static const boost::intmax_t num;
- static const boost::intmax_t den;
- typedef ratio<num, den> type;
+ Distance
+ compute_distance(Speed v0, Time t, Acceleration a)
+ {
+ return v0 * t + Scalar(.5) * a * t * t; // if a units mistake is made here it won't compile
+ }
- ratio() {}
- template <intmax_t _N2, intmax_t _D2>
- ratio(const ratio<_N2, _D2>&,
- typename enable_if_c
- <
- ratio<_N2, _D2>::num == num &&
- ratio<_N2, _D2>::den == den
- >::type* = 0) {}
+Exercise example type-safe physics function and show interoperation
+of custom time durations (User1::seconds) and standard time durations (boost::hours).
+Though input can be arbitrary (but type-safe) units, output is always in SI-units
+(a limitation of the simplified Units lib demoed here).
- template <intmax_t _N2, intmax_t _D2>
- typename enable_if_c
- <
- ratio<_N2, _D2>::num == num &&
- ratio<_N2, _D2>::den == den,
- ratio&
- >::type
- operator=(const ratio<_N2, _D2>&) {return *this;}
- };
+ int main()
+ {
+ typedef boost::ratio<8, BOOST_INTMAX_C(0x7FFFFFFFD)> R1;
+ typedef boost::ratio<3, BOOST_INTMAX_C(0x7FFFFFFFD)> R2;
+ typedef User1::quantity<boost::ratio_subtract<boost::ratio<0>, boost::ratio<1> >::type,
+ boost::ratio_subtract<boost::ratio<1>, boost::ratio<0> >::type > RR;
+ typedef boost::ratio_subtract<R1, R2>::type RS;
+ std::cout << RS::num << '/' << RS::den << '\n';
-A diagnostic will be emitted if `ratio` is instantiated with `D == 0`, or if the absolute value of `N` or `D` can not be represented. [*Note:] These rules ensure that infinite ratios are avoided and that for any negative input, there exists a representable value of its absolute value which is positive. In a two's complement representation, this excludes the most negative value.
-Let `gcd` denote the greatest common divisor of `N`'s absolute value and of `D`'s absolute value.
+ std::cout << "*************\n";
+ std::cout << "* testUser1 *\n";
+ std::cout << "*************\n";
+ User1::Distance d( User1::mile(110) );
+ User1::Time t( boost::chrono::hours(2) );
-* `num` has the value `sign(N)*sign(D)*abs(N)/gcd`.
+ RR r=d / t;
+ //r.set(d.get() / t.get());
-* `den` has the value `abs(D)/gcd`.
+ User1::Speed rc= r;
-The nested typedef `type` denotes the normalized form of this ratio type. It should be used when the template parameters doesn't give a normalized form.
+ User1::Speed s = d / t;
+ std::cout << "Speed = " << s.get() << " meters/sec\n";
+ User1::Acceleration a = User1::Distance( User1::foot(32.2) ) / User1::Time() / User1::Time();
+ std::cout << "Acceleration = " << a.get() << " meters/sec^2\n";
+ User1::Distance df = compute_distance(s, User1::Time( User1::seconds(0.5) ), a);
+ std::cout << "Distance = " << df.get() << " meters\n";
+ std::cout << "There are " << User1::mile::ratio::den << '/' << User1::mile::ratio::num << " miles/meter";
+ User1::meter mt = 1;
+ User1::mile mi = mt;
+ std::cout << " which is approximately " << mi.count() << '\n';
+ std::cout << "There are " << User1::mile::ratio::num << '/' << User1::mile::ratio::den << " meters/mile";
+ mi = 1;
+ mt = mi;
+ std::cout << " which is approximately " << mt.count() << '\n';
+ User1::attosecond as(1);
+ User1::seconds sec = as;
+ std::cout << "1 attosecond is " << sec.count() << " seconds\n";
+ std::cout << "sec = as; // compiles\n";
+ sec = User1::seconds(1);
+ as = sec;
+ std::cout << "1 second is " << as.count() << " attoseconds\n";
+ std::cout << "as = sec; // compiles\n";
+ std::cout << "\n";
+ return 0;
+ }
-Two `ratio` classes `ratio<N1,D1>` and `ratio<N2,D2>` have the same normalized form if `ratio<N1,D1>::type` is the same type as `ratio<N2,D2>::type`
+['See the source file [@../../test/ratio_test.cpp test/ratio_test.cpp]]
-[section Construction and assignment]
+[endsect]
+[endsect]
- template <intmax_t N2, intmax_t D2>
- ratio(const ratio<N2, D2>& r);
+[/===============]
+[section How you override the duration's default constructor]
-[*Effects:] Constructs a `ratio` object.
+Next follows how you override the duration's default constructor to do anything you want (in this case zero). All we need to do is to change the representation
-[*Remarks:] This constructor will not participate in overload resolution unless `r` has the same normalized form as `*this`.
+ namespace I_dont_like_the_default_duration_behavior {
- template <intmax_t N2, intmax_t D2>
- ratio& operator=(const ratio<N2, D2>& r);
+ template <class R>
+ class zero_default
+ {
+ public:
+ typedef R rep;
-[*Effects:] Assigns a `ratio` object.
+ private:
+ rep rep_;
+ public:
+ zero_default(rep i = 0) : rep_(i) {}
+ operator rep() const {return rep_;}
-[*Returns:] *this.
+ zero_default& operator+=(zero_default x) {rep_ += x.rep_; return *this;}
+ zero_default& operator-=(zero_default x) {rep_ -= x.rep_; return *this;}
+ zero_default& operator*=(zero_default x) {rep_ *= x.rep_; return *this;}
+ zero_default& operator/=(zero_default x) {rep_ /= x.rep_; return *this;}
-[*Remarks:] This operator will not participate in overload resolution unless `r` has the same normalized form as `*this`.
+ zero_default operator+ () const {return *this;}
+ zero_default operator- () const {return zero_default(-rep_);}
+ zero_default& operator++() {++rep_; return *this;}
+ zero_default operator++(int) {return zero_default(rep_++);}
+ zero_default& operator--() {--rep_; return *this;}
+ zero_default operator--(int) {return zero_default(rep_--);}
-[endsect]
+ friend zero_default operator+(zero_default x, zero_default y) {return x += y;}
+ friend zero_default operator-(zero_default x, zero_default y) {return x -= y;}
+ friend zero_default operator*(zero_default x, zero_default y) {return x *= y;}
+ friend zero_default operator/(zero_default x, zero_default y) {return x /= y;}
+ friend bool operator==(zero_default x, zero_default y) {return x.rep_ == y.rep_;}
+ friend bool operator!=(zero_default x, zero_default y) {return !(x == y);}
+ friend bool operator< (zero_default x, zero_default y) {return x.rep_ < y.rep_;}
+ friend bool operator<=(zero_default x, zero_default y) {return !(y < x);}
+ friend bool operator> (zero_default x, zero_default y) {return y < x;}
+ friend bool operator>=(zero_default x, zero_default y) {return !(x < y);}
+ };
-[endsect]
+ typedef boost::chrono::duration<zero_default<long long>, boost::nano > nanoseconds;
+ typedef boost::chrono::duration<zero_default<long long>, boost::micro > microseconds;
+ typedef boost::chrono::duration<zero_default<long long>, boost::milli > milliseconds;
+ typedef boost::chrono::duration<zero_default<long long> > seconds;
+ typedef boost::chrono::duration<zero_default<long long>, boost::ratio<60> > minutes;
+ typedef boost::chrono::duration<zero_default<long long>, boost::ratio<3600> > hours;
+ }
+Usage
-[section:ratio_arithmetic `ratio` arithmetic]
+ using namespace I_dont_like_the_default_duration_behavior;
-For each of the class templates in this clause, each template parameter refers to a `ratio`. If the implementation is unable to form the indicated `ratio` due to overflow, a diagnostic will be issued.
+ milliseconds ms;
+ std::cout << ms.count() << '\n';
- template <class R1, class R2> struct ratio_add {
- typedef [/see below] type;
- };
+['See the source file [@../../example/i_dont_like_the_default_duration_behavior.cpp example/i_dont_like_the_default_duration_behavior.cpp]]
-The nested typedef `type` is a synonym for `ratio<R1::num * R2::den + R2::num * R1::den, R1::den * R2::den>::type`.
+[endsect]
- template <class R1, class R2> struct ratio_subtract {
- typedef [/see below] type;
- };
+[/==================]
+[section min utility]
-The nested typedef `type` is a synonym for `ratio<R1::num * R2::den - R2::num * R1::den, R1::den * R2::den>::type`.
+Returns the earliest time_point.
- template <class R1, class R2> struct ratio_multiply {
- typedef [/see below] type;
- };
+ template <class Clock, class Duration1, class Duration2>
+ typename boost::common_type<time_point<Clock, Duration1>,
+ time_point<Clock, Duration2> >::type
+ min(time_point<Clock, Duration1> t1, time_point<Clock, Duration2> t2)
+ {
+ return t2 < t1 ? t2 : t1;
+ }
-The nested typedef `type` is a synonym for `ratio<R1::num * R2::num, R1::den * R2::den>::type`.
+Being able to *easily* write this function is a major feature!
- template <class R1, class R2> struct ratio_divide {
- typedef [/see below] type;
- };
+ BOOST_AUTO(t1, system_clock::now() + seconds(3));
+ BOOST_AUTO(t2, system_clock::now() + nanoseconds(3));
+ BOOST_AUTO(t3, (min)(t1, t2));
+
+['See the source file [@../../example/min_time_point.cpp example/min_time_point.cpp]]
-The nested typedef `type` is a synonym for `ratio<R1::num * R2::den, R2::num * R1::den>::type`.
[endsect]
-[section:ratio_comparison `ratio` comparison]
+[/==================]
+[section Cycle count]
- template <class R1, class R2> struct ratio_equal
- : public boost::integral_constant<bool, [/see below] > {};
+Users can easily create their own clocks, with both points in time and time durations which have a representation and precision of their own choosing. For example if there is a hardware counter which simply increments a count with each cycle of the cpu, one can very easily build clocks, time points and durations on top of that, using only a few tens of lines of code. Such systems can be used to call the time-sensitive threading API's such as sleep, wait on a condition variable, or wait for a mutex lock. The API proposed herein is not sensitive as to whether this is a 300MHz clock (with a 3 1/3 nanosecond tick period) or a 3GHz clock (with a tick period of 1/3 of a nanosecond). And the resulting code will be just as efficient as if the user wrote a special purpose clock cycle counter.
-If R1::num == R2::num && R1::den == R2::den, ratio_equal derives from true_type, else derives from false_type.
- template <class R1, class R2>
- struct ratio_less
- : public boost::integral_constant<bool, [/see below] > {};
+ #include <boost/chrono/chrono.hpp>
+ #include <boost/type_traits.hpp>
-If R1::num * R2::den < R2::num * R1::den, ratio_less derives from true_type, else derives from false_type.
+ #include <iostream>
- template <class R1, class R2> struct ratio_not_equal
- : public boost::integral_constant<bool, !ratio_equal<R1, R2>::value> {};
+ using namespace boost::chrono;
- template <class R1, class R2> struct ratio_less_equal
- : public boost::integral_constant<bool, !ratio_less<R2, R1>::value> {};
- template <class R1, class R2> struct ratio_greater
- : public boost::integral_constant<bool, ratio_less<R2, R1>::value> {};
+ template <long long speed>
+ struct cycle_count
+ {
+ typedef typename boost::ratio_multiply<boost::ratio<speed>, boost::mega>::type frequency; // Mhz
+ typedef typename boost::ratio_divide<boost::ratio<1>, frequency>::type period;
+ typedef long long rep;
+ typedef boost::chrono::duration<rep, period> duration;
+ typedef boost::chrono::time_point<cycle_count> time_point;
- template <class R1, class R2> struct ratio_greater_equal
- : public boost::integral_constant<bool, !ratio_less<R1, R2>::value> {};
+ static time_point now()
+ {
+ static long long tick = 0;
+ // return exact cycle count
+ return time_point(duration(++tick)); // fake access to clock cycle count
+ }
+ };
+ template <long long speed>
+ struct approx_cycle_count
+ {
+ static const long long frequency = speed * 1000000; // MHz
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ static const long long nanosec_per_sec = period::den;
+ typedef boost::chrono::time_point<approx_cycle_count> time_point;
-[endsect]
+ static time_point now()
+ {
+ static long long tick = 0;
+ // return cycle count as an approximate number of nanoseconds
+ // compute as if nanoseconds is only duration in the std::lib
+ return time_point(duration(++tick * nanosec_per_sec / frequency));
+ }
+ };
-[section:ration_SI_typedefs SI typedefs]
+['See the source file [@../../example/cycle_count.cpp here]]
- // convenience SI typedefs
- typedef ratio<1LL, 1000000000000000000LL> atto;
- typedef ratio<1LL, 1000000000000000LL> femto;
- typedef ratio<1LL, 1000000000000LL> pico;
- typedef ratio<1LL, 1000000000LL> nano;
- typedef ratio<1LL, 1000000LL> micro;
- typedef ratio<1LL, 1000LL> milli;
- typedef ratio<1LL, 100LL> centi;
- typedef ratio<1LL, 10LL> deci;
- typedef ratio< 10LL, 1LL> deca;
- typedef ratio< 100LL, 1LL> hecto;
- typedef ratio< 1000LL, 1LL> kilo;
- typedef ratio< 1000000LL, 1LL> mega;
- typedef ratio< 1000000000LL, 1LL> giga;
- typedef ratio< 1000000000000LL, 1LL> tera;
- typedef ratio< 1000000000000000LL, 1LL> peta;
- typedef ratio<1000000000000000000LL, 1LL> exa;
+[endsect]
+[/==================]
+[section xtime conversions]
-Four of the typedefs in the recomendation which can be conditionally supported are not supported: yocto, zepto, zetta and yotta.
+Example round_up utility: converts d to To, rounding up for inexact conversions
+Being able to *easily* write this function is a major feature!
- typedef ratio<1, 1000000000000000000000000> yocto; // conditionally supported
- typedef ratio<1, 1000000000000000000000> zepto; // conditionally supported
- typedef ratio< 1000000000000000000000, 1> zetta; // conditionally supported
- typedef ratio<1000000000000000000000000, 1> yotta; // conditionally supported
+ #include <boost/chrono/chrono.hpp>
+ #include <boost/type_traits.hpp>
-[endsect]
+ #include <iostream>
-[endsect]
+ using namespace boost::chrono;
-[/=============================================]
-[section:chrono_hpp Header `<boost/chrono.hpp>`]
-[/=============================================]
+ template <class To, class Rep, class Period>
+ To
+ round_up(duration<Rep, Period> d)
+ {
+ To result = duration_cast<To>(d);
+ if (result < d)
+ ++result;
+ return result;
+ }
-This file is a redirection to `boost/chrono/chrono.hpp` including in addition registration for `duration<>` and `timepoint<>` class templates to Boost.Typeof.
+Demonstrate interaction with xtime-like facility:
- #include <boost/chrono/chrono.hpp>
- #include <boost/chrono/typeof/boost/chrono/chrono.hpp>
+ struct xtime
+ {
+ long sec;
+ unsigned long usec;
+ };
-[endsect]
+ template <class Rep, class Period>
+ xtime
+ to_xtime_truncate(duration<Rep, Period> d)
+ {
+ xtime xt;
+ xt.sec = static_cast<long>(duration_cast<seconds>(d).count());
+ xt.usec = static_cast<long>(duration_cast<microseconds>(d - seconds(xt.sec)).count());
+ return xt;
+ }
-[/=============================================]
-[section:chrono_chrono_hpp Header `<boost/chrono/chrono.hpp>`]
-[/=============================================]
+ template <class Rep, class Period>
+ xtime
+ to_xtime_round_up(duration<Rep, Period> d)
+ {
+ xtime xt;
+ xt.sec = static_cast<long>(duration_cast<seconds>(d).count());
+ xt.usec = static_cast<unsigned long>(round_up<microseconds>(d - seconds(xt.sec)).count());
+ return xt;
+ }
- namespace boost {
- namespace chrono {
+ microseconds
+ from_xtime(xtime xt)
+ {
+ return seconds(xt.sec) + microseconds(xt.usec);
+ }
- template <class Rep, class Period = ratio<1> > class duration;
- template <class Clock, class Duration = typename Clock::duration> class time_point;
+ void print(xtime xt)
+ {
+ std::cout << '{' << xt.sec << ',' << xt.usec << "}\n";
+ }
- }
- template <class Rep1, class Period1, class Rep2, class Period2>
- struct common_type<chrono::duration<Rep1, Period1>,
- chrono::duration<Rep2, Period2> >;
+Usage
- template <class Clock, class Duration1, class Duration2>
- struct common_type<chrono::time_point<Clock, Duration1>,
- chrono::time_point<Clock, Duration2> >;
+ xtime xt = to_xtime_truncate(seconds(3) + milliseconds(251));
+ print(xt);
+ milliseconds ms = duration_cast<milliseconds>(from_xtime(xt));
+ std::cout << ms.count() << " milliseconds\n";
+ xt = to_xtime_round_up(ms);
+ print(xt);
+ xt = to_xtime_truncate(seconds(3) + nanoseconds(999));
+ print(xt);
+ xt = to_xtime_round_up(seconds(3) + nanoseconds(999));
+ print(xt);
- namespace chrono {
- // customization traits
- template <class Rep> struct treat_as_floating_point;
- template <class Rep> struct duration_values;
+['See the source file [@../../example/xtime.cpp here]]
- // duration arithmetic
- template <class Rep1, class Period1, class Rep2, class Period2>
- typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
- operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+[endsect]
- template <class Rep1, class Period1, class Rep2, class Period2>
- typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
- operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+[/==================]
+[section xtime_clock]
- template <class Rep1, class Period, class Rep2>
- duration<typename common_type<Rep1, Rep2>::type, Period>
- operator*(const duration<Rep1, Period>& d, const Rep2& s);
+This example demonstrates the use of a timeval-like struct to be used as the representation
+type for both duraiton and time_point.
- template <class Rep1, class Period, class Rep2>
- duration<typename common_type<Rep1, Rep2>::type, Period>
- operator*(const Rep1& s, const duration<Rep2, Period>& d);
+ class xtime {
+ private:
+ long tv_sec;
+ long tv_usec;
- template <class Rep1, class Period, class Rep2>
- duration<typename common_type<Rep1, Rep2>::type, Period>
- operator/(const duration<Rep1, Period>& d, const Rep2& s);
+ void fixup() {
+ if (tv_usec < 0) {
+ tv_usec += 1000000;
+ --tv_sec;
+ }
+ }
- template <class Rep1, class Period1, class Rep2, class Period2>
- typename common_type<Rep1, Rep2>::type
- operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+ public:
+ explicit xtime(long sec, long usec) {
+ tv_sec = sec;
+ tv_usec = usec;
+ if (tv_usec < 0 || tv_usec >= 1000000) {
+ tv_sec += tv_usec / 1000000;
+ tv_usec %= 1000000;
+ fixup();
+ }
+ }
- template <class Rep1, class Rep2, class Period>
- double operator/(const Rep1& s, const duration<Rep2, Period>& d);
+ explicit xtime(long long usec) {
+ tv_usec = static_cast<long>(usec % 1000000);
+ tv_sec = static_cast<long>(usec / 1000000);
+ fixup();
+ }
- // duration comparisons
- template <class Rep1, class Period1, class Rep2, class Period2>
- bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+ // explicit
+ operator long long() const {return static_cast<long long>(tv_sec) * 1000000 + tv_usec;}
- template <class Rep1, class Period1, class Rep2, class Period2>
- bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+ xtime& operator += (xtime rhs) {
+ tv_sec += rhs.tv_sec;
+ tv_usec += rhs.tv_usec;
+ if (tv_usec >= 1000000) {
+ tv_usec -= 1000000;
+ ++tv_sec;
+ }
+ return *this;
+ }
- template <class Rep1, class Period1, class Rep2, class Period2>
- bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Rep1, class Period1, class Rep2, class Period2>
- bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+ xtime& operator -= (xtime rhs) {
+ tv_sec -= rhs.tv_sec;
+ tv_usec -= rhs.tv_usec;
+ fixup();
+ return *this;
+ }
- template <class Rep1, class Period1, class Rep2, class Period2>
- bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Rep1, class Period1, class Rep2, class Period2>
- bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+ xtime& operator %= (xtime rhs) {
+ long long t = tv_sec * 1000000 + tv_usec;
+ long long r = rhs.tv_sec * 1000000 + rhs.tv_usec;
+ t %= r;
+ tv_sec = static_cast<long>(t / 1000000);
+ tv_usec = static_cast<long>(t % 1000000);
+ fixup();
+ return *this;
+ }
- // duration_cast
+ friend xtime operator+(xtime x, xtime y) {return x += y;}
+ friend xtime operator-(xtime x, xtime y) {return x -= y;}
+ friend xtime operator%(xtime x, xtime y) {return x %= y;}
- template <class ToDuration, class Rep, class Period>
- ToDuration duration_cast(const duration<Rep, Period>& d);
+ friend bool operator==(xtime x, xtime y)
+ { return (x.tv_sec == y.tv_sec && x.tv_usec == y.tv_usec); }
- // convenience typedefs
- typedef duration<boost::int_least64_t, nano> nanoseconds; // at least 64 bits needed
- typedef duration<boost::int_least64_t, micro> microseconds; // at least 55 bits needed
- typedef duration<boost::int_least64_t, milli> milliseconds; // at least 45 bits needed
- typedef duration<boost::int_least64_t> seconds; // at least 35 bits needed
- typedef duration<boost::int_least32_t, ratio< 60> > minutes; // at least 29 bits needed
- typedef duration<boost::int_least32_t, ratio<3600> > hours; // at least 23 bits needed
+ friend bool operator<(xtime x, xtime y) {
+ if (x.tv_sec == y.tv_sec)
+ return (x.tv_usec < y.tv_usec);
+ return (x.tv_sec < y.tv_sec);
+ }
- // time_point arithmetic
- template <class Clock, class Duration1, class Rep2, class Period2>
- time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
- operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
+ friend bool operator!=(xtime x, xtime y) { return !(x == y); }
+ friend bool operator> (xtime x, xtime y) { return y < x; }
+ friend bool operator<=(xtime x, xtime y) { return !(y < x); }
+ friend bool operator>=(xtime x, xtime y) { return !(x < y); }
- template <class Rep1, class Period1, class Clock, class Duration2>
- time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
- operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
+ friend std::ostream& operator<<(std::ostream& os, xtime x)
+ {return os << '{' << x.tv_sec << ',' << x.tv_usec << '}';}
+ };
- template <class Clock, class Duration1, class Rep2, class Period2>
- time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
- operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
+Clock based on timeval-like struct.
- template <class Clock, class Duration1, class Duration2>
- typename common_type<Duration1, Duration2>::type
- operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
+ class xtime_clock
+ {
+ public:
+ typedef xtime rep;
+ typedef boost::micro period;
+ typedef boost::chrono::duration<rep, period> duration;
+ typedef boost::chrono::time_point<xtime_clock> time_point;
- // time_point comparisons
- template <class Clock, class Duration1, class Duration2>
- bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
- Duration2>& rhs);
+ static time_point now()
+ {
+ #if defined(BOOST_CHRONO_WINDOWS_API)
+ time_point t(duration(xtime(0)));
+ gettimeofday((timeval*)&t, 0);
+ return t;
- // time_point_cast
- template <class ToDuration, class Clock, class Duration>
- time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
+ #elif defined(BOOST_CHRONO_MAC_API)
- // Clocks
- class system_clock;
- class monotonic_clock;
- class high_resolution_clock;
+ time_point t(duration(xtime(0)));
+ gettimeofday((timeval*)&t, 0);
+ return t;
- }
- }
+ #elif defined(BOOST_CHRONO_POSIX_API)
+ //time_point t(0,0);
-[section `Clock` Requirements]
+ timespec ts;
+ ::clock_gettime( CLOCK_REALTIME, &ts );
-A clock represents a bundle consisting of a native `duration`, a native `time_point`, and a function `now()` to get the current `time_point`. A clock must meet the requirements in the following Table.
+ xtime xt( ts.tv_sec, ts.tv_nsec/1000);
+ return time_point(duration(xt));
-In this table `C1` and `C2` denote `clock` types. `t1` and `t2` are values returned from `C1::now()` where the call returning `t1` happens before the call returning `t2` and both of these calls happen before `C1::time_point::max()`.
+ #endif // POSIX
+ }
+ };
-[table Clock Requirements
- [[expression] [return type] [operational semantics]]
- [[`C1::rep`] [An arithmetic type or class emulating an arithmetic type. ] [The representation type of the native `duration` and `time_point`.]]
- [[`C1::period`] [`ratio`] [The tick period of the clock in seconds.]]
- [[`C1::duration`] [`chrono::duration<C1::rep, C1::period>`] [The native `duration` type of the `clock`.]]
- [[`C1::time_point`] [`chrono::time_point<C1> or chrono::time_point<C2, C1::duration>`] [The native `time_point` type of the `clock`. Different clocks are permitted to share a `time_point` definition if it is valid to compare their time_points by comparing their respective `duration`s. `C1` and `C2` must refer to the same epoch.]]
- [[`C1::is_monotonic`] [`const bool`] [`true` if `t1 <= t2` is always `true`, else `false`. [*Note: A `clock` that can be adjusted backwards is not monotonic]]]
- [[`C1::now()`] [`C1::time_point`] [Returns a `time_point` representing the current point in time.]]
-]
+Usage of xtime_clock
-[endsect]
+ using namespace boost::chrono;
+ std::cout << "sizeof xtime_clock::time_point = " << sizeof(xtime_clock::time_point) << '\n';
+ std::cout << "sizeof xtime_clock::duration = " << sizeof(xtime_clock::duration) << '\n';
+ std::cout << "sizeof xtime_clock::rep = " << sizeof(xtime_clock::rep) << '\n';
+ xtime_clock::duration delay(milliseconds(5));
+ xtime_clock::time_point start = xtime_clock::now();
+ while (xtime_clock::now() - start <= delay) {}
+ xtime_clock::time_point stop = xtime_clock::now();
+ xtime_clock::duration elapsed = stop - start;
+ std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
-[section Time-related traits]
-[section:treat_as_floating_point Metafunction `treat_as_floating_point<>`]
- template <class Rep> struct treat_as_floating_point
- : boost::is_floating_point<Rep> {};
+['See the source file [@../../example/timeval_demo.cpp example/timeval_demo.cpp]]
-The `duration` template uses the `treat_as_floating_point` trait to help determine if a `duration` with one tick period can be converted to another `duration` with a different tick period. If `treat_as_floating_point<Rep>::value` is `true`, then `Rep` is a floating point type and implicit conversions are allowed among `duration`s. Otherwise, the implicit convertibility depends on the tick periods of the `duration`s. If `Rep` is a class type which emulates a floating point type, the author of `Rep` can specialize `treat_as_floating_point` so that `duration` will treat this `Rep` as if it were a floating point type. Otherwise `Rep` is assumed to be an integral type, or a class emulating an integral type.
+[endsect]
+[/=========================]
+[section runtime_resolution]
-[endsect]
-[section:duration_values Class template `duration_values`]
+Handle duration with resolution not known until run time
- template <class Rep>
- struct duration_values
+ class duration
{
public:
- static BOOST_CHRONO_CONSTEXPR Rep zero();
- static BOOST_CHRONO_CONSTEXPR Rep max();
- static BOOST_CHRONO_CONSTEXPR Rep min();
- };
+ typedef long long rep;
+ private:
+ rep rep_;
-The `duration` template uses the `duration_values` trait to construct special values of the `duration`s representation (`Rep`). This is done because the representation might be a class type with behavior which requires some other implementation to return these special values. In that case, the author of that class type should specialize `duration_values` to return the indicated values.
+ static const double ticks_per_nanosecond;
-[section:zero Static member Function `zero()`]
+ public:
+ typedef boost::chrono::duration<double, boost::nano> tonanosec;
- static BOOST_CHRONO_CONSTEXPR Rep zero();
+ duration() {} // = default;
+ explicit duration(const rep& r) : rep_(r) {}
-[*Returns:] `Rep(0)`. [*Note:] `Rep(0)` is specified instead of `Rep()` since `Rep()` may have some other meaning, such as an uninitialized value.
+ // conversions
+ explicit duration(const tonanosec& d)
+ : rep_(static_cast<rep>(d.count() * ticks_per_nanosecond)) {}
-[*Remarks:] The value returned corresponds to the additive identity.
+ // explicit
+ operator tonanosec() const {return tonanosec(rep_/ticks_per_nanosecond);}
-[endsect]
-[section:max Static member function `max()`]
+ // observer
- static BOOST_CHRONO_CONSTEXPR Rep max();
+ rep count() const {return rep_;}
-[*Returns:] `numeric_limits<Rep>::max()`.
+ // arithmetic
-[*Remarks:] The value returned compares greater than zero().
+ duration& operator+=(const duration& d) {rep_ += d.rep_; return *this;}
+ duration& operator-=(const duration& d) {rep_ += d.rep_; return *this;}
+ duration& operator*=(rep rhs) {rep_ *= rhs; return *this;}
+ duration& operator/=(rep rhs) {rep_ /= rhs; return *this;}
-[endsect]
-[section:min Static member function `min()`]
+ duration operator+() const {return *this;}
+ duration operator-() const {return duration(-rep_);}
+ duration& operator++() {++rep_; return *this;}
+ duration operator++(int) {return duration(rep_++);}
+ duration& operator--() {--rep_; return *this;}
+ duration operator--(int) {return duration(rep_--);}
- static BOOST_CHRONO_CONSTEXPR Rep min();
+ friend duration operator+(duration x, duration y) {return x += y;}
+ friend duration operator-(duration x, duration y) {return x -= y;}
+ friend duration operator*(duration x, rep y) {return x *= y;}
+ friend duration operator*(rep x, duration y) {return y *= x;}
+ friend duration operator/(duration x, rep y) {return x /= y;}
-[*Returns:] `numeric_limits<Rep>::lowest()`.
+ friend bool operator==(duration x, duration y) {return x.rep_ == y.rep_;}
+ friend bool operator!=(duration x, duration y) {return !(x == y);}
+ friend bool operator< (duration x, duration y) {return x.rep_ < y.rep_;}
+ friend bool operator<=(duration x, duration y) {return !(y < x);}
+ friend bool operator> (duration x, duration y) {return y < x;}
+ friend bool operator>=(duration x, duration y) {return !(x < y);}
+ };
-[*Remarks:] The value returned compares less than or equal to `zero()`.
+['See the source file [@../../example/runtime_resolution.cpp here]]
[endsect]
-[endsect]
+[/=======================================================]
+[section Simulated thread interface demonstration program]
-[section `common_type` specializations]
+Free sleep functions
- template <class Rep1, class Period1, class Rep2, class Period2>
- struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2> >
- {
- typedef chrono::duration<typename common_type<Rep1, Rep2>::type, see below> type;
- };
+ namespace boost { namespace this_thread {
-The period of the `duration` indicated by this specialization of `common_type` is the greatest common divisor of `Period1` and `Period2`. This can be computed by forming a `ratio` of the greatest common divisor of `Period1::num` and `Period2::num`, and the least common multiple of `Period1::den` and `Period2::den`.
+ template <class Rep, class Period>
+ void sleep_for(const boost::chrono::duration<Rep, Period>& d) {
+ boost::chrono::microseconds t = boost::chrono::duration_cast<boost::chrono::microseconds>(d);
+ if (t < d)
+ ++t;
+ if (t > boost::chrono::microseconds(0))
+ std::cout << "sleep_for " << t.count() << " microseconds\n";
+ }
-[*Note:] The typedef type is the `duration` with the largest tick period possible where both `duration` arguments will convert to it without requiring a division operation. The representation of this type is intended to be able to hold any value resulting from this conversion, with the possible exception of round-off error when floating point `duration`s are involved (but not truncation error).
+ template <class Clock, class Duration>
+ void sleep_until(const boost::chrono::time_point<Clock, Duration>& t) {
+ using namespace boost::chrono;
+ typedef time_point<Clock, Duration> Time;
+ typedef system_clock::time_point SysTime;
+ if (t > Clock::now()) {
+ typedef typename boost::common_type<typename Time::duration,
+ typename SysTime::duration>::type D;
+ /* auto */ D d = t - Clock::now();
+ microseconds us = duration_cast<microseconds>(d);
+ if (us < d)
+ ++us;
+ SysTime st = system_clock::now() + us;
+ std::cout << "sleep_until ";
+ detail::print_time(st);
+ std::cout << " which is " << (st - system_clock::now()).count() << " microseconds away\n";
+ }
+ }
- template <class Clock, class Duration1, class Duration2>
- struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2> >
- {
- typedef chrono::time_point<Clock, typename common_type<Duration1, Duration2>::type> type;
- };
+ }}
-The `common_type` of two `time_point`s is a `time_point` with the same `clock` (both have the same `clock`), and the `common_type` of the two `duration`s.
-[endsect]
+timed_mutex modified fuctions
+ namespace boost {
+ struct timed_mutex {
+ // ...
-[endsect]
+ template <class Rep, class Period>
+ bool try_lock_for(const boost::chrono::duration<Rep, Period>& d) {
+ boost::chrono::microseconds t = boost::chrono::duration_cast<boost::chrono::microseconds>(d);
+ if (t <= boost::chrono::microseconds(0))
+ return try_lock();
+ std::cout << "try_lock_for " << t.count() << " microseconds\n";
+ return true;
+ }
-[section Class template `duration`]
+ template <class Clock, class Duration>
+ bool try_lock_until(const boost::chrono::time_point<Clock, Duration>& t)
+ {
+ using namespace boost::chrono;
+ typedef time_point<Clock, Duration> Time;
+ typedef system_clock::time_point SysTime;
+ if (t <= Clock::now())
+ return try_lock();
+ typedef typename boost::common_type<typename Time::duration,
+ typename Clock::duration>::type D;
+ /* auto */ D d = t - Clock::now();
+ microseconds us = duration_cast<microseconds>(d);
+ SysTime st = system_clock::now() + us;
+ std::cout << "try_lock_until ";
+ detail::print_time(st);
+ std::cout << " which is " << (st - system_clock::now()).count()
+ << " microseconds away\n";
+ return true;
+ }
+ };
+ }
-A `duration` measures time between two points in time (`time_point`). A `duration` has a representation which holds a count of ticks, and a tick period. The tick period is the amount of time which occurs from one tick to another in units of a second. It is expressed as a rational constant using `ratio`.
+condition_variable modified fuctions
- namespace boost { namespace chrono {
+ namespace boost {
+ struct condition_variable
+ {
+ // ...
template <class Rep, class Period>
- class duration {
- public:
- typedef Rep rep;
- typedef Period period;
- private:
- rep rep_; // exposition only
- public:
- BOOST_CHRONO_CONSTEXPR duration() {} // = default;
- template <class Rep2>
- BOOST_CHRONO_CONSTEXPR explicit duration(const Rep2& r,
- typename boost::enable_if_c
- <
- boost::is_convertible<Rep2, rep>::value
- && (treat_as_floating_point<rep>::value
- || (!treat_as_floating_point<rep>::value
- && !treat_as_floating_point<Rep2>::value))
- >::type* = 0);
+ bool wait_for(mutex&, const boost::chrono::duration<Rep, Period>& d) {
+ boost::chrono::microseconds t = boost::chrono::duration_cast<boost::chrono::microseconds>(d);
+ std::cout << "wait_for " << t.count() << " microseconds\n";
+ return true;
+ }
- template <class Rep2, class Period2>
- BOOST_CHRONO_CONSTEXPR duration(const duration<Rep2, Period2>& d,
- typename boost::enable_if_c
- <
- treat_as_floating_point<rep>::value
- || (ratio_divide<Period2, period>::type::den == 1
- && !treat_as_floating_point<Rep2>::value)
- >::type* = 0);
+ template <class Clock, class Duration>
+ bool wait_until(mutex&, const boost::chrono::time_point<Clock, Duration>& t) {
+ using namespace boost::chrono;
+ typedef time_point<Clock, Duration> Time;
+ typedef system_clock::time_point SysTime;
+ if (t <= Clock::now())
+ return false;
+ typedef typename boost::common_type<typename Time::duration,
+ typename Clock::duration>::type D;
+ /* auto */ D d = t - Clock::now();
+ microseconds us = duration_cast<microseconds>(d);
+ SysTime st = system_clock::now() + us;
+ std::cout << "wait_until ";
+ detail::print_time(st);
+ std::cout << " which is " << (st - system_clock::now()).count()
+ << " microseconds away\n";
+ return true;
+ }
+ };
+ }
- //~duration() = default;
- //duration(const duration&) = default;
- //duration& operator=(const duration&) = default;
+Usage
- BOOST_CHRONO_CONSTEXPR rep count() const;
+ boost::mutex m;
+ boost::timed_mutex mut;
+ boost::condition_variable cv;
- BOOST_CHRONO_CONSTEXPR duration operator+();
- BOOST_CHRONO_CONSTEXPR duration operator-();
- duration& operator++();
- duration operator++(int);
- duration& operator--();
- duration operator--(int);
+ using namespace boost;
+ using namespace boost::chrono;
- duration& operator+=(const duration& d);
- duration& operator-=(const duration& d);
+ this_thread::sleep_for(seconds(3));
+ this_thread::sleep_for(nanoseconds(300));
+ system_clock::time_point time_limit = system_clock::now() + seconds(4) + milliseconds(500);
+ this_thread::sleep_until(time_limit);
- duration& operator*=(const rep& rhs);
- duration& operator/=(const rep& rhs);
- duration& operator%=(const rep& rhs);
- duration& operator%=(const duration& rhs);
+ mut.try_lock_for(milliseconds(30));
+ mut.try_lock_until(time_limit);
- static BOOST_CHRONO_CONSTEXPR duration zero();
- static BOOST_CHRONO_CONSTEXPR duration min();
- static BOOST_CHRONO_CONSTEXPR duration max();
- };
+ cv.wait_for(m, minutes(1)); // real code would put this in a loop
+ cv.wait_until(m, time_limit); // real code would put this in a loop
- }}
+ // For those who prefer floating point
+ this_thread::sleep_for(duration<double>(0.25));
+ this_thread::sleep_until(system_clock::now() + duration<double>(1.5));
-Rep must be an arithmetic type, or a class emulating an arithmetic type, compile diagnostic otherwise. If `duration` is instantiated with the type of `Rep` being a `duration`, compile diagnostic is issued.
-Period must be an instantiation of `ratio`, compile diagnostic otherwise.
+['See the source file [@../../example/simulated_thread_interface_demo.cpp example/simulated_thread_interface_demo.cpp]]
-Period::num must be positive, compile diagnostic otherwise.
-Examples:
+[endsect]
- duration<long, ratio<60> > holds a count of minutes using a long.
+[/================]
+[section Saturating]
- duration<long long, milli> holds a count of milliseconds using a long long.
+A "saturating" signed integral type is developed. This type has +/- infinity and a nan (like IEEE floating point) but otherwise obeys signed integral arithmetic. This class is subsequently used as the rep in boost::chrono::duration to demonstrate a duration class that does not silently ignore overflow.
- duration<double, ratio<1, 30> > holds a count using a double with a tick period of 1/30 second (a tick frequency of 30 Hz).
+['See the source file [@../../example/satutating.cpp example/satutating.cpp]]
-The following members of `duration` do not throw an exception unless the indicated operations on the representations throw an exception.
-[section:duration_c_1 Constructor `duration(const Rep2&)`]
+[endsect]
- template <class Rep2>
- BOOST_CHRONO_CONSTEXPR explicit duration(const Rep2& r);
+[/======================================================]
+[section Howard Hinnant's original demonstration program]
-[*Remarks:] `Rep2` is implicitly convertible to `rep`, and
+['See the source file [@../../example/time2_demo.cpp example/time2_demo.cpp]]
-* `treat_as_floating_point<rep>::value` is `true`, or
-* `!treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value` is `true`.
+[endsect]
-If these constraints are not met, this constructor shall not participate in overload resolution. [*Note:] This requirement prevents construction of an integral-based `duration` with a floating point representation. Such a construction could easily lead to confusion about the value of the `duration`.
+[/===============================================================]
+[section A tiny program that times how long until a key is struck]
-[*Example:]
+ #include <boost/chrono/chrono.hpp>
+ #include <iostream>
+ #include <iomanip>
- duration<int, milli> d(3.5); // do not compile
- duration<int, milli> d(3); // ok
+ using namespace boost::chrono;
-[*Effects:] Constructs an object of type `duration`.
+ template< class Clock >
+ class timer
+ {
+ typename Clock::time_point start;
+ public:
-[*PostConditions:] `count() == static_cast<rep>(r)`.
+ timer() : start( Clock::now() ) {}
-[endsect]
-[section:duration_c_2 Constructor `duration(const duration&)`]
+ typename Clock::duration elapsed() const
+ {
+ return Clock::now() - start;
+ }
- template <class Rep2, class Period2>
- BOOST_CHRONO_CONSTEXPR duration(const duration<Rep2, Period2>& d);
+ double seconds() const
+ {
+ return elapsed().count() * ((double)Clock::period::num/Clock::period::den);
+ }
+ };
-[*Remarks:] `treat_as_floating_point<rep>::value`, or `ratio_divide<Period2, period>::type::den == 1`, else this constructor shall not participate in overload resolution. [*note] This requirement prevents implicit truncation error when converting between integral-based `duration`s. Such a construction could easily lead to confusion about the value of the `duration`.
+ int main()
+ {
+ timer<system_clock> t1;
+ timer<monotonic_clock> t2;
+ timer<high_resolution_clock> t3;
-[*Example:]
+ std::cout << "Strike any key: ";
+ std::cin.get();
- duration<int, milli> ms(3);
- duration<int, micro> us = ms; // ok
- duration<int, milli> ms2 = us; // do not compile
+ std::cout << std::fixed << std::setprecision(9);
+ std::cout << "system_clock-----------: "
+ << t1.seconds() << " seconds\n";
+ std::cout << "monotonic_clock--------: "
+ << t2.seconds() << " seconds\n";
+ std::cout << "high_resolution_clock--: "
+ << t3.seconds() << " seconds\n";
-[*Effects:] Constructs an object of type `duration`, constructing `rep_` from `duration_cast<duration>(d).count()`.
+ system_clock::time_point d4 = system_clock::now();
+ system_clock::time_point d5 = system_clock::now();
-[endsect]
-[section:count Member function `count() const`]
+ std::cout << "\nsystem_clock latency-----------: " << (d5 - d4).count() << std::endl;
- BOOST_CHRONO_CONSTEXPR rep count() const;
+ monotonic_clock::time_point d6 = monotonic_clock::now();
+ monotonic_clock::time_point d7 = monotonic_clock::now();
-[*Returns:] `rep_v.
+ std::cout << "monotonic_clock latency--------: " << (d7 - d6).count() << std::endl;
-[endsect]
-[section:duration_operator_p Member function `operator+() const`]
+ high_resolution_clock::time_point d8 = high_resolution_clock::now();
+ high_resolution_clock::time_point d9 = high_resolution_clock::now();
- BOOST_CHRONO_CONSTEXPR duration operator+() const;
+ std::cout << "high_resolution_clock latency--: " << (d9 - d8).count() << std::endl;
-[*Returns:] `*this`.
+ std::time_t now = system_clock::to_time_t(system_clock::now());
-[endsect]
-[section:duration_operator_m Member function `operator+() const`]
+ std::cout << "\nsystem_clock::now() reports UTC is "
+ << std::asctime(std::gmtime(&now)) << "\n";
- BOOST_CHRONO_CONSTEXPR duration operator-() const;
+ return 0;
+ }
-[*Returns:] `duration(-rep_)`.
+['See the source file [@../../example/await_keystroke.cpp example/await_keystroke.cpp]]
[endsect]
-[section:duration_operator_pp Member function `operator++()`]
-
- duration& operator++();
-[*Effects:] `++rep_`.
+[/============================]
+[section stopclock_example.cpp]
-[*Returns:] `*this`.
+Here is the stopclock_example.cpp program supplied with the Boost Chrono library:
-[endsect]
-[section:duration_operator_pp2 Member function `operator++(int)`]
+[/stopclock_example_cpp]
- duration operator++(int);
+When the `stopclock<> t` object is created, it starts timing. When it is destroyed at the end of the program, its destructor stops the time counting and displays timing information on cout.
-[*Returns:] `duration(rep_++)v.
+ #include <boost/chrono/stopclock.hpp>
+ #include <cmath>
-[endsect]
-[section:duration_operator_mm Member function `operator++()`]
+ int main()
+ {
+ boost::chrono::stopclock<> t;
- duration& operator--();
+ for ( long i = 0; i < 10000000; ++i )
+ std::sqrt( 123.456L ); // burn some time
-[*Effects:] `--rep_`.
+ return 0;
+ }
-[*Returns:] `*this`.
+The output of this program run looks like this:
-[endsect]
-[section:duration_operator_mm2 Member function `operator++(int)`]
+ wall 0.42 s, user 0.41 s + system 0.00 s = total cpu 0.41 s, (96.3%)
- duration operator--(int);
+In other words, this program ran in 0.42 seconds as would be measured by a clock on the wall, the operating system charged it for 0.41 seconds of user CPU time and 0 seconds of system CPU time, the total of these two was 0.41, and that represented 96.3 percent of the wall clock time.
-[*Returns:] `duration(rep_--)`.
+['See the source file [@../../example/stopclock_example.cpp example/stopclock_example.cpp]]
[endsect]
-[section:duration_operator_pa Member function `operator+=(const duration&)`]
- duration& operator+=(const duration& d);
-
-[*Effects:] `rep_ += d.count()`.
-[*Returns:] `*this`.
+[/=============================]
+[section stopclock_example2.cpp]
-[endsect]
-[section:duration_operator_ma Member function `operator-=(const duration&)`]
+The stopclock_example2.cpp program is the same, except that it supplies additional constructor arguments from the command line:
- duration& operator-=(const duration& d);
+ #include <boost/chrono/stopclock.hpp>
+ #include <cmath>
-[*Effects:] `rep_ -= d.count()`.
+ int main( int argc, char * argv[] )
+ {
+ const char * format = argc > 1 ? argv[1] : "%t cpu seconds\n";
+ int places = argc > 2 ? std::atoi( argv[2] ) : 2;
-[*Returns:] `*this`.
+ boost::chrono::stopclock<> t( format, places );
-[endsect]
-[section:duration_operator_moda Member function `operator%=(const duration&)`]
+ for ( long i = 0; i < 10000000; ++i )
+ std::sqrt( 123.456L ); // burn some time
- duration& operator%=(const duration& d);
+ return 0;
+ }
-[*Effects:] `rep_ %= d.count()`.
+Here is the output for this program for several sets of command line arguments:
-[*Returns:] `*this`.
+ stopclock_example2
+ 0.42 cpu seconds
-[endsect]
-[section:duration_operator_proda Member function `operator*=(const rep&)`]
+ stopclock_example2 "%w wall clock seconds\n"
+ 0.41 wall clock seconds
- duration& operator*=(const rep& rhs);
+ stopclock_example2 "%w wall clock seconds\n" 6
+ 0.421875 wall clock seconds
-[*Effects:] `rep_ *= rhs`.
+ stopclock_example2 "%t total CPU seconds\n" 3
+ 0.422 total CPU seconds
-[*Returns:] `*this`.
+['See the source file [@../../example/stopclock_example2.cpp example/stopclock_example2.cpp]]
[endsect]
-[section:duration_operator_da Member function `operator/=(const rep&)`]
-
- duration& operator/=(const rep& rhs);
-[*Effects:] `rep_ /= rhs`.
+[/===============================================================]
+[section time command]
-[*Returns:] `*this`.
-
-[endsect]
-[section:duration_operator_moda_2 Member function `operator%=(const rep&)`]
+ #include <boost/chrono/stopclock.hpp>
+ #include <cstdlib>
+ #include <string>
+ #include <iostream>
- duration& operator%=(const rep& rhs);
+ int main( int argc, char * argv[] )
+ {
+ if ( argc == 1 )
+ {
+ std::cout << "invoke: timex [-v] command [args...]\n"
+ " command will be executed and timings displayed\n"
+ " -v option causes command and args to be displayed\n";
+ return 1;
+ }
-[*Effects:] `rep_ %= rhs`.
+ std::string s;
-[*Returns:] `*this`.
+ bool verbose = false;
+ if ( argc > 1 && *argv[1] == '-' && *(argv[1]+1) == 'v' )
+ {
+ verbose = true;
+ ++argv;
+ --argc;
+ }
-[endsect]
+ for ( int i = 1; i < argc; ++i )
+ {
+ if ( i > 1 ) s += ' ';
+ s += argv[i];
+ }
+ if ( verbose )
+ { std::cout << "command: \"" << s.c_str() << "\"\n"; }
-[section:duration_zero Static Member function `zero()`]
+ boost::chrono::stopclock<> t;
- static duration zero();
+ return std::system( s.c_str() );
+ }
-[*Returns:] `duration(duration_values<rep>::zero())`.
+['See the source file [@../../example/timex.cpp example/timex.cpp]]
[endsect]
-[section:duration_min Static Member function `min()`]
-
- static duration min();
-
-[*Returns:] `duration(duration_values<rep>::min()).`
[endsect]
-[section:duration_max Static Member function `max()`]
- static constexpr duration max();
+[/================================]
+[section:ext_references External Resources]
+[/================================]
-[*Returns:] `duration(duration_values<rep>::max())`.
+[variablelist
-[endsect]
+[
+ [[@http://www.open-std.org/jtc1/sc22/wg21 [*C++ Standards Committee's current Working Paper]]]
+ [The most authoritative reference material for the library is the C++ Standards Committee's current Working Paper (WP). 20.9 Time utilities "time", 20.4 Compile-time rational arithmetic "ratio", 20.6.7 Other transformations "meta.trans.other"]
+]
-[endsect]
+[
+ [[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]]]
+ [From Howard E. Hinnant, Walter E. Brown, Jeff Garland and Marc Paterno. Is very informative and provides motivation for key design decisions]
+]
-[section duration non-member arithmetic]
+[
+ [[@http://home.roadrunner.com/~hinnant/issue_review/lwg-defects.html#934 [*LGW 934. duration is missing operator%]]]
+ [From Terry Golubiewski. Is very informative and provides motivation for key design decisions]
+]
-[section:duration_operator_p_1 Non-Member function `operator+(duration,duration)`]
+[
+ [[@http://home.roadrunner.com/~hinnant/issue_review/lwg-active.html#1281 [*LWG 1281. CopyConstruction and Assignment between ratios having the same normalized form]]]
+ [From Vicente Juan Botet Escriba.]
+]
- template <class Rep1, class Period1, class Rep2, class Period2>
- typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
- operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+]
-[*Returns:] `CD(lhs) += rhs` where `CD` is the type of the return value.
+[endsect]
[endsect]
-[section:duration_operator_m_1 Non-Member function `operator-(duration,duration)`]
- template <class Rep1, class Period1, class Rep2, class Period2>
- typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
- operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+[/=================]
+[section:reference Reference ]
+[/=================]
-[*Returns:] `CD(lhs) -= rhs` where `CD` is the type of the return value.
+[section:cpp0x Included on the C++0x recommendation]
- template <class Rep1, class Period, class Rep2>
- duration<typename common_type<Rep1, Rep2>::type, Period>
- operator*(const duration<Rep1, Period>& d, const Rep2& s);
+[/===================================================================]
+[section:common_type_hpp Header `<boost/type_traits/common_type.hpp>`]
+[/===================================================================]
-[*Requires:] Let `CR` represent the `common_type` of `Rep1` and `Rep2`. This function will not participate in overload resolution unless both `Rep1` and `Rep2` are implicitly convertible to `CR`.
+ namespace boost {
+ template <class ...T> struct common_type;
+ }
-[*Returns:] `duration<CR, Period>(d) *= s`.
+[section:common_type Class Template `common_type`]
-[endsect]
-[section:duration_operator_prod_1 Non-Member function `operator*(Rep1,duration)`]
+`common_type` is a facility which is useful in specifying the type of the result of functions and operators which take a variety of types (e.g. "mixed mode" complex arithmetic).
- template <class Rep1, class Period, class Rep2>
- duration<typename common_type<Rep1, Rep2>::type, Period>
- operator*(const Rep1& s, const duration<Rep2, Period>& d);
+The nested typedef `common_type::type` could be defined as follows:
-[*Requires:] Let `CR` represent the `common_type` of `Rep1` and `Rep2`. This function will not participate in overload resolution unless both `Rep1` and `Rep2` are implicitly convertible to `CR`.
+ template <class T, class U = void, class V = void>
+ struct common_type {
+ typedef typename common_type<typename common_type<T, U>::type, V>::type type;
+ };
-[*Returns:] `d * s`.
+ template <class T>
+ struct common_type<T, void, void> {
+ typedef T type;
+ };
-[endsect]
-[section:duration_operator_d_1 Non-Member function `operator/(duration,Rep2)`]
+ template <class T, class U>
+ struct common_type<T, U, void> {
+ private:
+ static T m_t();
+ static U m_u();
+ static bool m_f(); // workaround gcc bug; not required by std
+ public:
+ typedef BOOST_TYPEOF_TPL(m_f() ? m_t() : m_u()) type;
+ };
- template <class Rep1, class Period, class Rep2>
- duration<typename common_type<Rep1, Rep2>::type, Period>
- operator/(const duration<Rep1, Period>& d, const Rep2& s);
+All parameter types must be complete. This trait is permitted to be specialized by a user if at least one template parameter is a user-defined type.
-[*Requires:] Let `CR` represent the `common_type` of `Rep1` and `Rep2`. This function will not participate in overload resolution unless both `Rep1` and `Rep2` are implicitly convertible to `CR`, and `Rep2` is not an instantiation of `duration`.
+[*Note:] Such specializations are required when only explicit conversions are desired among the `common_type` arguments.
-[*Returns:] `duration<CR, Period>(d) /= s`.
[endsect]
-[section:duration_operator_d_2 Non-Member function `operator/(duration,duration)`]
- template <class Rep1, class Period1, class Rep2, class Period2>
- typename common_type<Rep1, Rep2>::type
- operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+[endsect]
-[*Returns:] Let `CD` represent the `common_type` of the two `duration` arguments. Returns `CD(lhs).count() / CD(rhs).count()`.
-[endsect]
+[/===========================================]
+[section:ratio_hpp Header `<boost/ratio.hpp>`]
+[/===========================================]
-[section:duration_operator_d_3 Non-Member function `operator/(Rep1,duration)`]
+`ratio` is a facility which is useful in specifying compile time rational constants. Compile time rational arithmetic is supported with protection against overflow and divide by zero. Such a facility is very handy when needing to efficiently represent 1/3 of a nanosecond, or specifying an inch in terms of meters (for example 254/10000 meters - which `ratio` will reduce to 127/5000 meters).
- template <class Rep1, class Rep2, class Period>
- double operator/(const Rep1& s, const duration<Rep2, Period>& d);
+ namespace boost {
-[*Remarks:] Let `CR` represent the `common_type` of `Rep1` and `Rep2`. This function will not participate in overload resolution unless both `Rep1` and `Rep2` are implicitly convertible to `CR`, and `Rep1` is not an instantiation of `duration`.
+ template <boost::intmax_t N, boost::intmax_t D = 1> class ratio;
-[*Returns:] `CR(s)/duration<CR, Period>(d)`.
+ // ratio arithmetic
+ template <class R1, class R2> struct ratio_add;
+ template <class R1, class R2> struct ratio_subtract;
+ template <class R1, class R2> struct ratio_multiply;
+ template <class R1, class R2> struct ratio_divide;
-[endsect]
+ // ratio comparison
+ template <class R1, class R2> struct ratio_equal;
+ template <class R1, class R2> struct ratio_not_equal;
+ template <class R1, class R2> struct ratio_less;
+ template <class R1, class R2> struct ratio_less_equal;
+ template <class R1, class R2> struct ratio_greater;
+ template <class R1, class R2> struct ratio_greater_equal;
+ // convenience SI typedefs
+ typedef ratio<1LL, 1000000000000000000LL> atto;
+ typedef ratio<1LL, 1000000000000000LL> femto;
+ typedef ratio<1LL, 1000000000000LL> pico;
+ typedef ratio<1LL, 1000000000LL> nano;
+ typedef ratio<1LL, 1000000LL> micro;
+ typedef ratio<1LL, 1000LL> milli;
+ typedef ratio<1LL, 100LL> centi;
+ typedef ratio<1LL, 10LL> deci;
+ typedef ratio< 10LL, 1LL> deca;
+ typedef ratio< 100LL, 1LL> hecto;
+ typedef ratio< 1000LL, 1LL> kilo;
+ typedef ratio< 1000000LL, 1LL> mega;
+ typedef ratio< 1000000000LL, 1LL> giga;
+ typedef ratio< 1000000000000LL, 1LL> tera;
+ typedef ratio< 1000000000000000LL, 1LL> peta;
+ typedef ratio<1000000000000000000LL, 1LL> exa;
+ }
-[section:duration_operator_mod_1 Non-Member function `operator%(duration,Rep2)`]
- template <class Rep1, class Period, class Rep2>
- duration<typename common_type<Rep1, Rep2>::type, Period>
- operator%(const duration<Rep1, Period>& d, const Rep2& s);
+[section:ratio Class Template `ratio<>`]
-[*Remarks] This function will not participate in overload resolution unless Rep2 shall be implicitly convertible to CR(Rep1, Rep2) and Rep2 shall not be an instantiation of duration.
+ template <boost::intmax_t N, boost::intmax_t D>
+ class ratio {
+ public:
+ static const boost::intmax_t num;
+ static const boost::intmax_t den;
+ typedef ratio<num, den> type;
-[*Returns:] duration<CR(Rep1,Rep2), Period>(d) %= s.
-[endsect]
+ ratio() {}
-[section:duration_operator_mod_2 Non-Member function `operator%(duration,duration)`]
+ template <intmax_t _N2, intmax_t _D2>
+ ratio(const ratio<_N2, _D2>&,
+ typename enable_if_c
+ <
+ ratio<_N2, _D2>::num == num &&
+ ratio<_N2, _D2>::den == den
+ >::type* = 0) {}
- template <class Rep1, class Period1, class Rep2, class Period2>
- typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
- operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+ template <intmax_t _N2, intmax_t _D2>
+ typename enable_if_c
+ <
+ ratio<_N2, _D2>::num == num &&
+ ratio<_N2, _D2>::den == den,
+ ratio&
+ >::type
+ operator=(const ratio<_N2, _D2>&) {return *this;}
+ };
-[*Remarks] This function will not participate in overload resolution unless
+A diagnostic will be emitted if `ratio` is instantiated with `D == 0`, or if the absolute value of `N` or `D` can not be represented. [*Note:] These rules ensure that infinite ratios are avoided and that for any negative input, there exists a representable value of its absolute value which is positive. In a two's complement representation, this excludes the most negative value.
-[*Returns:] CD(lhs) %= CD(rhs)
+Let `gcd` denote the greatest common divisor of `N`'s absolute value and of `D`'s absolute value.
-[endsect]
-[endsect]
+* `num` has the value `sign(N)*sign(D)*abs(N)/gcd`.
-[section duration comparaisons]
+* `den` has the value `abs(D)/gcd`.
-[section:duration_operator_eq_1 Non-Member function `operator==(duration,duration)`]
+The nested typedef `type` denotes the normalized form of this ratio type. It should be used when the template parameters doesn't give a normalized form.
- template <class Rep1, class Period1, class Rep2, class Period2>
- bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+Two `ratio` classes `ratio<N1,D1>` and `ratio<N2,D2>` have the same normalized form if `ratio<N1,D1>::type` is the same type as `ratio<N2,D2>::type`
-[*Returns:] Let `CD` represent the `common_type` of the two `duration` arguments. Returns `CD(lhs).count() == CD(rhs).count()`
+[section Construction and assignment]
-[endsect]
-[section:duration_operator_neq_1 Non-Member function `operator!=(duration,duration)`]
+ template <intmax_t N2, intmax_t D2>
+ ratio(const ratio<N2, D2>& r);
- template <class Rep1, class Period1, class Rep2, class Period2>
- bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+[*Effects:] Constructs a `ratio` object.
-[*Returns:] `!(lhs == rhs)`.
+[*Remarks:] This constructor will not participate in overload resolution unless `r` has the same normalized form as `*this`.
-[endsect]
-[section:duration_operator_lt_1 Non-Member function `operator<(duration,duration)`]
+ template <intmax_t N2, intmax_t D2>
+ ratio& operator=(const ratio<N2, D2>& r);
- template <class Rep1, class Period1, class Rep2, class Period2>
- bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+[*Effects:] Assigns a `ratio` object.
-[*Returns:] Let `CD` represent the `common_type` of the two `duration` arguments. Returns `CD(lhs).count() < CD(rhs).count()`
+[*Returns:] *this.
+
+[*Remarks:] This operator will not participate in overload resolution unless `r` has the same normalized form as `*this`.
[endsect]
-[section:duration_operator_leq_1 Non-Member function `operator<=(duration,duration)`]
- template <class Rep1, class Period1, class Rep2, class Period2>
- bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
-
-[*Returns:] `!(rhs < lhs)`.
[endsect]
-[section:duration_operator_gt_1 Non-Member function `operator>(duration,duration)`]
-
- template <class Rep1, class Period1, class Rep2, class Period2>
- bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
-[*Returns:] `rhs < lhs`.
-[endsect]
-[section:duration_operator_gteq_1 Non-Member function `operator>=(duration,duration)`]
+[section:ratio_arithmetic `ratio` arithmetic]
- template <class Rep1, class Period1, class Rep2, class Period2>
- bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+For each of the class templates in this clause, each template parameter refers to a `ratio`. If the implementation is unable to form the indicated `ratio` due to overflow, a diagnostic will be issued.
-[*Returns:] `!(lhs < rhs)`.
+ template <class R1, class R2> struct ratio_add {
+ typedef [/see below] type;
+ };
-[endsect]
-[endsect]
-[section:duration_cast Non-Member function `duration_cast(duration)`]
+The nested typedef `type` is a synonym for `ratio<R1::num * R2::den + R2::num * R1::den, R1::den * R2::den>::type`.
- template <class ToDuration, class Rep, class Period>
- ToDuration duration_cast(const duration<Rep, Period>& d);
+ template <class R1, class R2> struct ratio_subtract {
+ typedef [/see below] type;
+ };
-[*Requires:] This function will not participate in overload resolution unless `ToDuration` is an instantiation of `duration`.
+The nested typedef `type` is a synonym for `ratio<R1::num * R2::den - R2::num * R1::den, R1::den * R2::den>::type`.
-[*Returns:] Forms `CF` which is a `ratio` resulting from `ratio_divide<Period, typename ToDuration::period>::type`. Let `CR` be the `common_type` of `ToDuration::rep`, `Rep`, and `intmax_t`.
+ template <class R1, class R2> struct ratio_multiply {
+ typedef [/see below] type;
+ };
-* If `CF::num == 1` and `CF::den == 1`, then returns `ToDuration(static_cast<typename ToDuration::rep>(d.count())) `
-* else if `CF::num != 1` and `CF::den == 1`, then returns
- `ToDuration(static_cast<typename ToDuration::rep>(static_cast<CR>(d.count()) *
- static_cast<CR>(CF::num)))`
-* else if `CF::num == 1` and `CF::den != 1`, then returns
- `ToDuration(static_cast<typename ToDuration::rep>(static_cast<CR>(d.count()) /
- static_cast<CR>(CF::den)))`
-* else returns
- `ToDuration(static_cast<typename ToDuration::rep>(static_cast<CR>(d.count()) *
- static_cast<CR>(CF::num) /
- static_cast<CR>(CF::den)))`
+The nested typedef `type` is a synonym for `ratio<R1::num * R2::num, R1::den * R2::den>::type`.
-[*Remarks:] This function does not rely on any implicit conversions. All conversions must be accomplished through `static_cast`. The implementation avoids all multiplications or divisions when it is known at compile time that it can be avoided because one or more arguments are `1`. All intermediate computations are carried out in the widest possible representation and only converted to the destination representation at the final step.
+ template <class R1, class R2> struct ratio_divide {
+ typedef [/see below] type;
+ };
+The nested typedef `type` is a synonym for `ratio<R1::num * R2::den, R2::num * R1::den>::type`.
[endsect]
+[section:ratio_comparison `ratio` comparison]
+ template <class R1, class R2> struct ratio_equal
+ : public boost::integral_constant<bool, [/see below] > {};
-[section Class template `time_point`]
-
-A `time_point` represents a point in time with respect to a specific clock.
+If R1::num == R2::num && R1::den == R2::den, ratio_equal derives from true_type, else derives from false_type.
- template <class Clock, class Duration>
- class time_point {
- public:
- typedef Clock clock;
- typedef Duration duration;
- typedef typename duration::rep rep;
- typedef typename duration::period period;
- private:
- duration d_; // exposition only
- public:
- time_point();
- explicit time_point(const duration& d);
+ template <class R1, class R2>
+ struct ratio_less
+ : public boost::integral_constant<bool, [/see below] > {};
- // conversions
- template <class Duration2>
- time_point(const time_point<clock, Duration2>& t,
- typename boost::enable_if
- <
- boost::is_convertible<Duration2, duration>
- >::type* = 0);
+If R1::num * R2::den < R2::num * R1::den, ratio_less derives from true_type, else derives from false_type.
- // observer
+ template <class R1, class R2> struct ratio_not_equal
+ : public boost::integral_constant<bool, !ratio_equal<R1, R2>::value> {};
- duration time_since_epoch() const;
+ template <class R1, class R2> struct ratio_less_equal
+ : public boost::integral_constant<bool, !ratio_less<R2, R1>::value> {};
- // arithmetic
+ template <class R1, class R2> struct ratio_greater
+ : public boost::integral_constant<bool, ratio_less<R2, R1>::value> {};
- time_point& operator+=(const duration& d);
- time_point& operator-=(const duration& d);
+ template <class R1, class R2> struct ratio_greater_equal
+ : public boost::integral_constant<bool, !ratio_less<R1, R2>::value> {};
- // special values
- static BOOST_CHRONO_CONSTEXPR time_point min();
- static BOOST_CHRONO_CONSTEXPR time_point max();
- };
+[endsect]
-Clock must meet the Clock Requirements.
+[section:ration_SI_typedefs SI typedefs]
-Duration must be an instantiation of `duration`, compile diagnostic otherwise.
+ // convenience SI typedefs
+ typedef ratio<1LL, 1000000000000000000LL> atto;
+ typedef ratio<1LL, 1000000000000000LL> femto;
+ typedef ratio<1LL, 1000000000000LL> pico;
+ typedef ratio<1LL, 1000000000LL> nano;
+ typedef ratio<1LL, 1000000LL> micro;
+ typedef ratio<1LL, 1000LL> milli;
+ typedef ratio<1LL, 100LL> centi;
+ typedef ratio<1LL, 10LL> deci;
+ typedef ratio< 10LL, 1LL> deca;
+ typedef ratio< 100LL, 1LL> hecto;
+ typedef ratio< 1000LL, 1LL> kilo;
+ typedef ratio< 1000000LL, 1LL> mega;
+ typedef ratio< 1000000000LL, 1LL> giga;
+ typedef ratio< 1000000000000LL, 1LL> tera;
+ typedef ratio< 1000000000000000LL, 1LL> peta;
+ typedef ratio<1000000000000000000LL, 1LL> exa;
-[section:time_point_c_1 Constructor `time_point()`]
- time_point();
+Four of the typedefs in the recomendation which can be conditionally supported are not supported: yocto, zepto, zetta and yotta.
-[*Effects:] Constructs an object of `time_point`, initializing `d_` with `duration::zero()`. This `time_point` represents the epoch.
+ typedef ratio<1, 1000000000000000000000000> yocto; // conditionally supported
+ typedef ratio<1, 1000000000000000000000> zepto; // conditionally supported
+ typedef ratio< 1000000000000000000000, 1> zetta; // conditionally supported
+ typedef ratio<1000000000000000000000000, 1> yotta; // conditionally supported
[endsect]
-[section:time_point_c_2 Constructor `time_point(const duration&)`]
-
- time_point(const duration& d);
-
-[*Effects:] Constructs an object of `time_point`, initializing `d_` with `d`. This `time_point` represents the epoch `+ d`.
[endsect]
-[section:time_point_c_3 Constructor `time_point(const duration&)`]
-
- template <class Duration2> time_point(const time_point<clock, Duration2>& t);
-
-[*Requires:] This function will not participate in overload resolution unless `Duration2` is implicitly convertible to `duration`.
-[*Effects:] Constructs an object of `time_point`, initializing `d_` with `t.time_since_epoch()`.
-
-[endsect]
+[/=============================================]
+[section:chrono_hpp Header `<boost/chrono.hpp>`]
+[/=============================================]
-[section:time_since_epoch Member function `time_since_epoch() const`]
+This file is a redirection to `boost/chrono/chrono.hpp` including in addition registration for `duration<>` and `timepoint<>` class templates to Boost.Typeof.
- duration time_since_epoch() const;
-[*Returns:] `d_`.
+ #include <boost/chrono/chrono.hpp>
+ #include <boost/chrono/typeof/boost/chrono/chrono.hpp>
[endsect]
-[section:time_point_operator_pe Member function `operator+=`]
- time_point& operator+=(const duration& d);
+[/=============================================]
+[section:chrono_chrono_hpp Header `<boost/chrono/chrono.hpp>`]
+[/=============================================]
-[*Effects:] `d_ += d`.
+ #define BOOST_SYSTEM_CLOCK_DURATION
+ #define BOOST_CHRONO_HAS_CLOCK_MONOTONIC
-[*Returns:] `*this`.
+ namespace boost {
+ namespace chrono {
-[endsect]
-[section:time_point_operator_me Member function `operator-=`]
+ template <class Rep, class Period = ratio<1> > class duration;
+ template <class Clock, class Duration = typename Clock::duration> class time_point;
- time_point& operator-=(const duration& d);
+ }
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ struct common_type<chrono::duration<Rep1, Period1>,
+ chrono::duration<Rep2, Period2> >;
-[*Effects:] `d_ -= d`
+ template <class Clock, class Duration1, class Duration2>
+ struct common_type<chrono::time_point<Clock, Duration1>,
+ chrono::time_point<Clock, Duration2> >;
-[*Returns:] `*this`.
+ namespace chrono {
-[endsect]
-[section:time_point_min Static Member function `min`]
+ // customization traits
+ template <class Rep> struct treat_as_floating_point;
+ template <class Rep> struct duration_values;
- static BOOST_CHRONO_CONSTEXPR time_point min();
+ // duration arithmetic
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
+ operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
-[*Returns:] `time_point(duration::min())`.
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
+ operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
-[endsect]
-[section:time_point_max Static Member function `max`]
+ template <class Rep1, class Period, class Rep2>
+ duration<typename common_type<Rep1, Rep2>::type, Period>
+ operator*(const duration<Rep1, Period>& d, const Rep2& s);
- static BOOST_CHRONO_CONSTEXPR time_point max();
+ template <class Rep1, class Period, class Rep2>
+ duration<typename common_type<Rep1, Rep2>::type, Period>
+ operator*(const Rep1& s, const duration<Rep2, Period>& d);
-[*Returns:] `time_point(duration::max())`.
+ template <class Rep1, class Period, class Rep2>
+ duration<typename common_type<Rep1, Rep2>::type, Period>
+ operator/(const duration<Rep1, Period>& d, const Rep2& s);
-[endsect]
-[endsect]
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ typename common_type<Rep1, Rep2>::type
+ operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+ template <class Rep1, class Rep2, class Period>
+ double operator/(const Rep1& s, const duration<Rep2, Period>& d);
-[section time_point non-member arithmetic]
+ // duration comparisons
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
-[section:time_point_operator_p_1 Non-Member function `operator+(time_point,duration)`]
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Clock, class Duration1, class Rep2, class Period2>
- time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
- operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
-[*Returns:] `CT(lhs) += rhs` where `CT` is the type of the return value.
+ // duration_cast
-[endsect]
-[section:time_point_operator_p_2 Non-Member function `operator+(duration,time_point)`]
+ template <class ToDuration, class Rep, class Period>
+ ToDuration duration_cast(const duration<Rep, Period>& d);
- template <class Rep1, class Period1, class Clock, class Duration2>
- time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
- operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
+ // convenience typedefs
+ typedef duration<boost::int_least64_t, nano> nanoseconds; // at least 64 bits needed
+ typedef duration<boost::int_least64_t, micro> microseconds; // at least 55 bits needed
+ typedef duration<boost::int_least64_t, milli> milliseconds; // at least 45 bits needed
+ typedef duration<boost::int_least64_t> seconds; // at least 35 bits needed
+ typedef duration<boost::int_least32_t, ratio< 60> > minutes; // at least 29 bits needed
+ typedef duration<boost::int_least32_t, ratio<3600> > hours; // at least 23 bits needed
-[*Returns:] `rhs + lhs`.
+ // time_point arithmetic
+ template <class Clock, class Duration1, class Rep2, class Period2>
+ time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
+ operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
-[endsect]
-[section:time_point_operator_m_1 Non-Member function `operator-(time_point,duration)`]
+ template <class Rep1, class Period1, class Clock, class Duration2>
+ time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
+ operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
- template <class Clock, class Duration1, class Rep2, class Period2>
- time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
- operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
+ template <class Clock, class Duration1, class Rep2, class Period2>
+ time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
+ operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
-[*Returns:] `lhs + (-rhs)`.
+ template <class Clock, class Duration1, class Duration2>
+ typename common_type<Duration1, Duration2>::type
+ operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
-[endsect]
-[section:time_point_operator_m_2 Non-Member function `operator-(duration,time_point)`]
+ // time_point comparisons
+ template <class Clock, class Duration1, class Duration2>
+ bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
+ template <class Clock, class Duration1, class Duration2>
+ bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
+ template <class Clock, class Duration1, class Duration2>
+ bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
+ template <class Clock, class Duration1, class Duration2>
+ bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
+ template <class Clock, class Duration1, class Duration2>
+ bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
+ template <class Clock, class Duration1, class Duration2>
+ bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock,
+ Duration2>& rhs);
- template <class Clock, class Duration1, class Duration2>
- typename common_type<Duration1, Duration2>::type
- operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+ // time_point_cast
+ template <class ToDuration, class Clock, class Duration>
+ time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
-[*Returns:] `lhs.time_since_epoch() - rhs.time_since_epoch()`.
+ // Clocks
+ class system_clock;
+ class monotonic_clock;
+ class high_resolution_clock;
-[endsect]
-[endsect]
+ }
+ }
-[section time_point comparisons]
-[section:time_point_operator_eq Non-Member function `operator==(time_point,time_point)`]
+[section:clock `Clock` Requirements]
- template <class Clock, class Duration1, class Duration2>
- bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+A clock represents a bundle consisting of a native `duration`, a native `time_point`, and a function `now()` to get the current `time_point`. A clock must meet the requirements in the following Table.
-[*Returns:] `lhs.time_since_epoch() == rhs.time_since_epoch()`.
+In this table `C1` and `C2` denote `clock` types. `t1` and `t2` are values returned from `C1::now()` where the call returning `t1` happens before the call returning `t2` and both of these calls happen before `C1::time_point::max()`.
-[endsect]
-[section:time_point_operator_neq Non-Member function `operator!=(time_point,time_point)`]
+[table Clock Requirements
+ [[expression] [return type] [operational semantics]]
+ [[`C1::rep`] [An arithmetic type or class emulating an arithmetic type. ] [The representation type of the native `duration` and `time_point`.]]
+ [[`C1::period`] [`ratio`] [The tick period of the clock in seconds.]]
+ [[`C1::duration`] [`chrono::duration<C1::rep, C1::period>`] [The native `duration` type of the `clock`.]]
+ [[`C1::time_point`] [`chrono::time_point<C1> or chrono::time_point<C2, C1::duration>`] [The native `time_point` type of the `clock`. Different clocks are permitted to share a `time_point` definition if it is valid to compare their time_points by comparing their respective `duration`s. `C1` and `C2` must refer to the same epoch.]]
+ [[`C1::is_monotonic`] [`const bool`] [`true` if `t1 <= t2` is always `true`, else `false`. [*Note: A `clock` that can be adjusted backwards is not monotonic]]]
+ [[`C1::now()`] [`C1::time_point`] [Returns a `time_point` representing the current point in time.]]
+]
-template <class Clock, class Duration1, class Duration2>
- bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
-[*Returns:] `!(lhs == rhs)`.
+Models of Clock:
-[endsect]
-[section:time_point_operator_lt Non-Member function `operator<(time_point,time_point)`]
+* [@boost_chrono/reference/cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_ system_clock]
+* [@boost_chrono/reference/cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__monotonic_clock_ monotonic_clock]
+* [@boost_chrono/reference/cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__high_resolution_clock_ high_resolution_clock]
+* [@boost_chrono/reference/other_clocks.html#boost_chrono.reference.other_clocks.process_cpu_clocks_hpp.class__process_real_cpu_clock_ process_real_cpu_clock]
+* [@boost_chrono/reference/other_clocks.html#boost_chrono.reference.other_clocks.process_cpu_clocks_hpp.class__process_user_cpu_clock_ process_user_cpu_clock]
+* [@boost_chrono/reference/other_clocks.html#boost_chrono.reference.other_clocks.process_cpu_clocks_hpp.class__process_system_cpu_clock_ process_system_cpu_clock]
+* [@boost_chrono/reference/other_clocks.html#boost_chrono.reference.other_clocks.thread_clock_hpp.class__thread_clock_ thread_clock]
- template <class Clock, class Duration1, class Duration2>
- bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+[endsect]
-[*Returns:] lhs.time_since_epoch() < rhs.time_since_epoch().
+[section Time-related traits]
+[section:treat_as_floating_point Metafunction `treat_as_floating_point<>`]
-[endsect]
-[section:time_point_operator_leq Non-Member function `operator<=(time_point,time_point)`]
+ template <class Rep> struct treat_as_floating_point
+ : boost::is_floating_point<Rep> {};
- template <class Clock, class Duration1, class Duration2>
- bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+The `duration` template uses the `treat_as_floating_point` trait to help determine if a `duration` with one tick period can be converted to another `duration` with a different tick period. If `treat_as_floating_point<Rep>::value` is `true`, then `Rep` is a floating point type and implicit conversions are allowed among `duration`s. Otherwise, the implicit convertibility depends on the tick periods of the `duration`s. If `Rep` is a class type which emulates a floating point type, the author of `Rep` can specialize `treat_as_floating_point` so that `duration` will treat this `Rep` as if it were a floating point type. Otherwise `Rep` is assumed to be an integral type, or a class emulating an integral type.
-[*Returns:] `!(rhs < lhs)`.
[endsect]
-[section:time_point_operator_gt Non-Member function `operator>(time_point,time_point)`]
+[section:duration_values Class template `duration_values`]
-template <class Clock, class Duration1, class Duration2>
- bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+ template <class Rep>
+ struct duration_values
+ {
+ public:
+ static BOOST_CHRONO_CONSTEXPR Rep zero();
+ static BOOST_CHRONO_CONSTEXPR Rep max();
+ static BOOST_CHRONO_CONSTEXPR Rep min();
+ };
-[*Returns:] `rhs < lhs`.
+The `duration` template uses the `duration_values` trait to construct special values of the `duration`s representation (`Rep`). This is done because the representation might be a class type with behavior which requires some other implementation to return these special values. In that case, the author of that class type should specialize `duration_values` to return the indicated values.
-[endsect]
-[section:time_point_operator_geq Non-Member function `operator>=(time_point,time_point)`]
+[section:zero Static member Function `zero()`]
- template <class Clock, class Duration1, class Duration2>
- bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+ static BOOST_CHRONO_CONSTEXPR Rep zero();
-[*Returns:] `!(lhs < rhs)`.
+[*Returns:] `Rep(0)`. [*Note:] `Rep(0)` is specified instead of `Rep()` since `Rep()` may have some other meaning, such as an uninitialized value.
+
+[*Remarks:] The value returned corresponds to the additive identity.
[endsect]
-[section:time_point_cast Non-Member function `time_point_cast(time_point)`]
+[section:max Static member function `max()`]
- template <class ToDuration, class Clock, class Duration>
- time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
+ static BOOST_CHRONO_CONSTEXPR Rep max();
-[*Requires:] This function will not participate in overload resolution unless `ToDuration` is an instantiation of `duration`.
+[*Returns:] `numeric_limits<Rep>::max()`.
-[*Returns:] `time_point<Clock, ToDuration>(duration_cast<ToDuration>(t.time_since_epoch()))`.
+[*Remarks:] The value returned compares greater than zero().
[endsect]
-[endsect]
-
+[section:min Static member function `min()`]
-[section Class `system_clock`]
+ static BOOST_CHRONO_CONSTEXPR Rep min();
-The `system_clock` class provides a means of obtaining the current wall-clock time from the system-wide real-time clock. The current time can be obtained by calling `system_clock::now()`. Instances of `system_clock::time_point` can be converted to and from time_t with the `system_clock::to_time_t()` and `system_clock::to_time_point()` functions. If system clock is not monotonic, a subsequent call to `system_clock::now()` may return an earlier time than a previous call (e.g. if the operating system clock is manually adjusted, or synchronized with an external clock).
+[*Returns:] `numeric_limits<Rep>::lowest()`.
- class system_clock {
- public:
- typedef BOOST_SYSTEM_CLOCK_DURATION duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<system_clock> time_point;
- static const bool is_monotonic = false;
+[*Remarks:] The value returned compares less than or equal to `zero()`.
- static time_point now(); // throws on error
- static time_point now(system::error_code & ec); // never throws
+[endsect]
- static std::time_t to_time_t(const time_point& t);
- static time_point from_time_t(std::time_t t);
- };
+[endsect]
-`system_clock` satisfy the Clock Requirements. In addition:
+[section `common_type` specializations]
-* `system_clock::duration::min() < system_clock::duration::zero()` is `true`.
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2> >
+ {
+ typedef chrono::duration<typename common_type<Rep1, Rep2>::type, see below> type;
+ };
+The period of the `duration` indicated by this specialization of `common_type` is the greatest common divisor of `Period1` and `Period2`. This can be computed by forming a `ratio` of the greatest common divisor of `Period1::num` and `Period2::num`, and the least common multiple of `Period1::den` and `Period2::den`.
-[section:to_time_t Static member function `to_time_t(time_point)`]
+[*Note:] The typedef type is the `duration` with the largest tick period possible where both `duration` arguments will convert to it without requiring a division operation. The representation of this type is intended to be able to hold any value resulting from this conversion, with the possible exception of round-off error when floating point `duration`s are involved (but not truncation error).
-time_t to_time_t(const time_point& t);
+ template <class Clock, class Duration1, class Duration2>
+ struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2> >
+ {
+ typedef chrono::time_point<Clock, typename common_type<Duration1, Duration2>::type> type;
+ };
-[*Returns:] A `time_t` such that the `time_t` and `t` represent the same point in time, truncated to the courser of the precisions among `time_t` and `t`.
+The `common_type` of two `time_point`s is a `time_point` with the same `clock` (both have the same `clock`), and the `common_type` of the two `duration`s.
[endsect]
-[section:from_time_t Static member function `from_time_t(time_t)`]
- time_point from_time_t(time_t t);
-
-[*Returns:] A `time_point` such that the `time_point` and `t` represent the same point in time, truncated to the courser of the precisions among `time_point` and `t`.
[endsect]
-[endsect]
-[section Class `monotonic_clock`]
+[section Class template `duration`]
-`monotonic_clock` satisfy the Clock Requirements.
+A `duration` measures time between two points in time (`time_point`). A `duration` has a representation which holds a count of ticks, and a tick period. The tick period is the amount of time which occurs from one tick to another in units of a second. It is expressed as a rational constant using `ratio`.
-`monotonic_clock` class provides access to the system-wide monotonic clock. The current time can be obtained by calling `monotonic_clock::now()`. There is no fixed relationship between values returned by `monotonic_clock::now()` and wall-clock time.
+ namespace boost { namespace chrono {
- #ifdef BOOST_HAS_CLOCK_MONOTONIC
- class BOOST_CHRONO_DECL monotonic_clock {
+ template <class Rep, class Period>
+ class duration {
public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<monotonic_clock> time_point;
- static const bool is_monotonic = true;
+ typedef Rep rep;
+ typedef Period period;
+ private:
+ rep rep_; // exposition only
+ public:
+ BOOST_CHRONO_CONSTEXPR duration() {} // = default;
+ template <class Rep2>
+ BOOST_CHRONO_CONSTEXPR explicit duration(const Rep2& r,
+ typename boost::enable_if_c
+ <
+ boost::is_convertible<Rep2, rep>::value
+ && (treat_as_floating_point<rep>::value
+ || (!treat_as_floating_point<rep>::value
+ && !treat_as_floating_point<Rep2>::value))
+ >::type* = 0);
- static time_point now(); // throws on error
- static time_point now(system::error_code & ec); // never throws
- };
- #endif
+ template <class Rep2, class Period2>
+ BOOST_CHRONO_CONSTEXPR duration(const duration<Rep2, Period2>& d,
+ typename boost::enable_if_c
+ <
+ treat_as_floating_point<rep>::value
+ || (ratio_divide<Period2, period>::type::den == 1
+ && !treat_as_floating_point<Rep2>::value)
+ >::type* = 0);
-[endsect]
+ //~duration() = default;
+ //duration(const duration&) = default;
+ //duration& operator=(const duration&) = default;
-[section Class `high_resolution_clock`]
+ BOOST_CHRONO_CONSTEXPR rep count() const;
-`high_resolution_clock` satisfy the Clock Requirements.
+ BOOST_CHRONO_CONSTEXPR duration operator+();
+ BOOST_CHRONO_CONSTEXPR duration operator-();
+ duration& operator++();
+ duration operator++(int);
+ duration& operator--();
+ duration operator--(int);
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef monotonic_clock high_resolution_clock; // as permitted by [time.clock.hires]
- #else
- typedef system_clock high_resolution_clock; // as permitted by [time.clock.hires]
- #endif
+ duration& operator+=(const duration& d);
+ duration& operator-=(const duration& d);
-[endsect]
+ duration& operator*=(const rep& rhs);
+ duration& operator/=(const rep& rhs);
+ duration& operator%=(const rep& rhs);
+ duration& operator%=(const duration& rhs);
-[endsect]
+ static BOOST_CHRONO_CONSTEXPR duration zero();
+ static BOOST_CHRONO_CONSTEXPR duration min();
+ static BOOST_CHRONO_CONSTEXPR duration max();
+ };
-[/=============================================]
-[section:chrono_typeof_hpp Header `<boost/chrono/typeof/boost/chrono/chorno.hpp>`]
-[/=============================================]
+ }}
-Register `duration<>` and `timepoint<>` class templates to Boost.Typeof.
+Rep must be an arithmetic type, or a class emulating an arithmetic type, compile diagnostic otherwise. If `duration` is instantiated with the type of `Rep` being a `duration`, compile diagnostic is issued.
-[endsect]
-[endsect]
+Period must be an instantiation of `ratio`, compile diagnostic otherwise.
-[section Other clocks]
+Period::num must be positive, compile diagnostic otherwise.
-[/==================================================================]
-[section:process_cpu_clocks_hpp Header `<boost/chrono/process_cpu_clocks.hpp>`]
-[/==================================================================]
+Examples:
-Knowing how long a program takes to execute is useful in both test and production environments. It is also helpful if such timing information is broken down into real (wall clock) time, CPU time spent by the user, and CPU time spent by the operating system servicing user requests.
+ duration<long, ratio<60> > holds a count of minutes using a long.
- namespace boost { namespace chrono {
+ duration<long long, milli> holds a count of milliseconds using a long long.
- class process_real_cpu_clock;
- class process_user_cpu_clock;
- class process_system_cpu_clock;
- class process_cpu_clock;
+ duration<double, ratio<1, 30> > holds a count using a double with a tick period of 1/30 second (a tick frequency of 30 Hz).
- } }
+The following members of `duration` do not throw an exception unless the indicated operations on the representations throw an exception.
-[section Class `process_real_cpu_clock`]
+[section:duration_c_1 Constructor `duration(const Rep2&)`]
-`process_real_cpu_clock` satisfy the Clock Requirements.
+ template <class Rep2>
+ BOOST_CHRONO_CONSTEXPR explicit duration(const Rep2& r);
-`process_real_cpu_clock` class provides access to the real process wall-clock monotonic clock, i.e. the real CPU-time clock of the calling process. The process relative current time can be obtained by calling `process_real_cpu_clock::now()`.
+[*Remarks:] `Rep2` is implicitly convertible to `rep`, and
- class process_real_cpu_clock {
- public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<process_real_cpu_clock> time_point;
- static const bool is_monotonic = true;
+* `treat_as_floating_point<rep>::value` is `true`, or
+* `!treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value` is `true`.
- static time_point now( system::error_code & ec = system::throws );
- };
+If these constraints are not met, this constructor shall not participate in overload resolution. [*Note:] This requirement prevents construction of an integral-based `duration` with a floating point representation. Such a construction could easily lead to confusion about the value of the `duration`.
+
+[*Example:]
+
+ duration<int, milli> d(3.5); // do not compile
+ duration<int, milli> d(3); // ok
+
+[*Effects:] Constructs an object of type `duration`.
+[*PostConditions:] `count() == static_cast<rep>(r)`.
[endsect]
-[section Class `process_user_cpu_clock`]
+[section:duration_c_2 Constructor `duration(const duration&)`]
-`process_user_cpu_clock` satisfy the Clock Requirements.
+ template <class Rep2, class Period2>
+ BOOST_CHRONO_CONSTEXPR duration(const duration<Rep2, Period2>& d);
-`process_user_cpu_clock` class provides access to the user CPU-time monotonic clock of the calling process. The process relative user current time can be obtained by calling `process_user_cpu_clock::now()`.
+[*Remarks:] `treat_as_floating_point<rep>::value`, or `ratio_divide<Period2, period>::type::den == 1`, else this constructor shall not participate in overload resolution. [*note] This requirement prevents implicit truncation error when converting between integral-based `duration`s. Such a construction could easily lead to confusion about the value of the `duration`.
- class process_user_cpu_clock {
- public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<process_user_cpu_clock> time_point;
- static const bool is_monotonic = true;
+[*Example:]
- static time_point now( system::error_code & ec = system::throws );
- };
+ duration<int, milli> ms(3);
+ duration<int, micro> us = ms; // ok
+ duration<int, milli> ms2 = us; // do not compile
+[*Effects:] Constructs an object of type `duration`, constructing `rep_` from `duration_cast<duration>(d).count()`.
[endsect]
+[section:count Member function `count() const`]
-[section Class `process_system_cpu_clock`]
-
-`process_system_cpu_clock` satisfy the Clock Requirements.
+ BOOST_CHRONO_CONSTEXPR rep count() const;
-`process_system_cpu_clock` class provides access to the system CPU-time monotonic clockof the calling process. The process relative system current time can be obtained by calling `process_system_cpu_clock::now()`.
+[*Returns:] `rep_v.
- class process_system_cpu_clock {
- public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<process_system_cpu_clock> time_point;
- static const bool is_monotonic = true;
+[endsect]
+[section:duration_operator_p Member function `operator+() const`]
- static time_point now( system::error_code & ec = system::throws );
- };
+ BOOST_CHRONO_CONSTEXPR duration operator+() const;
+[*Returns:] `*this`.
[endsect]
+[section:duration_operator_m Member function `operator+() const`]
-[section Class `process_cpu_clock`]
+ BOOST_CHRONO_CONSTEXPR duration operator-() const;
-`process_cpu_clock` can be considered as a `tuple<process_real_cpu_clock, process_user_cpu_clock, process_system_cpu_clock>`.
+[*Returns:] `duration(-rep_)`.
-`process_cpu_clock` provides a thin wrapper around the operating system's process timer API. For POSIX-like systems, that's the times() function, while for Windows, it's the GetProcessTimes() function.
+[endsect]
+[section:duration_operator_pp Member function `operator++()`]
-The process relative real, user and system current time can be obtained at once by calling `process_clocks::now()`.
+ duration& operator++();
+[*Effects:] `++rep_`.
- class BOOST_CHRONO_DECL process_cpu_clock
- {
- public:
- struct times ;
+[*Returns:] `*this`.
- typedef duration<times, nano> duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<process_cpu_clock> time_point;
- static const bool is_monotonic = true;
+[endsect]
+[section:duration_operator_pp2 Member function `operator++(int)`]
- static time_point now( system::error_code & ec = system::throws );
- };
+ duration operator++(int);
- template <>
- struct duration_values<process_cpu_clock::times>;
+[*Returns:] `duration(rep_++)v.
+[endsect]
+[section:duration_operator_mm Member function `operator++()`]
-[section Class `times`]
+ duration& operator--();
-This class is the representation of the process_cpu_clock::duration class. As such it needs to implements the arithmetic operators.
+[*Effects:] `--rep_`.
- struct times : arithmetic<times>, less_than_comparable<times>
- {
- process_real_cpu_clock::rep real; // real (i.e wall clock) time
- process_user_cpu_clock::rep user; // user cpu time
- process_system_cpu_clock::rep system; // system cpu time
+[*Returns:] `*this`.
- times();
- times(
- process_real_cpu_clock::rep r,
- process_user_cpu_clock::rep u,
- process_system_cpu_clock::rep s);
+[endsect]
+[section:duration_operator_mm2 Member function `operator++(int)`]
- bool operator==(times const& rhs);
+ duration operator--(int);
- times operator+=(times const& rhs);
- times operator-=(times const& rhs);
- times operator*=(times const& rhs);
- times operator/=(times const& rhs);
- bool operator<(times const & rhs) const;
- };
+[*Returns:] `duration(rep_--)`.
[endsect]
+[section:duration_operator_pa Member function `operator+=(const duration&)`]
-[section `duration_values` specialization for `times`]
+ duration& operator+=(const duration& d);
- template <>
- struct duration_values<process_cpu_clock::times>
- {
- static process_cpu_clock::times zero();
- static process_cpu_clock::times max();
- static process_cpu_clock::times min();
- };
+[*Effects:] `rep_ += d.count()`.
-The `times` specific functions `zero()`, `max()` and `min()` uses the relative functions on the representation of each component.
+[*Returns:] `*this`.
[endsect]
+[section:duration_operator_ma Member function `operator-=(const duration&)`]
-[endsect]
+ duration& operator-=(const duration& d);
-[endsect]
+[*Effects:] `rep_ -= d.count()`.
-[/
-[section:suspendible_clock_req `SuspendibleClock` requirements]
+[*Returns:] `*this`.
-A `SuspendibleClock` is a Clock that in addition support for `suspend`/`resume` operations.
+[endsect]
+[section:duration_operator_moda Member function `operator%=(const duration&)`]
-A `SuspendibleClock` must meet the requirements in the following Table.
+ duration& operator%=(const duration& d);
-In this table `C` denote `clock` types.
+[*Effects:] `rep_ %= d.count()`.
-[table SuspendibleClock Requirements
- [[expression] [return type] [operational semantics]]
- [[`C::suspend()`] [`void`] [Suspends the time counting of the clock C.]]
- [[`C::resume()`] [`void`] [Resumes the time counting of the clock C.]]
- [[`C::suspended()`] [`duration`] [Returns the delay(duration during which the clock has been suspended.]]
-]
+[*Returns:] `*this`.
-[section:SuspendibleClock_suspend Static Member Function `suspend()`]
+[endsect]
+[section:duration_operator_proda Member function `operator*=(const rep&)`]
- void suspend( system::error_code & ec = system::throws );
+ duration& operator*=(const rep& rhs);
-[*Effect:] Suspends the SuspendibleClock.
+[*Effects:] `rep_ *= rhs`.
-[*Throw:] Any exception the `Clock::now(ec)` function can throw. Otherwise `ec` is set with the correspoding error code set by `Clock::now(ec)`.
+[*Returns:] `*this`.
[endsect]
-[section:SuspendibleClock_resume Static Member Function `resume()`]
+[section:duration_operator_da Member function `operator/=(const rep&)`]
- void resume( system::error_code & ec = system::throws );
+ duration& operator/=(const rep& rhs);
-[*Effect:] Resumes the `SuspendibleClock`.
+[*Effects:] `rep_ /= rhs`.
-[*Throw:] Any exception the `Clock::now(ec)` can throw. Otherwise `ec` is set with the correspoding error code set by `Clock::now(ec)`.
+[*Returns:] `*this`.
[endsect]
+[section:duration_operator_moda_2 Member function `operator%=(const rep&)`]
-[section:SuspendibleClock_suspended Static Member Function `suspended()`]
-
- duration suspended( system::error_code & ec = system::throws );
-
-[*Returns:] the cumalative elapsed duration during which the `SuspendibleClock` has been suspendeed.
+ duration& operator%=(const rep& rhs);
-[*Throw:] Any exception the Clock::now function can throw if `ec == system::throws`. Otherwise `ec` is set with the correspoding error code set by `Clock::now(ec)`.
+[*Effects:] `rep_ %= rhs`.
-[endsect]
+[*Returns:] `*this`.
[endsect]
-[/==================================================================]
-[section:scoped_suspend_hpp Header `<boost/chrono/scoped_suspend.hpp>`]
-[/==================================================================]
- namespace boost { namespace chrono {
- template <class Clock> struct is_suspendible;
- template <class Clock> class scoped_suspend;
- }}
+[section:duration_zero Static Member function `zero()`]
-[section Meta Function Class `is_suspendible`]
+ static duration zero();
- template <class Clock>
- struct is_suspendible : mpl:: false_ {};
+[*Returns:] `duration(duration_values<rep>::zero())`.
[endsect]
+[section:duration_min Static Member function `min()`]
-[section Template Class `scoped_suspend`]
+ static duration min();
- template <class Clock>
- class scoped_suspend {
- public:
- scoped_suspend(system::error_code & ec = system::throws) {}
- ~scoped_suspend() {}
- private:
- scoped_suspend(); // = delete;
- scoped_suspend(const scoped_suspend&); // = delete;
- scoped_suspend& operator=(const scoped_suspend&); // = delete;
- };
+[*Returns:] `duration(duration_values<rep>::min()).`
[endsect]
+[section:duration_max Static Member function `max()`]
+
+ static constexpr duration max();
+
+[*Returns:] `duration(duration_values<rep>::max())`.
[endsect]
+[endsect]
-[/==================================================================]
-[section:suspendible_clock_hpp Header `<boost/chrono/suspendible_clock.hpp>`]
-[/==================================================================]
- namespace boost { namespace chrono {
+[section duration non-member arithmetic]
- template <class Clock>
- class suspendible_clock;
+[section:duration_operator_p_1 Non-Member function `operator+(duration,duration)`]
- template <class Clock>
- struct is_suspendible<suspendible_clock<Clock> > : mpl:: true_ {};
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
+ operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- template <class Clock>
- class scoped_suspend<suspendible_clock<Clock> >;
+[*Returns:] `CD(lhs) += rhs` where `CD` is the type of the return value.
- }}
+[endsect]
+[section:duration_operator_m_1 Non-Member function `operator-(duration,duration)`]
-[section Template Class `suspendible_clock<>`]
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
+ operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
-Given a `Clock`, `suspendible_clock<Clock>` is a model of SuspendibleClock.
+[*Returns:] `CD(lhs) -= rhs` where `CD` is the type of the return value.
- template < class Clock >
- class suspendible_clock {
- public:
- typedef typename Clock::duration duration;
- typedef typename Clock::rep rep;
- typedef typename Clock::period period;
- typedef chrono::time_point<suspendible_clock<Clock> > time_point;
- static const bool is_monotonic = true;
+ template <class Rep1, class Period, class Rep2>
+ duration<typename common_type<Rep1, Rep2>::type, Period>
+ operator*(const duration<Rep1, Period>& d, const Rep2& s);
- static time_point now( system::error_code & ec = system::throws );
+[*Requires:] Let `CR` represent the `common_type` of `Rep1` and `Rep2`. This function will not participate in overload resolution unless both `Rep1` and `Rep2` are implicitly convertible to `CR`.
- static void suspend( system::error_code & ec = system::throws );
- static void resume( system::error_code & ec = system::throws );
- static duration suspended(system::error_code & ec = system::throws);
- };
+[*Returns:] `duration<CR, Period>(d) *= s`.
-[section `scoped_suspend` specialization for `suspendible_clock<>`]
+[endsect]
+[section:duration_operator_prod_1 Non-Member function `operator*(Rep1,duration)`]
- template <class Clock>
- class scoped_suspend<suspendible_clock<Clock> > {
- public:
- scoped_suspend(system::error_code & ec = system::throws);
- ~scoped_suspend();
- };
+ template <class Rep1, class Period, class Rep2>
+ duration<typename common_type<Rep1, Rep2>::type, Period>
+ operator*(const Rep1& s, const duration<Rep2, Period>& d);
-[endsect]
+[*Requires:] Let `CR` represent the `common_type` of `Rep1` and `Rep2`. This function will not participate in overload resolution unless both `Rep1` and `Rep2` are implicitly convertible to `CR`.
-[endsect]
+[*Returns:] `d * s`.
[endsect]
-]
-[endsect]
-
+[section:duration_operator_d_1 Non-Member function `operator/(duration,Rep2)`]
-[/==================================================]
-[section Stopwatches]
-[/==================================================]
-[/=============================================]
-[section:stopwatches_hpp Header `<boost/stopwatches.hpp>`]
-[/=============================================]
+ template <class Rep1, class Period, class Rep2>
+ duration<typename common_type<Rep1, Rep2>::type, Period>
+ operator/(const duration<Rep1, Period>& d, const Rep2& s);
-This file include all the stopwatches related files
+[*Requires:] Let `CR` represent the `common_type` of `Rep1` and `Rep2`. This function will not participate in overload resolution unless both `Rep1` and `Rep2` are implicitly convertible to `CR`, and `Rep2` is not an instantiation of `duration`.
- #include <boost/chrono/stopwatches.hpp>
+[*Returns:] `duration<CR, Period>(d) /= s`.
[endsect]
+[section:duration_operator_d_2 Non-Member function `operator/(duration,duration)`]
-[/=============================================]
-[section:chrono_stopwatches_hpp Header `<boost/chrono/stopwatches.hpp>`]
-[/=============================================]
-
-This file include all the stopwatches related files
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ typename common_type<Rep1, Rep2>::type
+ operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- #include <boost/chrono/scoped_stopclock.hpp>
- #include <boost/chrono/process_cpu_clocks.hpp>
- #include <boost/chrono/stopclock.hpp>
- #include <boost/chrono/stopclock_accumulator.hpp>
- #include <boost/chrono/stopwatch.hpp>
- #include <boost/chrono/stopwatch_accumulator.hpp>
- #include <boost/chrono/stopwatch_accumulator_formatter.hpp>
- #include <boost/chrono/stopwatch_formatter.hpp>
- #include <boost/chrono/stopwatch_reporter.hpp>
- #include <boost/chrono/stopwatch_scoped.hpp>
- #include <boost/chrono/time_formatter.hpp>
- #include <boost/chrono/t24_hours.hpp>
- #include <boost/chrono/t24_hours_formatter.hpp>
+[*Returns:] Let `CD` represent the `common_type` of the two `duration` arguments. Returns `CD(lhs).count() / CD(rhs).count()`.
[endsect]
-[section `Stopwatch` Requirements]
-
-A Stopwatch measure the amount of time elapsed from a particular time when activated to when it is deactivated, or the accumulation of them.
-
-A Stopwatch must meet the requirements in the following Table.
+[section:duration_operator_d_3 Non-Member function `operator/(Rep1,duration)`]
-In this table `S`, `S1` and `S2` denote stopwatches types. `s` is an instance of `S`.
+ template <class Rep1, class Rep2, class Period>
+ double operator/(const Rep1& s, const duration<Rep2, Period>& d);
-[table Stopwatch Requirements
- [[expression] [return type] [operational semantics]]
- [[`S::clock`] [A model of the Clock concept.] [The clock associated to this Stopwatch.]]
- [[`S::duration`] [`S::clock::duration`] [The `duration` type of the `clock`.]]
- [[`S::time_point`] [`S::clock::time_point`] [The `time_point` type of the `clock`.]]
- [[`s.start()`] [`S::time_point`] [starts a Stopwatch.]]
- [[`s.restart()`] [`std::pair<S::duration,S::time_point>`] [restarts a Stopwatch.]]
- [[`s.stop()`] [`S::duration`] [stops a Stopwatch.]]
- [[`s.resume()`] [`S::time_point`] [starts a Stopwatch.]]
- [[`s.suspend()`] [`S::duration`] [stops a Stopwatch.]]
- [[`s.elapsed()`] [`S::duration`] [the elapsed time while the Stopwatch was running.]]
-]
+[*Remarks:] Let `CR` represent the `common_type` of `Rep1` and `Rep2`. This function will not participate in overload resolution unless both `Rep1` and `Rep2` are implicitly convertible to `CR`, and `Rep1` is not an instantiation of `duration`.
+[*Returns:] `CR(s)/duration<CR, Period>(d)`.
-[section:stopwatch_start Member Function `start()`]
+[endsect]
- time_point start( system::error_code & ec = system::throws );
-[*Effect:] Starts running the stopwatch.
+[section:duration_operator_mod_1 Non-Member function `operator%(duration,Rep2)`]
-[*Returns:] the starting time point.
+ template <class Rep1, class Period, class Rep2>
+ duration<typename common_type<Rep1, Rep2>::type, Period>
+ operator%(const duration<Rep1, Period>& d, const Rep2& s);
-[*Throw:] Any exception the Clock::now function can throw.
+[*Remarks] This function will not participate in overload resolution unless Rep2 shall be implicitly convertible to CR(Rep1, Rep2) and Rep2 shall not be an instantiation of duration.
+[*Returns:] duration<CR(Rep1,Rep2), Period>(d) %= s.
[endsect]
-[section:stopwatch_stop Member Function `stop()`]
- duration stop( system::error_code & ec = system::throws );
+[section:duration_operator_mod_2 Non-Member function `operator%(duration,duration)`]
-[*Effect:] Stops running the stopwatch.
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
+ operator%(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
-[*Returns:] The cummulated elapsed time.
+[*Remarks] This function will not participate in overload resolution unless
-[*Throw:] Any exception the Clock::now function can throw.
+[*Returns:] CD(lhs) %= CD(rhs)
[endsect]
-[section:stopwatch_suspend Member Function `suspend()`]
+[endsect]
- duration suspend( system::error_code & ec = system::throws );
+[section duration comparaisons]
-[*Effect:] Suspends the stopwatch.
+[section:duration_operator_eq_1 Non-Member function `operator==(duration,duration)`]
-[*Throw:] Any exception the Clock::now function can throw.
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+
+[*Returns:] Let `CD` represent the `common_type` of the two `duration` arguments. Returns `CD(lhs).count() == CD(rhs).count()`
[endsect]
-[section:stopwatch_resume Member Function `resume()`]
+[section:duration_operator_neq_1 Non-Member function `operator!=(duration,duration)`]
- time_point resume( system::error_code & ec = system::throws );
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
-[*Effect:] Resumes the stopwatch.
+[*Returns:] `!(lhs == rhs)`.
-[*Returns:] the starting time point.
+[endsect]
+[section:duration_operator_lt_1 Non-Member function `operator<(duration,duration)`]
-[*Throw:] Any exception the Clock::now function can throw.
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+
+[*Returns:] Let `CD` represent the `common_type` of the two `duration` arguments. Returns `CD(lhs).count() < CD(rhs).count()`
[endsect]
+[section:duration_operator_leq_1 Non-Member function `operator<=(duration,duration)`]
-[section:stopwatch_restart Member Function `restart()`]
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
- time_point restart( system::error_code & ec = system::throws );
+[*Returns:] `!(rhs < lhs)`.
-[*Effect:] Stop/Start the stopwatch.
+[endsect]
+[section:duration_operator_gt_1 Non-Member function `operator>(duration,duration)`]
-[*Returns:] the starting time point.
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
-[*Throw:] Any exception the Clock::now function can throw.
+[*Returns:] `rhs < lhs`.
[endsect]
+[section:duration_operator_gteq_1 Non-Member function `operator>=(duration,duration)`]
+
+ template <class Rep1, class Period1, class Rep2, class Period2>
+ bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
+
+[*Returns:] `!(lhs < rhs)`.
[endsect]
-[/==================================================]
-[section:stopwatch_hpp Header `<boost/chrono/stopwatch.hpp>`]
-[/==================================================]
+[endsect]
+[section:duration_cast Non-Member function `duration_cast(duration)`]
+ template <class ToDuration, class Rep, class Period>
+ ToDuration duration_cast(const duration<Rep, Period>& d);
- namespace boost { namespace chrono {
- struct dont_start_t;
- static const dont_start_t dont_start;
+[*Requires:] This function will not participate in overload resolution unless `ToDuration` is an instantiation of `duration`.
- template <class Clock=high_resolution_clock> class stopwatch;
+[*Returns:] Forms `CF` which is a `ratio` resulting from `ratio_divide<Period, typename ToDuration::period>::type`. Let `CR` be the `common_type` of `ToDuration::rep`, `Rep`, and `intmax_t`.
- template <class Clock>
- struct stopwatch_reporter_default_formatter<stopwatch<Clock> > {
- typedef stopwatch_formatter type;
- };
+* If `CF::num == 1` and `CF::den == 1`, then returns `ToDuration(static_cast<typename ToDuration::rep>(d.count())) `
+* else if `CF::num != 1` and `CF::den == 1`, then returns
+ `ToDuration(static_cast<typename ToDuration::rep>(static_cast<CR>(d.count()) *
+ static_cast<CR>(CF::num)))`
+* else if `CF::num == 1` and `CF::den != 1`, then returns
+ `ToDuration(static_cast<typename ToDuration::rep>(static_cast<CR>(d.count()) /
+ static_cast<CR>(CF::den)))`
+* else returns
+ `ToDuration(static_cast<typename ToDuration::rep>(static_cast<CR>(d.count()) *
+ static_cast<CR>(CF::num) /
+ static_cast<CR>(CF::den)))`
- template <class Clock>
- struct wstopwatch_reporter_default_formatter<stopwatch<Clock> > {
- typedef wstopwatch_formatter type;
- };
+[*Remarks:] This function does not rely on any implicit conversions. All conversions must be accomplished through `static_cast`. The implementation avoids all multiplications or divisions when it is known at compile time that it can be avoided because one or more arguments are `1`. All intermediate computations are carried out in the widest possible representation and only converted to the destination representation at the final step.
- typedef <see above> system_stopwatch;
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef <see above> monotonic_stopwatch;
- #endif
- typedef <see above> high_resolution_stopwatch;
- typedef <see above> process_real_cpu_stopwatch;
- typedef <see above> process_user_cpu_stopwatch;
- typedef <see above> process_system_cpu_stopwatch;
- }}
-[section Template Class `stopwatch<>`]
+[endsect]
-`stopwatch<>` is a model of a `Stopwatch`.
-Knowing how long a part of a program takes to execute is useful in both test and production environments.
-A `stopwatch` object measures elapsed time. It is recommended to use it with clocks that measure wall clock rather than CPU time since the intended use is performance measurement on systems where total elapsed time is more important than just process or CPU time.
-The maximum measurable elapsed time depends on the Clock parameter. The accuracy of timings depends on the
-accuracy of timing information provided the Clock, and this coudl varies a great deal from one clock to another.
+[section Class template `time_point`]
- template <class Clock> class stopwatch {
- public:
- typedef Clock clock;
- typedef typename Clock::duration duration;
- typedef typename Clock::time_point time_point;
+A `time_point` represents a point in time with respect to a specific clock.
- explicit stopwatch( system::error_code & ec = system::throws );
- explicit stopwatch( const dont_start_t& t );
+ template <class Clock, class Duration>
+ class time_point {
+ public:
+ typedef Clock clock;
+ typedef Duration duration;
+ typedef typename duration::rep rep;
+ typedef typename duration::period period;
+ private:
+ duration d_; // exposition only
+ public:
+ time_point();
+ explicit time_point(const duration& d);
- ~timer();
+ // conversions
+ template <class Duration2>
+ time_point(const time_point<clock, Duration2>& t,
+ typename boost::enable_if
+ <
+ boost::is_convertible<Duration2, duration>
+ >::type* = 0);
- time_point start( system::error_code & ec = system::throws );
- duration stop( system::error_code & ec = system::throws );
- std::pair<duration,time_point> restart( system::error_code & ec = system::throws );
+ // observer
- duration suspend( system::error_code & ec = system::throws );
- time_point resume( system::error_code & ec = system::throws );
+ duration time_since_epoch() const;
- duration elapsed( system::error_code & ec = system::throws );
+ // arithmetic
- typedef stopwatch_runner<stopwatch<Clock> > scoped_run;
- typedef stopwatch_suspender<stopwatch<Clock> > scoped_suspend;
- typedef stopwatch_resumer<stopwatch<Clock> > scoped_resume;
- typedef stopwatch_reporter<stopwatch<Clock> > reporter;
+ time_point& operator+=(const duration& d);
+ time_point& operator-=(const duration& d);
- };
+ // special values
-[section:stopwatch_elapsed Member Function `elapsed()`]
+ static BOOST_CHRONO_CONSTEXPR time_point min();
+ static BOOST_CHRONO_CONSTEXPR time_point max();
+ };
- duration elapsed(system::error_code & ec = system::throws) const;
+Clock must meet the [@boost_chrono/reference/cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_ Clock Requirements].
-[*Returns:] the elapsed time from the last call to start.
+Duration must be an instantiation of `duration`, compile diagnostic otherwise.
-[*Throw:] Nothing.
+[section:time_point_c_1 Constructor `time_point()`]
-[*Note:] the system::error_code & parameter is here to conform to the Stopwatch concept.
+ time_point();
-[endsect]
+[*Effects:] Constructs an object of `time_point`, initializing `d_` with `duration::zero()`. This `time_point` represents the epoch.
[endsect]
+[section:time_point_c_2 Constructor `time_point(const duration&)`]
-[section `stopwatch` useful typedefs]
+ time_point(const duration& d);
- typedef boost::chrono::stopwatch< boost::chrono::system_clock > system_stopwatch;
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef boost::chrono::stopwatch< boost::chrono::monotonic_clock > monotonic_stopwatch;
- #endif
- typedef boost::chrono::stopwatch< boost::chrono::high_resolution_clock > high_resolution_stopwatch;
-
- typedef boost::chrono::stopwatch< boost::chrono::process_real_cpu_clock > process_real_cpu_stopwatch;
- typedef boost::chrono::stopwatch< boost::chrono::process_user_cpu_clock > process_user_cpu_stopwatch;
- typedef boost::chrono::stopwatch< boost::chrono::process_system_cpu_clock > process_system_cpu_stopwatch;
+[*Effects:] Constructs an object of `time_point`, initializing `d_` with `d`. This `time_point` represents the epoch `+ d`.
[endsect]
-[endsect]
-
-[/==================================================]
-[section:stopwatch_accumulator_hpp Header `<boost/chrono/stopwatch_accumulator.hpp>`]
-[/==================================================]
-
- namespace boost { namespace chrono {
- template <class Clock, class Accumulator> class stopwatch_accumulator;
+[section:time_point_c_3 Constructor `time_point(const duration&)`]
- template <class Clock, class Accumulator>
- struct stopwatch_reporter_default_formatter<stopwatch_accumulator<Clock, Accumulator> > {
- typedef stopwatch_accumulator_formatter type;
- };
+ template <class Duration2> time_point(const time_point<clock, Duration2>& t);
- template <class Clock, class Accumulator>
- struct wstopwatch_reporter_default_formatter<stopwatch_accumulator<Clock, Accumulator> > {
- typedef wstopwatch_accumulator_formatter type;
- };
+[*Requires:] This function will not participate in overload resolution unless `Duration2` is implicitly convertible to `duration`.
- typedef <see below> system_stopwatch_accumulator;
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef <see below> monotonic_stopwatch_accumulator;
- #endif
- typedef <see below> high_resolution_stopwatch_accumulator;
+[*Effects:] Constructs an object of `time_point`, initializing `d_` with `t.time_since_epoch()`.
- typedef <see below> process_real_cpu_stopwatch_accumulator;
- typedef <see below> process_user_cpu_stopwatch_accumulator;
- typedef <see below> process_system_cpu_stopwatch_accumulator;
+[endsect]
- }}
+[section:time_since_epoch Member function `time_since_epoch() const`]
+ duration time_since_epoch() const;
-[section Template Class `stopwatch_accumulator<>`]
+[*Returns:] `d_`.
-A `stopwatch_accumulator<>` is a model of a Stopwatch that allows to accumulate the time in several times instead of at once as it is the case of the class `stopwatch<>`.
+[endsect]
+[section:time_point_operator_pe Member function `operator+=`]
- template <class Clock> class stopwatch_accumulator {
- public:
- typedef Clock clock;
- typedef typename Clock::duration duration;
- typedef typename Clock::time_point time_point;
- typedef Accumulator accumulator;
+ time_point& operator+=(const duration& d);
- stopwatch_accumulator();
+[*Effects:] `d_ += d`.
- time_point start( system::error_code & ec = system::throws );
- duration stop( system::error_code & ec = system::throws );
- std::pair<duration,time_point> restart( system::error_code & ec = system::throws );
+[*Returns:] `*this`.
- duration suspend( system::error_code & ec = system::throws );
- time_point resume( system::error_code & ec = system::throws );
+[endsect]
+[section:time_point_operator_me Member function `operator-=`]
- duration elapsed(system::error_code & ec = system::throws);
+ time_point& operator-=(const duration& d);
- accumulator& accumulated( );
- void reset();
+[*Effects:] `d_ -= d`
- typedef stopwatch_runner<stopwatch_accumulator<Clock> > scoped_run;
- typedef stopwatch_suspender<stopwatch_accumulator<Clock> > scoped_suspend;
- typedef stopwatch_resumer<stopwatch_accumulator<Clock> > scoped_resume;
- typedef stopwatch_reporter<stopwatch_accumulator<Clock> > reporter;
- };
+[*Returns:] `*this`.
-[section:stopwatch_accumulator_c Constructor `stopwatch_accumulator()`]
+[endsect]
+[section:time_point_min Static Member function `min`]
- stopwatch_accumulator();
+ static BOOST_CHRONO_CONSTEXPR time_point min();
-[*Effect:] Initialize the elapsed duration and the times counter to 0.
+[*Returns:] `time_point(duration::min())`.
[endsect]
-[section:stopwatch_accumulator_start Member Function `start()`]
+[section:time_point_max Static Member function `max`]
- time_point start( system::error_code & ec = system::throws );
+ static BOOST_CHRONO_CONSTEXPR time_point max();
-[*Effect:] Starts running the stopwatch.
+[*Returns:] `time_point(duration::max())`.
-[*Returns:] the starting time point.
+[endsect]
+[endsect]
-[*Throw:] Any exception the Clock::now function can throw.
-[endsect]
-[section:stopwatch_accumulator_stop Member Function `stop()`]
+[section time_point non-member arithmetic]
- duration stop( system::error_code & ec = system::throws );
-[*Effect:] Stops running the stopwatch. Accumulates the elapsed time since the last start-like operation + the partial accumulated by resume/suspend operation.
+[section:time_point_operator_p_1 Non-Member function `operator+(time_point,duration)`]
-[*Returns:] The cummulated elapsed time.
+ template <class Clock, class Duration1, class Rep2, class Period2>
+ time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
+ operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
-[*Throw:] Any exception the Clock::now function can throw.
+[*Returns:] `CT(lhs) += rhs` where `CT` is the type of the return value.
[endsect]
-[section:stopwatch_accumulator_suspend Member Function `suspend()`]
-
- duration suspend( system::error_code & ec = system::throws );
+[section:time_point_operator_p_2 Non-Member function `operator+(duration,time_point)`]
-[*Effect:] Suspends the stopwatch. Accumulates the elapsed time since the last start-like operation on a partial duration.
+ template <class Rep1, class Period1, class Clock, class Duration2>
+ time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
+ operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
-[*Throw:] Any exception the Clock::now function can throw.
+[*Returns:] `rhs + lhs`.
[endsect]
-[section:stopwatch_accumulator_resume Member Function `resume()`]
+[section:time_point_operator_m_1 Non-Member function `operator-(time_point,duration)`]
- time_point resume( system::error_code & ec = system::throws );
+ template <class Clock, class Duration1, class Rep2, class Period2>
+ time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
+ operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
-[*Effect:] Resumes the stopwatch.
+[*Returns:] `lhs + (-rhs)`.
-[*Returns:] the starting time point.
+[endsect]
+[section:time_point_operator_m_2 Non-Member function `operator-(duration,time_point)`]
-[*Throw:] Any exception the Clock::now function can throw.
+ template <class Clock, class Duration1, class Duration2>
+ typename common_type<Duration1, Duration2>::type
+ operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
+
+[*Returns:] `lhs.time_since_epoch() - rhs.time_since_epoch()`.
[endsect]
+[endsect]
-[section:stopwatch_accumulator_restart Member Function `restart()`]
+[section time_point comparisons]
+[section:time_point_operator_eq Non-Member function `operator==(time_point,time_point)`]
- time_point restart( system::error_code & ec = system::throws );
+ template <class Clock, class Duration1, class Duration2>
+ bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
-[*Effect:] Stop/Start the stopwatch.
+[*Returns:] `lhs.time_since_epoch() == rhs.time_since_epoch()`.
-[*Returns:] the starting time point.
+[endsect]
+[section:time_point_operator_neq Non-Member function `operator!=(time_point,time_point)`]
-[*Throw:] Any exception the Clock::now function can throw.
+template <class Clock, class Duration1, class Duration2>
+ bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
-[endsect]
-[section:stopwatch_accumulator_reset Member Function `reset()`]
+[*Returns:] `!(lhs == rhs)`.
- void reset( );
+[endsect]
+[section:time_point_operator_lt Non-Member function `operator<(time_point,time_point)`]
-[*Effect:] Stop the stopwatch and reset the accumulator.
+ template <class Clock, class Duration1, class Duration2>
+ bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
-[*Throw:] Nothing.
+[*Returns:] lhs.time_since_epoch() < rhs.time_since_epoch().
[endsect]
-[section:stopwatch_accumulator_elapsed Member Function `elapsed()`]
-
- duration elapsed(system::error_code & ec = system::throws) const;
+[section:time_point_operator_leq Non-Member function `operator<=(time_point,time_point)`]
-[*Returns:] the cumulated elapsed time.
+ template <class Clock, class Duration1, class Duration2>
+ bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
-[*Throw:] Nothing.
+[*Returns:] `!(rhs < lhs)`.
[endsect]
+[section:time_point_operator_gt Non-Member function `operator>(time_point,time_point)`]
-[section:stopwatch_accumulator_accumulated Member Function `accumulated()`]
+template <class Clock, class Duration1, class Duration2>
+ bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
- accumulator& accumulated();
+[*Returns:] `rhs < lhs`.
-[*Returns:] the assocaited accumulator.
+[endsect]
+[section:time_point_operator_geq Non-Member function `operator>=(time_point,time_point)`]
-[*Throw:] Nothing.
+ template <class Clock, class Duration1, class Duration2>
+ bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
-[endsect]
+[*Returns:] `!(lhs < rhs)`.
[endsect]
+[section:time_point_cast Non-Member function `time_point_cast(time_point)`]
-[section `stopwatch_accumulator` useful typedefs]
+ template <class ToDuration, class Clock, class Duration>
+ time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
- typedef boost::chrono::stopwatch_accumulator< boost::chrono::system_clock > system_stopwatch_accumulator;
-#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef boost::chrono::stopwatch_accumulator< boost::chrono::monotonic_clock > monotonic_stopwatch_accumulator;
-#endif
- typedef boost::chrono::stopwatch_accumulator< boost::chrono::high_resolution_clock > high_resolution_stopwatch_accumulator;
+[*Requires:] This function will not participate in overload resolution unless `ToDuration` is an instantiation of `duration`.
- typedef boost::chrono::stopwatch_accumulator< boost::chrono::process_real_cpu_clock > process_real_cpu_stopwatch_accumulator;
- typedef boost::chrono::stopwatch_accumulator< boost::chrono::process_user_cpu_clock > process_user_cpu_stopwatch_accumulator;
- typedef boost::chrono::stopwatch_accumulator< boost::chrono::process_system_cpu_clock > process_system_cpu_stopwatch_accumulator;
+[*Returns:] `time_point<Clock, ToDuration>(duration_cast<ToDuration>(t.time_since_epoch()))`.
[endsect]
[endsect]
-[/==================================================]
-[section:stopwatch_scoped_hpp Header `<boost/chrono/stopwatch_scoped.hpp>`]
-[/==================================================]
- namespace boost { namespace chrono {
- template <class Clock> class stopwatch_runner;
- template <class Clock> class stopwatch_suspender;
- template <class Clock> class stopwatch_resumer;
- }}
+[section Class `system_clock`]
-Boost.Chrono provides some helper classes ensuring pairwised operations (start/stop, suspend/resume, resule/suspend).
+The `system_clock` class provides a means of obtaining the current wall-clock time from the system-wide real-time clock. The current time can be obtained by calling `system_clock::now()`. Instances of `system_clock::time_point` can be converted to and from time_t with the `system_clock::to_time_t()` and `system_clock::to_time_point()` functions. If system clock is not monotonic, a subsequent call to `system_clock::now()` may return an earlier time than a previous call (e.g. if the operating system clock is manually adjusted, or synchronized with an external clock).
-[section Template Class `stopwatch_runner<>`]
+ class system_clock {
+ public:
+ typedef BOOST_SYSTEM_CLOCK_DURATION duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<system_clock> time_point;
+ static const bool is_monotonic = false;
-This helper class ensures that the start/stop are pairwised. Start the associated accumulator at construction time, and stop it at destruction time.
+ static time_point now(); // throws on error
+ static time_point now(system::error_code & ec); // never throws
- template <class Stopwatch> class stopwatch_runner {
- public:
- typedef Stopwatch stopwatch;
- stopwatch_runner(stopwatch & a, system::error_code & ec = system::throws);
- ~stopwatch_runner();
- stopwatch_runner() = delete;
- stopwatch_runner(const stopwatch_runner&) = delete;
- stopwatch_runner& operator=(const stopwatch_runner&) = delete;
+ static std::time_t to_time_t(const time_point& t);
+ static time_point from_time_t(std::time_t t);
};
-Usage
+`system_clock` satisfy the [@boost_chrono/reference/cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_ Clock Requirements]. In addition:
- void f1()
- {
- static stopwatch_accumulator<> t;
- stopwatch_runner<stopwatch_accumulator<> > _(t);
- // ...
- }
+* `system_clock::duration::min() < system_clock::duration::zero()` is `true`.
-[endsect]
-[section Template Class `stopwatch_suspender<>`]
-This helper class ensures that the suspend/resume are pairwised. Suspend the associated accumulator at construction time, and resume it at destruction time.
+[section:to_time_t Static member function `to_time_t(time_point)`]
- template <class Stopwatch> class stopwatch_suspender {
- public:
- typedef Stopwatch stopwatch;
- stopwatch_suspender(stopwatch & a, system::error_code & ec = system::throws);
- ~stopwatch_suspender();
- stopwatch_suspender() = delete;
- stopwatch_suspender(const stopwatch_suspender&) = delete;
- stopwatch_suspender& operator=(const stopwatch_suspender&) = delete;
- }
+time_t to_time_t(const time_point& t);
-Usage
+[*Returns:] A `time_t` such that the `time_t` and `t` represent the same point in time, truncated to the courser of the precisions among `time_t` and `t`.
- void f1()
- {
- static stopwatch_accumulator<> t;
- stopwatch_runner<stopwatch_accumulator<> > _(t);
- // ...
+[endsect]
+[section:from_time_t Static member function `from_time_t(time_t)`]
- // call to some function we don't want to measure
- {
- stopwatch_suspender<stopwatch_accumulator<> > _(t);
- external_function();
- }
- }
+ time_point from_time_t(time_t t);
+
+[*Returns:] A `time_point` such that the `time_point` and `t` represent the same point in time, truncated to the courser of the precisions among `time_point` and `t`.
[endsect]
+[endsect]
-[section Template Class `stopwatch_resumer<>`]
+[section Macro `BOOST_CHRONO_HAS_CLOCK_MONOTONIC`]
-This helper class ensures that the resume/suspend are pairwised. Resume the associated accumulator at construction time, and suspecd it at destruction time.
+Defined if the platform support monotonic clocks.
- template <class Stopwatch> class stopwatch_resumer {
- public:
- typedef Stopwatch stopwatch;
- stopwatch_resumer(stopwatch & a, system::error_code & ec = system::throws);
- ~stopwatch_resumer();
- stopwatch_resumer() = delete;
- stopwatch_resumer(const stopwatch_resumer&) = delete;
- stopwatch_resumer& operator=(const stopwatch_resumer&) = delete;
- }
+[endsect]
-Usage
+[section Class `monotonic_clock`]
- void f1()
- {
- static stopwatch_accumulator<> t;
- stopwatch_runner<stopwatch_accumulator<> > _(t);
- // ...
+`monotonic_clock` satisfy the [@boost_chrono/reference/cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_ Clock Requirements].
- // call to some function we don't want to measure
- {
- stopwatch_suspender<stopwatch_accumulator<> > _(t);
+`monotonic_clock` class provides access to the system-wide monotonic clock. The current time can be obtained by calling `monotonic_clock::now()`. There is no fixed relationship between values returned by `monotonic_clock::now()` and wall-clock time.
- {
- stopwatch_resumer<stopwatch_accumulator<> > _(t);
+ #ifdef BOOST_HAS_CLOCK_MONOTONIC
+ class BOOST_CHRONO_DECL monotonic_clock {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<monotonic_clock> time_point;
+ static const bool is_monotonic = true;
- }
- }
- }
+ static time_point now(); // throws on error
+ static time_point now(system::error_code & ec); // never throws
+ };
+ #endif
-[endsect]
-[endsect]
[endsect]
-[section Stopwatch Reporters]
-[section `Formatter` Requirements]
-A Formatter outputs on a given ostream a formatted string combining informations from a Stopwatch and the format and the double precission.
-
-A Stopwatch must meet the requirements in the following Table.
+[section Class `high_resolution_clock`]
-In this table `F` denote Fromaters types, `S` is a Stopwatch and `s` is an instance of `S`, `f` is `const char *` , `p` is and int, and `os` is a `std::ostream`, ec is a system::error_code
+`high_resolution_clock` satisfy the [@boost_chrono/reference/cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_ Clock Requirements].
-[table Stopwatch Requirements
- [[expression] [return type] [operational semantics]]
- [[`F::default_os()`] [std::otream&] [The output stream.]]
- [[`F::default_places()`] [`std::size_t`] [The precission when displaying a double.]]
- [[`F::default_format()`] [`const char*`] [The default format.]]
- [[`F::show_time(s,f,p,os,ec)`] [`S::time_point`] [outputs on `os` a formatted string combining informations from the Stopwatch `s`, the format `f` and the double precission `p`.]]
-]
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef monotonic_clock high_resolution_clock; // as permitted by [time.clock.hires]
+ #else
+ typedef system_clock high_resolution_clock; // as permitted by [time.clock.hires]
+ #endif
[endsect]
-[section `Formatter` related traits]
+[endsect]
- template <class Stopwatch>
- struct stopwatch_reporter_default_formatter {
- typedef <see below> type;
- };
+[/=============================================]
+[section:chrono_typeof_hpp Header `<boost/chrono/typeof/boost/chrono/chrono.hpp>`]
+[/=============================================]
-The nested typedef `type` defines the default formatter used by the `stopwatch_reporter` class when the `Formatter` parameter is not explicit.
+Register `duration<>` and `timepoint<>` class templates to Boost.Typeof.
[endsect]
+[endsect]
-[/==================================================]
-[section:stopwatch_reporter_hpp Header `<boost/chrono/stopwatch_reporter.hpp>`]
-[/==================================================]
+[section Other clocks]
- namespace boost { namespace chrono {
- template <class Stopwatch>
- struct basic_stopwatch_reporter_default_formatter;
- template <class Stopwatch>
- struct stopwatch_reporter_default_formatter;
- template <class Stopwatch>
- struct wstopwatch_reporter_default_formatter;
+[/==================================================================]
+[section:process_cpu_clocks_hpp Header `<boost/chrono/process_cpu_clocks.hpp>`]
+[/==================================================================]
- template <class Stopwatch, class Formatter=typename stopwatch_reporter_default_formatter<Stopwatch>::type>
- class stopwatch_reporter;
- }}
+Knowing how long a program takes to execute is useful in both test and production environments. It is also helpful if such timing information is broken down into real (wall clock) time, CPU time spent by the user, and CPU time spent by the operating system servicing user requests.
-[section Template Class `basic_stopwatch_reporter<>`]
+ namespace boost { namespace chrono {
-class `basic_stopwatch_reporter` provides a everything a Timer provides and it adds reporting capabilities that can be invoked in a single line of code. The reporting is controleed by two parameters:
+ class process_real_cpu_clock;
+ class process_user_cpu_clock;
+ class process_system_cpu_clock;
+ class process_cpu_clock;
-* format : The output format
-* places(precission): the number of decimal placess used.
+ } }
-The default places is given by Formatter::default_places().
+[section Class `process_real_cpu_clock`]
-The default format is given by Formatter::default_format().
+`process_real_cpu_clock` satisfy the [@boost_chrono/reference/cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_ Clock Requirements].
- template <class Stopwatch, class Formatter>
- class basic_stopwatch_reporter : public Stopwatch {
- public:
- typedef typename Stopwatch::clock clock;
- typedef Stopwatch stopwatch;
- typedef Formatter formatter;
+`process_real_cpu_clock` class provides access to the real process wall-clock monotonic clock, i.e. the real CPU-time clock of the calling process. The process relative current time can be obtained by calling `process_real_cpu_clock::now()`.
- explicit basic_stopwatch_reporter( system::error_code & ec = system::throws );
- explicit basic_stopwatch_reporter( std::ostream & os,
- system::error_code & ec = system::throws );
+ class process_real_cpu_clock {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<process_real_cpu_clock> time_point;
+ static const bool is_monotonic = true;
- explicit basic_stopwatch_reporter( const std::string & format,
- system::error_code & ec = system::throws );
- explicit basic_stopwatch_reporter( std::ostream & os, const std::string & format,
- system::error_code & ec = system::throws );
+ static time_point now( system::error_code & ec = system::throws );
+ };
- explicit basic_stopwatch_reporter( const std::string & format, int places,
- system::error_code & ec = system::throws );
- explicit basic_stopwatch_reporter( std::ostream & os, const std::string & format, int places,
- system::error_code & ec = system::throws );
- explicit basic_stopwatch_reporter( int places,
- system::error_code & ec = system::throws );
- explicit basic_stopwatch_reporter( std::ostream & os, int places,
- system::error_code & ec = system::throws );
+[endsect]
+[section Class `process_user_cpu_clock`]
- explicit basic_stopwatch_reporter( int places, const std::string & format,
- system::error_code & ec = system::throws );
- explicit basic_stopwatch_reporter( std::ostream & os, int places, const std::string & format,
- system::error_code & ec = system::throws );
+`process_user_cpu_clock` satisfy the [@boost_chrono/reference/cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_ Clock Requirements].
- ~basic_stopwatch_reporter();
+`process_user_cpu_clock` class provides access to the user CPU-time monotonic clock of the calling process. The process relative user current time can be obtained by calling `process_user_cpu_clock::now()`.
- void report( system::error_code & ec = system::throws );
- bool reported() const;
+ class process_user_cpu_clock {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<process_user_cpu_clock> time_point;
+ static const bool is_monotonic = true;
+ static time_point now( system::error_code & ec = system::throws );
+ };
- typedef stopwatch_runner<basic_stopwatch_reporter<Stopwatch> > scoped_run;
- typedef stopwatch_suspender<basic_stopwatch_reporter<Stopwatch> > scoped_suspend;
- typedef stopwatch_resumer<basic_stopwatch_reporter<Stopwatch> > scoped_resume;
- };
[endsect]
-[section Template Class `stopwatch_reporter<>`]
-
-class `stopwatch_reporter` provides a everything a Timer provides and it adds reporting capabilities that can be invoked in a single line of code. The reporting is controleed by two parameters:
+[section Class `process_system_cpu_clock`]
-* format : The output format
-* places(precission): the number of decimal placess used.
+`process_system_cpu_clock` satisfy the [@boost_chrono/reference/cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_ Clock Requirements].
-The default places is given by Formatter::default_places().
+`process_system_cpu_clock` class provides access to the system CPU-time monotonic clockof the calling process. The process relative system current time can be obtained by calling `process_system_cpu_clock::now()`.
-The default format is given by Formatter::default_format().
+ class process_system_cpu_clock {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<process_system_cpu_clock> time_point;
+ static const bool is_monotonic = true;
- template <class Stopwatch, class Formatter>
- class stopwatch_reporter : public basic_stopwatch_reporter<Stopwatch,Formatter> {
- public:
- typedef typename Stopwatch::clock clock;
- typedef Stopwatch stopwatch;
- typedef Formatter formatter;
+ static time_point now( system::error_code & ec = system::throws );
+ };
- explicit stopwatch_reporter( system::error_code & ec = system::throws );
- explicit stopwatch_reporter( std::ostream & os,
- system::error_code & ec = system::throws );
- explicit stopwatch_reporter( const std::string & format,
- system::error_code & ec = system::throws );
- explicit stopwatch_reporter( std::ostream & os, const std::string & format,
- system::error_code & ec = system::throws );
+[endsect]
- explicit stopwatch_reporter( const std::string & format, int places,
- system::error_code & ec = system::throws );
- explicit stopwatch_reporter( std::ostream & os, const std::string & format, int places,
- system::error_code & ec = system::throws );
+[section Class `process_cpu_clock`]
- explicit stopwatch_reporter( int places,
- system::error_code & ec = system::throws );
- explicit stopwatch_reporter( std::ostream & os, int places,
- system::error_code & ec = system::throws );
+`process_cpu_clock` can be considered as a `tuple<process_real_cpu_clock, process_user_cpu_clock, process_system_cpu_clock>`.
- explicit stopwatch_reporter( int places, const std::string & format,
- system::error_code & ec = system::throws );
- explicit stopwatch_reporter( std::ostream & os, int places, const std::string & format,
- system::error_code & ec = system::throws );
+`process_cpu_clock` provides a thin wrapper around the operating system's process time API. For POSIX-like systems, that's the times() function, while for Windows, it's the GetProcessTimes() function.
- ~stopwatch_reporter();
+The process relative real, user and system current time can be obtained at once by calling `process_clocks::now()`.
- void report( system::error_code & ec = system::throws );
- bool reported() const;
+ class BOOST_CHRONO_DECL process_cpu_clock
+ {
+ public:
+ struct times ;
+ typedef duration<times, nano> duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<process_cpu_clock> time_point;
+ static const bool is_monotonic = true;
- typedef stopwatch_runner<stopwatch_reporter<Stopwatch> > scoped_run;
- typedef stopwatch_suspender<stopwatch_reporter<Stopwatch> > scoped_suspend;
- typedef stopwatch_resumer<stopwatch_reporter<Stopwatch> > scoped_resume;
+ static time_point now( system::error_code & ec = system::throws );
};
-Usage
+ template <>
+ struct duration_values<process_cpu_clock::times>;
- void f1()
- {
- typedef stopwatch_reporter<stopwatch_accumulator<> > accumulator;
- static accumulator t;
- accumulator::scoped_run _(t);
- // ...
- // call to some function we don't want to measure
- {
- accumulator::scoped_suspend _(t);
- external_function();
- }
- }
+[section Class `times`]
-[endsect]
+This class is the representation of the process_cpu_clock::duration class. As such it needs to implements the arithmetic operators.
-[section Template Class `wstopwatch_reporter<>`]
+ struct times : arithmetic<times>, less_than_comparable<times>
+ {
+ process_real_cpu_clock::rep real; // real (i.e wall clock) time
+ process_user_cpu_clock::rep user; // user cpu time
+ process_system_cpu_clock::rep system; // system cpu time
-class `wstopwatch_reporter` provides a everything a Timer provides and it adds reporting capabilities that can be invoked in a single line of code. The reporting is controleed by two parameters:
+ times();
+ times(
+ process_real_cpu_clock::rep r,
+ process_user_cpu_clock::rep u,
+ process_system_cpu_clock::rep s);
-* format : The output format
-* places(precission): the number of decimal placess used.
-
-The default places is given by Formatter::default_places().
+ bool operator==(times const& rhs);
-The default format is given by Formatter::default_format().
+ times operator+=(times const& rhs);
+ times operator-=(times const& rhs);
+ times operator*=(times const& rhs);
+ times operator/=(times const& rhs);
+ bool operator<(times const & rhs) const;
+ };
- template <class Stopwatch, class Formatter>
- class wstopwatch_reporter : public basic_wstopwatch_reporter<Stopwatch,Formatter> {
- public:
- typedef typename Stopwatch::clock clock;
- typedef Stopwatch stopwatch;
- typedef Formatter formatter;
+[endsect]
- explicit wstopwatch_reporter( system::error_code & ec = system::throws );
- explicit wstopwatch_reporter( std::ostream & os,
- system::error_code & ec = system::throws );
+[section `duration_values` specialization for `times`]
- explicit wstopwatch_reporter( const std::string & format,
- system::error_code & ec = system::throws );
- explicit wstopwatch_reporter( std::ostream & os, const std::string & format,
- system::error_code & ec = system::throws );
+ template <>
+ struct duration_values<process_cpu_clock::times>
+ {
+ static process_cpu_clock::times zero();
+ static process_cpu_clock::times max();
+ static process_cpu_clock::times min();
+ };
- explicit wstopwatch_reporter( const std::string & format, int places,
- system::error_code & ec = system::throws );
- explicit wstopwatch_reporter( std::ostream & os, const std::string & format, int places,
- system::error_code & ec = system::throws );
+The `times` specific functions `zero()`, `max()` and `min()` uses the relative functions on the representation of each component.
- explicit wstopwatch_reporter( int places,
- system::error_code & ec = system::throws );
- explicit wstopwatch_reporter( std::ostream & os, int places,
- system::error_code & ec = system::throws );
+[endsect]
- explicit wstopwatch_reporter( int places, const std::string & format,
- system::error_code & ec = system::throws );
- explicit wstopwatch_reporter( std::ostream & os, int places, const std::string & format,
- system::error_code & ec = system::throws );
+[endsect]
- ~wstopwatch_reporter();
+[endsect]
- void report( system::error_code & ec = system::throws );
- bool reported() const;
+[/==================================================================]
+[section:thread_clock_hpp Header `<boost/chrono/thread_clock.hpp>`]
+[/==================================================================]
+Knowing the time a thread takes to execute is useful in both test and production environments.
- typedef stopwatch_runner<wstopwatch_reporter<Stopwatch> > scoped_run;
- typedef stopwatch_suspender<wstopwatch_reporter<Stopwatch> > scoped_suspend;
- typedef stopwatch_resumer<wstopwatch_reporter<Stopwatch> > scoped_resume;
- };
+ #define BOOST_CHRONO_HAS_THREAD_CLOCK
+ #define BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC
+ namespace boost { namespace chrono {
-Usage
+ class thread_clock;
- void f1()
- {
- typedef wstopwatch_reporter<stopwatch_accumulator<> > accumulator;
- static accumulator t;
- accumulator::scoped_run _(t);
- // ...
+ } }
- // call to some function we don't want to measure
- {
- accumulator::scoped_suspend _(t);
- external_function();
- }
- }
+[section Macro `BOOST_CHRONO_HAS_THREAD_CLOCK`]
-[endsect]
+This macro is defined if the platform supports thread clocks.
[endsect]
-[/==================================================]
-[section:stopclock_hpp Header `<boost/chrono/stopclock.hpp>`]
-[/==================================================]
-
- namespace boost { namespace chrono {
- template < class Clock, class Formatter > class basic_stopclock;
- template < class Clock, class Formatter > class stopclock;
- template < class Clock, class Formatter > class wstopclock;
-
- typedef <see above> system_stopclock;
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef <see above> monotonic_stopclock;
- #endif
- typedef <see above> high_resolution_stopclock;
- typedef <see above> process_real_cpu_stopclock;
- typedef <see above> process_user_cpu_stopclock;
- typedef <see above> process_system_cpu_stopclock;
+[section Macro `BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC`]
- typedef <see above> system_wstopclock;
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef <see above> monotonic_wstopclock;
- #endif
- typedef <see above> high_resolution_wstopclock;
- typedef <see above> process_real_cpu_wstopclock;
- typedef <see above> process_user_cpu_wstopclock;
- typedef <see above> process_system_cpu_wstopclock;
- }}
+This macro is defined if the platform has a thread clockIts value is true if it is monotonic and false otherwise.
-[section Template Class `basic_stopclock<>`]
+[endsect]
-`basic_stopclock<Clock>` template class is a shortcut of `basic_stopwatch_reporter<stopwatch<Clock>>`
+[section Class `thread_clock`]
- template< class Clock, class Formatter>
- class basic_stopclock : public basic_stopwatch_reporter<stopwatch<Clock>, Formatter> {
- public:
- typedef Clock clock;
- typedef stopwatch<Clock> stopwatch;
- typedef Formatter formatter;
- typedef typename Formatter::string_type string_type;
- typedef typename Formatter::char_type char_type;
- typedef typename Formatter::ostream_type ostream_type;
+`thread_clock` satisfy the [@boost_chrono/reference/cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_ Clock Requirements].
- explicit basic_stopclock( system::error_code & ec = system::throws );
- explicit basic_stopclock( ostream_type & os,
- system::error_code & ec = system::throws );
- explicit basic_stopclock( const string_type & format,
- system::error_code & ec = system::throws );
- explicit basic_stopclock( int places,
- system::error_code & ec = system::throws );
+`thread_clock` class provides access to the real thread wall-clock, i.e. the real CPU-time clock of the calling thread. The thread relative current time can be obtained by calling `thread_clock::now()`.
- basic_stopclock( ostream_type & os, const string_type & format,
- system::error_code & ec = system::throws );
- basic_stopclock( const string_type & format, int places,
- system::error_code & ec = system::throws );
- basic_stopclock( ostream_type & os, int places,
- system::error_code & ec = system::throws );
- basic_stopclock( int places, const string_type & format,
- system::error_code & ec = system::throws );
+ class thread_clock {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<thread_clock> time_point;
+ static const bool is_monotonic = BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC;
- basic_stopclock( ostream_type & os, const string_type & format, int places,
- system::error_code & ec = system::throws );
- basic_stopclock( ostream_type & os, int places, const string_type & format,
- system::error_code & ec = system::throws );
+ static time_point now( system::error_code & ec = system::throws );
+ };
- typedef typename base_type::scoped_run scoped_run;
- typedef typename base_type::scoped_suspend scoped_suspend;
- typedef typename base_type::scoped_resume scoped_resume;
- };
+[endsect]
[endsect]
-[section Template Class `stopclock<>`]
-`stopclock<Clock>` template class is a shortcut of `stopwatch_reporter<stopwatch<Clock>>` with a specific default formatter.
- template
- < class Clock=process_cpu_clock
- , class Formatter=typename stopwatch_reporter_default_formatter<stopwatch<Clock>>::type
- > class stopclock : public basic_stopclock<Clock, Formatter> {
- public:
- typedef Clock clock;
- typedef stopwatch<Clock> stopwatch;
- typedef Formatter formatter;
- typedef typename Formatter::string_type string_type;
- typedef typename Formatter::char_type char_type;
- typedef typename Formatter::ostream_type ostream_type;
+[section:suspendible_clock_req `SuspendibleClock` requirements]
- explicit stopclock( system::error_code & ec = system::throws );
- explicit stopclock( ostream_type & os,
- system::error_code & ec = system::throws );
- explicit stopclock( const string_type & format,
- system::error_code & ec = system::throws );
- explicit stopclock( int places,
- system::error_code & ec = system::throws );
+A `SuspendibleClock` is a Clock that in addition supports `suspend`/`resume` operations.
- stopclock( ostream_type & os, const string_type & format,
- system::error_code & ec = system::throws );
- stopclock( const string_type & format, int places,
- system::error_code & ec = system::throws );
- stopclock( ostream_type & os, int places,
- system::error_code & ec = system::throws );
- stopclock( int places, const string_type & format,
- system::error_code & ec = system::throws );
+A `SuspendibleClock` must meet the requirements in the following Table.
- stopclock( ostream_type & os, const string_type & format, int places,
- system::error_code & ec = system::throws );
- stopclock( ostream_type & os, int places, const string_type & format,
- system::error_code & ec = system::throws );
+In this table `C` denote `clock` types.
+[table SuspendibleClock Requirements
+ [[expression] [return type] [operational semantics]]
+ [[`C::suspend()`] [`void`] [Suspends the time counting of the clock C.]]
+ [[`C::resume()`] [`void`] [Resumes the time counting of the clock C.]]
+ [[`C::suspended()`] [`duration`] [Returns the delay(duration during which the clock has been suspended.]]
+]
- typedef typename base_type::scoped_run scoped_run;
- typedef typename base_type::scoped_suspend scoped_suspend;
- typedef typename base_type::scoped_resume scoped_resume;
- };
+[section:SuspendibleClock_suspend Static Member Function `suspend()`]
-[endsect]
-[section `stopclock` useful typedefs]
+ void suspend( system::error_code & ec = system::throws );
- typedef boost::chrono::stopclock< boost::chrono::system_clock > system_stopwatch_reporter;
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef boost::chrono::stopclock< boost::chrono::monotonic_clock > monotonic_stopwatch_reporter;
- #endif
- typedef boost::chrono::stopclock< boost::chrono::high_resolution_clock > high_resolution_stopclock;
- typedef boost::chrono::stopclock< boost::chrono::process_real_cpu_clock > process_real_cpu_stopclock;
- typedef boost::chrono::stopclock< boost::chrono::process_user_cpu_clock > process_user_cpu_stopclock;
- typedef boost::chrono::stopclock< boost::chrono::process_system_cpu_clock > process_system_cpu_stopclock;
+[*Effect:] Suspends the SuspendibleClock.
+
+[*Throw:] Any exception the `Clock::now(ec)` function can throw. Otherwise `ec` is set with the correspoding error code set by `Clock::now(ec)`.
[endsect]
+[section:SuspendibleClock_resume Static Member Function `resume()`]
-[section Template Class `wstopclock<>`]
+ void resume( system::error_code & ec = system::throws );
-`wstopclock<Clock>` template class is a shortcut of `stopwatch_reporter<stopwatch<Clock>>` with a specific default formatter.
+[*Effect:] Resumes the `SuspendibleClock`.
- template
- < class Clock=process_cpu_clock
- , class Formatter=typename stopwatch_reporter_default_formatter<stopwatch<Clock>>::type
- > class wstopclock : public basic_wstopclock<Clock, Formatter> {
- public:
- typedef Clock clock;
- typedef stopwatch<Clock> stopwatch;
- typedef Formatter formatter;
- typedef typename Formatter::string_type string_type;
- typedef typename Formatter::char_type char_type;
- typedef typename Formatter::ostream_type ostream_type;
+[*Throw:] Any exception the `Clock::now(ec)` can throw. Otherwise `ec` is set with the correspoding error code set by `Clock::now(ec)`.
- explicit wstopclock( system::error_code & ec = system::throws );
- explicit wstopclock( ostream_type & os,
- system::error_code & ec = system::throws );
- explicit wstopclock( const string_type & format,
- system::error_code & ec = system::throws );
- explicit wstopclock( int places,
- system::error_code & ec = system::throws );
+[endsect]
- wstopclock( ostream_type & os, const string_type & format,
- system::error_code & ec = system::throws );
- wstopclock( const string_type & format, int places,
- system::error_code & ec = system::throws );
- wstopclock( ostream_type & os, int places,
- system::error_code & ec = system::throws );
- wstopclock( int places, const string_type & format,
- system::error_code & ec = system::throws );
+[section:SuspendibleClock_suspended Static Member Function `suspended()`]
- wstopclock( ostream_type & os, const string_type & format, int places,
- system::error_code & ec = system::throws );
- wstopclock( ostream_type & os, int places, const string_type & format,
- system::error_code & ec = system::throws );
+ duration suspended( system::error_code & ec = system::throws );
+[*Returns:] the cumalative elapsed duration during which the `SuspendibleClock` has been suspendeed.
- typedef typename base_type::scoped_run scoped_run;
- typedef typename base_type::scoped_suspend scoped_suspend;
- typedef typename base_type::scoped_resume scoped_resume;
- };
+[*Throw:] Any exception the Clock::now function can throw if `ec == system::throws`. Otherwise `ec` is set with the correspoding error code set by `Clock::now(ec)`.
[endsect]
-[section `wstopclock` useful typedefs]
- typedef boost::chrono::wstopclock< boost::chrono::system_clock > system_stopwatch_reporter;
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef boost::chrono::wstopclock< boost::chrono::monotonic_clock > monotonic_stopwatch_reporter;
- #endif
- typedef boost::chrono::wstopclock< boost::chrono::high_resolution_clock > high_resolution_wstopclock;
- typedef boost::chrono::wstopclock< boost::chrono::process_real_cpu_clock > process_real_cpu_wstopclock;
- typedef boost::chrono::wstopclock< boost::chrono::process_user_cpu_clock > process_user_cpu_wstopclock;
- typedef boost::chrono::wstopclock< boost::chrono::process_system_cpu_clock > process_system_cpu_wstopclock;
+Models of `SuspendibleClock`:
-[endsect]
+* [@boost_chrono/reference/other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_hpp.template_class__suspendible_clock___ `suspendible_clock<Clock>`]
[endsect]
-[/==================================================]
-[section:stopclock_accumulator_hpp Header `<boost/chrono/stopclock_accumulator.hpp>`]
-[/==================================================]
+[/==================================================================]
+[section:scoped_suspend_hpp Header `<boost/chrono/scoped_suspend.hpp>`]
+[/==================================================================]
namespace boost { namespace chrono {
- template < class Clock, class Formatter >
- class basic_stopclock_accumulator;
- template < class Clock, class Formatter >
- class stopclock_accumulator;
- template < class Clock, class Formatter >
- class wstopclock_accumulator;
-
- typedef <see above> system_stopclock_accumulator;
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef <see above> monotonic_stopclock_accumulator;
- #endif
- typedef <see above> high_resolution_stopclock_accumulator;
- typedef <see above> process_real_cpu_stopclock_accumulator;
- typedef <see above> process_user_cpu_stopclock_accumulator;
- typedef <see above> process_system_cpu_stopclock_accumulator;
-
- typedef <see above> system_wstopclock_accumulator;
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef <see above> monotonic_wstopclock_accumulator;
- #endif
- typedef <see above> high_resolution_wstopclock_accumulator;
- typedef <see above> process_real_cpu_wstopclock_accumulator;
- typedef <see above> process_user_cpu_wstopclock_accumulator;
- typedef <see above> process_system_cpu_wstopclock_accumulator;
+ template <class Clock> struct is_suspendible;
+ template <class Clock> class scoped_suspend;
}}
-[section Template Class `basic_stopclock_accumulator<>`]
-
-`basic_stopclock_accumulator<Clock>` template class is a shortcut of `stopwatch_reporter<stopwatch<Clock>>`
-
- template
- < class Clock=high_resolution_clock
- , class Formatter=typename stopwatch_reporter_default_formatter<stopwatch_accumulator<Clock>>::type
- > class basic_stopclock_accumulator
- : public basic_stopwatch_reporter<stopwatch_accumulator<Clock>, Formatter> {
- public:
- typedef Clock clock;
- typedef stopwatch_accumulator<Clock> stopwatch;
- typedef Formatter formatter;
- typedef typename Formatter::string_type string_type;
- typedef typename Formatter::char_type char_type;
- typedef typename Formatter::ostream_type ostream_type;
-
- explicit basic_stopclock_accumulator( system::error_code & ec = system::throws );
- explicit basic_stopclock_accumulator( ostream_type & os,
- system::error_code & ec = system::throws );
- explicit basic_stopclock_accumulator( const string_type & format,
- system::error_code & ec = system::throws );
- explicit basic_stopclock_accumulator( int places,
- system::error_code & ec = system::throws );
+[section Meta Function Class `is_suspendible`]
- basic_stopclock_accumulator( ostream_type & os, const string_type & format,
- system::error_code & ec = system::throws );
- basic_stopclock_accumulator( const string_type & format, int places,
- system::error_code & ec = system::throws );
- basic_stopclock_accumulator( ostream_type & os, int places,
- system::error_code & ec = system::throws );
- basic_stopclock_accumulator( int places, const string_type & format,
- system::error_code & ec = system::throws );
+ template <class Clock>
+ struct is_suspendible : mpl:: false_ {};
- basic_stopclock_accumulator( ostream_type & os, const string_type & format, int places,
- system::error_code & ec = system::throws );
- basic_stopclock_accumulator( ostream_type & os, int places, const string_type & format,
- system::error_code & ec = system::throws );
+[endsect]
+[section Template Class `scoped_suspend`]
- typedef typename base_type::scoped_run scoped_run;
- typedef typename base_type::scoped_suspend scoped_suspend;
- typedef typename base_type::scoped_resume scoped_resume;
+ template <class Clock>
+ class scoped_suspend {
+ public:
+ scoped_suspend(system::error_code & ec = system::throws) {}
+ ~scoped_suspend() {}
+ private:
+ scoped_suspend(); // = delete;
+ scoped_suspend(const scoped_suspend&); // = delete;
+ scoped_suspend& operator=(const scoped_suspend&); // = delete;
};
[endsect]
-[section Template Class `stopclock_accumulator<>`]
-
-`stopclock_accumulator<Clock>` template class is a shortcut of `stopwatch_reporter<stopwatch<Clock>>` with a specific formatter.
-
- template
- < class Clock=high_resolution_clock
- , class Formatter=typename stopwatch_reporter_default_formatter<stopwatch_accumulator<Clock>>::type
- > class stopclock_accumulator
- : public basic_stopclock_accumulator<Clock, Formatter> {
- public:
- typedef Clock clock;
- typedef stopwatch_accumulator<Clock> stopwatch;
- typedef Formatter formatter;
- typedef typename Formatter::string_type string_type;
- typedef typename Formatter::char_type char_type;
- typedef typename Formatter::ostream_type ostream_type;
+[endsect]
- explicit stopclock_accumulator( system::error_code & ec = system::throws );
- explicit stopclock_accumulator( ostream_type & os,
- system::error_code & ec = system::throws );
- explicit stopclock_accumulator( const string_type & format,
- system::error_code & ec = system::throws );
- explicit stopclock_accumulator( int places,
- system::error_code & ec = system::throws );
- stopclock_accumulator( ostream_type & os, const string_type & format,
- system::error_code & ec = system::throws );
- stopclock_accumulator( const string_type & format, int places,
- system::error_code & ec = system::throws );
- stopclock_accumulator( ostream_type & os, int places,
- system::error_code & ec = system::throws );
- stopclock_accumulator( int places, const string_type & format,
- system::error_code & ec = system::throws );
+[/==================================================================]
+[section:suspendible_clock_hpp Header `<boost/chrono/suspendible_clock.hpp>`]
+[/==================================================================]
- stopclock_accumulator( ostream_type & os, const string_type & format, int places,
- system::error_code & ec = system::throws );
- stopclock_accumulator( ostream_type & os, int places, const string_type & format,
- system::error_code & ec = system::throws );
+ namespace boost { namespace chrono {
+ template <class Clock>
+ class suspendible_clock;
- typedef typename base_type::scoped_run scoped_run;
- typedef typename base_type::scoped_suspend scoped_suspend;
- typedef typename base_type::scoped_resume scoped_resume;
- };
+ template <class Clock>
+ struct is_suspendible<suspendible_clock<Clock> > : mpl:: true_ {};
-[endsect]
-[section `stopclock_accumulator` useful typedefs]
+ template <class Clock>
+ class scoped_suspend<suspendible_clock<Clock> >;
- typedef boost::chrono::stopclock_accumulator< boost::chrono::system_clock > system_stopwatch_reporter;
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef boost::chrono::stopclock_accumulator< boost::chrono::monotonic_clock > monotonic_stopwatch_reporter;
- #endif
- typedef boost::chrono::stopclock_accumulator< boost::chrono::high_resolution_clock > high_resolution_stopclock_accumulator;
- typedef boost::chrono::stopclock_accumulator< boost::chrono::process_real_cpu_clock > process_real_cpu_stopclock_accumulator;
- typedef boost::chrono::stopclock_accumulator< boost::chrono::process_user_cpu_clock > process_user_cpu_stopclock_accumulator;
- typedef boost::chrono::stopclock_accumulator< boost::chrono::process_system_cpu_clock > process_system_cpu_stopclock_accumulator;
+ }}
-[endsect]
-[section Template Class `wstopclock_accumulator<>`]
+[section Template Class `suspendible_clock<>`]
-`wstopclock_accumulator<Clock>` template class is a shortcut of `stopwatch_reporter<stopwatch<Clock>>` with a specific formatter.
+Given a `Clock`, `suspendible_clock<Clock>` is a model of [@boost_chrono/reference/other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_req SuspendibleClock].
- template
- < class Clock=high_resolution_clock
- , class Formatter=typename stopwatch_reporter_default_formatter<stopwatch_accumulator<Clock>>::type
- > class wstopclock_accumulator
- : public basic_wstopclock_accumulator<Clock, Formatter> {
+ template < class Clock >
+ class suspendible_clock {
public:
- typedef Clock clock;
- typedef stopwatch_accumulator<Clock> stopwatch;
- typedef Formatter formatter;
- typedef typename Formatter::string_type string_type;
- typedef typename Formatter::char_type char_type;
- typedef typename Formatter::ostream_type ostream_type;
-
- explicit wstopclock_accumulator( system::error_code & ec = system::throws );
- explicit wstopclock_accumulator( ostream_type & os,
- system::error_code & ec = system::throws );
- explicit wstopclock_accumulator( const string_type & format,
- system::error_code & ec = system::throws );
- explicit wstopclock_accumulator( int places,
- system::error_code & ec = system::throws );
+ typedef typename Clock::duration duration;
+ typedef typename Clock::rep rep;
+ typedef typename Clock::period period;
+ typedef chrono::time_point<suspendible_clock<Clock> > time_point;
+ static const bool is_monotonic = true;
- wstopclock_accumulator( ostream_type & os, const string_type & format,
- system::error_code & ec = system::throws );
- wstopclock_accumulator( const string_type & format, int places,
- system::error_code & ec = system::throws );
- wstopclock_accumulator( ostream_type & os, int places,
- system::error_code & ec = system::throws );
- wstopclock_accumulator( int places, const string_type & format,
- system::error_code & ec = system::throws );
+ static time_point now( system::error_code & ec = system::throws );
- wstopclock_accumulator( ostream_type & os, const string_type & format, int places,
- system::error_code & ec = system::throws );
- wstopclock_accumulator( ostream_type & os, int places, const string_type & format,
- system::error_code & ec = system::throws );
+ static void suspend( system::error_code & ec = system::throws );
+ static void resume( system::error_code & ec = system::throws );
+ static duration suspended(system::error_code & ec = system::throws);
+ };
+[section `scoped_suspend` specialization for `suspendible_clock<>`]
- typedef typename base_type::scoped_run scoped_run;
- typedef typename base_type::scoped_suspend scoped_suspend;
- typedef typename base_type::scoped_resume scoped_resume;
- };
+ template <class Clock>
+ class scoped_suspend<suspendible_clock<Clock> > {
+ public:
+ scoped_suspend(system::error_code & ec = system::throws);
+ ~scoped_suspend();
+ };
[endsect]
-[section `wstopclock_accumulator` useful typedefs]
- typedef boost::chrono::wstopclock_accumulator< boost::chrono::system_clock > system_stopwatch_reporter;
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef boost::chrono::wstopclock_accumulator< boost::chrono::monotonic_clock > monotonic_stopwatch_reporter;
- #endif
- typedef boost::chrono::wstopclock_accumulator< boost::chrono::high_resolution_clock > high_resolution_wstopclock_accumulator;
- typedef boost::chrono::wstopclock_accumulator< boost::chrono::process_real_cpu_clock > process_real_cpu_wstopclock_accumulator;
- typedef boost::chrono::wstopclock_accumulator< boost::chrono::process_user_cpu_clock > process_user_cpu_wstopclock_accumulator;
- typedef boost::chrono::wstopclock_accumulator< boost::chrono::process_system_cpu_clock > process_system_cpu_wstopclock_accumulator;
+[endsect]
[endsect]
+
[endsect]
+
[/==================================================]
-[section:scoped_stopclock_hpp Header `<boost/chrono/scoped_stopclock.hpp>`]
+[section Stopwatches]
[/==================================================]
+[/=============================================]
+[section:stopwatches_hpp Header `<boost/stopwatches.hpp>`]
+[/=============================================]
- namespace boost { namespace chrono {
- template < class Clock, class Formatter > class scoped_stopclock;
- }}
+This file include all the stopwatches related files
-[section Template Class `scoped_stopclock<>`]
+ #include <boost/chrono/stopwatches.hpp>
-`scoped_stopclock<>`is like a `stopclock<>` but that in addition will output a scoped trace. At construction time it will output
+[endsect]
- {{{ <string>
+[/=============================================]
+[section:chrono_stopwatches_hpp Header `<boost/chrono/stopwatches.hpp>`]
+[/=============================================]
-and at destruction time
+This file include all the stopwatches related files
- }}} <string> <output of stopwatch_reporter>
+ #include <boost/chrono/scoped_stopclock.hpp>
+ #include <boost/chrono/process_cpu_clocks.hpp>
+ #include <boost/chrono/stopclock.hpp>
+ #include <boost/chrono/stopclock_accumulator.hpp>
+ #include <boost/chrono/stopwatch.hpp>
+ #include <boost/chrono/stopwatch_accumulator.hpp>
+ #include <boost/chrono/stopwatch_accumulator_formatter.hpp>
+ #include <boost/chrono/stopwatch_formatter.hpp>
+ #include <boost/chrono/stopwatch_reporter.hpp>
+ #include <boost/chrono/stopwatch_scoped.hpp>
+ #include <boost/chrono/time_formatter.hpp>
+ #include <boost/chrono/t24_hours.hpp>
+ #include <boost/chrono/t24_hours_formatter.hpp>
-A typical ussage of this class is
+[endsect]
- int f1(long j)
- {
- scoped_stopclock<> _(BOOST_CURRENT_FUNCTION);
+[section:stopwatch_req `Stopwatch` Requirements]
- for ( long i = 0; i < j; ++i )
- std::sqrt( 123.456L ); // burn some time
+A Stopwatch measure the amount of time elapsed from a particular time when activated to when it is deactivated, or the accumulation of them.
- return 0;
- }
+A Stopwatch must meet the requirements in the following Table.
- template < class Clock=process_cpu_clock
- , class Formatter=typename stopwatch_reporter_default_formatter<stopwatch<Clock>>::type
- > class scoped_stopclock
- : public stopwatch_reporter<stopwatch<Clock>, Formatter> {
- public:
- typedef Clock clock;
- typedef Stopwatch stopwatch;
- typedef Formatter formatter;
- typedef typename Formatter::string_type string_type;
- typedef typename Formatter::char_type char_type;
- typedef typename Formatter::ostream_type ostream_type;
+In this table `S`, `S1` and `S2` denote stopwatches types. `s` is an instance of `S`.
- explicit scoped_stopclock( const std::string& func,
- system::error_code & ec = system::throws );
- scoped_stopclock( const std::string& func, ostream_type & os,
- system::error_code & ec = system::throws );
+[table Stopwatch Requirements
+ [[expression] [return type] [operational semantics]]
+ [[`S::clock`] [A model of the Clock concept.] [The clock associated to this Stopwatch.]]
+ [[`S::duration`] [`S::clock::duration`] [The `duration` type of the `clock`.]]
+ [[`S::time_point`] [`S::clock::time_point`] [The `time_point` type of the `clock`.]]
+ [[`s.start()`] [`S::time_point`] [starts a Stopwatch.]]
+ [[`s.restart()`] [`std::pair<S::duration,S::time_point>`] [restarts a Stopwatch.]]
+ [[`s.stop()`] [`S::duration`] [stops a Stopwatch.]]
+ [[`s.resume()`] [`S::time_point`] [starts a Stopwatch.]]
+ [[`s.suspend()`] [`S::duration`] [stops a Stopwatch.]]
+ [[`s.elapsed()`] [`S::duration`] [the elapsed time while the Stopwatch was running.]]
+]
- scoped_stopclock( const std::string& func, const string_type & format,
- system::error_code & ec = system::throws );
- scoped_stopclock( const std::string& func, int places,
- system::error_code & ec = system::throws );
+[section:stopwatch_start Member Function `start()`]
- scoped_stopclock( const std::string& func, ostream_type & os,
- const string_type & format,
- system::error_code & ec = system::throws );
+ time_point start( system::error_code & ec = system::throws );
- scoped_stopclock( const std::string& func, const string_type & format,
- int places, system::error_code & ec = system::throws );
+[*Effect:] Starts running the stopwatch.
- scoped_stopclock( const std::string& func, ostream_type & os, int places,
- system::error_code & ec = system::throws );
+[*Returns:] the starting time point.
- scoped_stopclock( const std::string& func, int places,
- const string_type & format, system::error_code & ec = system::throws );
+[*Throw:] Any exception the Clock::now function can throw.
- scoped_stopclock( const std::string& func, ostream_type & os,
- const string_type & format, int places,
- system::error_code & ec = system::throws );
+[endsect]
+[section:stopwatch_stop Member Function `stop()`]
- scoped_stopclock( const std::string& func, ostream_type & os, int places,
- const string_type & format, system::error_code & ec = system::throws );
+ duration stop( system::error_code & ec = system::throws );
- ~scoped_stopclock();
+[*Effect:] Stops running the stopwatch.
- typedef typename base_type::scoped_run scoped_run;
- typedef typename base_type::scoped_suspend scoped_suspend;
- typedef typename base_type::scoped_resume scoped_resume;
- };
+[*Returns:] The cummulated elapsed time.
-[endsect]
+[*Throw:] Any exception the Clock::now function can throw.
[endsect]
-[endsect]
-[section Stopwatch Formatters]
+[section:stopwatch_suspend Member Function `suspend()`]
-[/==================================================]
-[section:stopwatch_formatter_hpp Header `<boost/chrono/stopwatch_formatter.hpp>`]
-[/==================================================]
+ duration suspend( system::error_code & ec = system::throws );
- namespace boost { namespace chrono {
- template <
- typename CharT=char,
- typename Traits=std::char_traits<CharT>,
- class Alloc=std::allocator<CharT>
- >
- class basic_stopwatch_formatter;
+[*Effect:] Suspends the stopwatch.
- typedef basic_stopwatch_formatter<char> stopwatch_formatter;
- typedef basic_stopwatch_formatter<wchar_t> wstopwatch_formatter;
- }}
+[*Throw:] Any exception the Clock::now function can throw.
-[section Template Class `basic_stopwatch_formatter<>`]
+[endsect]
+[section:stopwatch_resume Member Function `resume()`]
-`stopwatch_formatter` is a model of `Formatter`.
+ time_point resume( system::error_code & ec = system::throws );
- template <
- typename CharT=char,
- typename Traits=std::char_traits<CharT>,
- class Alloc=std::allocator<CharT>
- >
- class basic_stopwatch_formatter {
- 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 char_type * default_format();
- static int default_places();
+[*Effect:] Resumes the stopwatch.
- template < class Stopwatch >
- static void show_time( Stopwatch & stopwatch_, const char * format, int places, std::ostream & os, system::error_code & ec);
- };
+[*Returns:] the starting time point.
-The default places is given by default_places and is 3.
+[*Throw:] Any exception the Clock::now function can throw.
-The default format is "%ts\\n", where
+[endsect]
-* `%d` : the result of elapsed() when the reporting is done.
+[section:stopwatch_restart Member Function `restart()`]
-The time is given using the suffix "s" following the System International d'Unites Std.
+ time_point restart( system::error_code & ec = system::throws );
+
+[*Effect:] Stop/Start the stopwatch.
+
+[*Returns:] the starting time point.
+
+[*Throw:] Any exception the Clock::now function can throw.
[endsect]
-[endsect]
+Models of `Stopwatch`:
+
+* [@boost_chrono/reference/stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_hpp.template_class__stopwatch___ `stopwatch`]
+* [@boost_chrono/reference/stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_accumulator_hpp.template_class__stopwatch_accumulator___ `stopwatch_accumulator`]
+
+[endsect]
[/==================================================]
-[section:stopwatch_accumulator_formatter_hpp Header `<boost/chrono/stopwatch_accumulator_formatter.hpp>`]
+[section:stopwatch_hpp Header `<boost/chrono/stopwatch.hpp>`]
[/==================================================]
+
namespace boost { namespace chrono {
- template <
- typename CharT=char,
- typename Traits=std::char_traits<CharT>,
- class Alloc=std::allocator<CharT>
- > basic_stopwatch_accumulator_formatter;
- typedef basic_stopwatch_formatter<char> stopwatch_formatter;
- typedef basic_stopwatch_formatter<wchar_t> wstopwatch_formatter;
- }}
+ struct dont_start_t;
+ static const dont_start_t dont_start;
-[section Template Class `basic_stopwatch_accumulator_formatter<>`]
+ template <class Clock=high_resolution_clock> class stopwatch;
-`stopwatch_accumulator_formatter` is a model of `Formatter`
+ template <class Clock>
+ struct stopwatch_reporter_default_formatter<stopwatch<Clock> > {
+ typedef stopwatch_formatter type;
+ };
- template <
- typename CharT=char,
- typename Traits=std::char_traits<CharT>,
- class Alloc=std::allocator<CharT>
- class basic_stopwatch_accumulator_formatter {
- 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 char_type * default_format();
- static int default_places();
+ template <class Clock>
+ struct wstopwatch_reporter_default_formatter<stopwatch<Clock> > {
+ typedef wstopwatch_formatter type;
+ };
- template <class Stopwatch >
- static void show_time( Stopwatch & stopwatch_, const char * format, int places, std::ostream & os, system::error_code & ec);
- };
+ typedef <see above> system_stopwatch;
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef <see above> monotonic_stopwatch;
+ #endif
+ typedef <see above> high_resolution_stopwatch;
+ typedef <see above> process_real_cpu_stopwatch;
+ typedef <see above> process_user_cpu_stopwatch;
+ typedef <see above> process_system_cpu_stopwatch;
+ }}
-The default places is given by default_places and is 3.
+[section Template Class `stopwatch<>`]
-The default format is "%c times, sum=%ss, min=%ms, max=%Ms, mean=%as, frequency=%fHz, lifetime=%ls, percentage=%p\%\\n", where
+`stopwatch<>` is a model of a [@boost_chrono/reference/stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req `Stopwatch`].
-* `%c` : the counter of the number of times the pair srat/stop has been called.
-* `%s` : the sum of the samples of elapsed time between the call to start/stop.
-* `%m` : the min of the samples of elapsed time between the call to start/stop.
-* `%M` : the max of the samples of elapsed time between the call to start/stop.
-* `%a` : the mean of the samples of elapsed time between the call to start/stop.
-* `%f` : the frequency of calls to start.
-* `%l` : the lifetime of the stopwatch_accumulator.
-* `%p` : the percentage of time spent by this stopwatch respect to its lifetime.
+Knowing how long a part of a program takes to execute is useful in both test and production environments.
+A `stopwatch` object measures elapsed time. It is recommended to use it with clocks that measure wall clock rather than CPU time since the intended use is performance measurement on systems where total elapsed time is more important than just process or CPU time.
-The time is given using the suffix "s", the frequency is given using the suffix "Hz", both following the System International d'Unites Std.
+The maximum measurable elapsed time depends on the Clock parameter. The accuracy of timings depends on the
+accuracy of timing information provided the Clock, and this coudl varies a great deal from one clock to another.
-[endsect]
+ template <class Clock> class stopwatch {
+ public:
+ typedef Clock clock;
+ typedef typename Clock::duration duration;
+ typedef typename Clock::time_point time_point;
-[endsect]
+ explicit stopwatch( system::error_code & ec = system::throws );
+ explicit stopwatch( const dont_start_t& t );
-[/==================================================================]
-[section:time_formatter_hpp Header `<boost/chrono/time_formatter.hpp>`]
-[/==================================================================]
+ ~stopwatch();
+ time_point start( system::error_code & ec = system::throws );
+ duration stop( system::error_code & ec = system::throws );
+ std::pair<duration,time_point> restart( system::error_code & ec = system::throws );
- namespace boost { namespace chrono {
+ duration suspend( system::error_code & ec = system::throws );
+ time_point resume( system::error_code & ec = system::throws );
- template <
- typename CharT=char,
- typename Traits=std::char_traits<CharT>,
- class Alloc=std::allocator<CharT>
- >
- class basic_time_formatter;
+ duration elapsed( system::error_code & ec = system::throws );
- typedef basic_time_formatter<char> time_formatter;
- typedef basic_time_formatter<wchar_t> wtime_formatter;
+ typedef stopwatch_runner<stopwatch<Clock> > scoped_run;
+ typedef stopwatch_suspender<stopwatch<Clock> > scoped_suspend;
+ typedef stopwatch_resumer<stopwatch<Clock> > scoped_resume;
+ typedef stopwatch_reporter<stopwatch<Clock> > reporter;
- template <>
- struct stopwatch_reporter_default_formatter<stopwatch<process_cpu_clock> > {
- typedef time_formatter type;
};
- } }
-
-[section Template Class `basic_time_formatter<>`]
-
- template <typename CharT, typename Traits, class Alloc>
- class basic_time_formatter {
- 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 char_type * default_format();
- static int default_places();
-
- template <class Stopwatch >
- static void show_time( Stopwatch & stopwatch_
- , const char * format, int places, std::ostream & os
- , system::error_code & ec);
- };
+[section:stopwatch_elapsed Member Function `elapsed()`]
-The default places is given by default_places and is 3.
+ duration elapsed(system::error_code & ec = system::throws) const;
-The default format is "nreal %rs, cpu %cs (%p%), user %us, system %ss\\n", where
+[*Returns:] the elapsed time from the last call to start.
-* `%r` : real process clock
-* `%u` : user process clock
-* `%s` : system process clock
-* `%c` : user+system process clock
-* `%p` : percentage (user+system)/real process clock
+[*Throw:] Nothing.
-All the units are given using the suffix "s" following the System International d'Unites Std.
+[*Note:] the system::error_code & parameter is here to conform to the Stopwatch concept.
[endsect]
[endsect]
-[/==================================================]
-[section:t24_hours_hpp Header `<boost/chrono/t24_hours.hpp>`]
-[/==================================================]
-
- namespace boost { namespace chrono {
- class t24_hours;
- }}
-
-[section Class `t24_hours`]
-
- class t24_hours {
- public:
- typedef boost::chrono::duration<boost::int_least32_t, ratio<24*3600> > days;
- typedef boost::chrono::hours hours;
- typedef boost::chrono::minutes minutes;
- typedef boost::chrono::seconds seconds;
- typedef boost::chrono::nanoseconds nanoseconds;
+[section `stopwatch` useful typedefs]
- days days_;
- hours hours_;
- minutes minutes_;
- seconds seconds_;
- nanoseconds nanoseconds_;
+ typedef boost::chrono::stopwatch< boost::chrono::system_clock > system_stopwatch;
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef boost::chrono::stopwatch< boost::chrono::monotonic_clock > monotonic_stopwatch;
+ #endif
+ typedef boost::chrono::stopwatch< boost::chrono::high_resolution_clock > high_resolution_stopwatch;
- template <class Rep, class Period>
- explicit t24_hours(const boost::chrono::duration<Rep, Period>& d);
- };
+ typedef boost::chrono::stopwatch< boost::chrono::process_real_cpu_clock > process_real_cpu_stopwatch;
+ typedef boost::chrono::stopwatch< boost::chrono::process_user_cpu_clock > process_user_cpu_stopwatch;
+ typedef boost::chrono::stopwatch< boost::chrono::process_system_cpu_clock > process_system_cpu_stopwatch;
[endsect]
[endsect]
-[/==================================================================]
-[section:t24_hours_formatter_hpp Header `<boost/chrono/t24_hours_formatter.hpp>`]
-[/==================================================================]
+[/==================================================]
+[section:stopwatch_accumulator_hpp Header `<boost/chrono/stopwatch_accumulator.hpp>`]
+[/==================================================]
+ namespace boost { namespace chrono {
+ template <class Clock, class Accumulator> class stopwatch_accumulator;
- namespace boost { namespace chrono {
+ template <class Clock, class Accumulator>
+ struct stopwatch_reporter_default_formatter<stopwatch_accumulator<Clock, Accumulator> > {
+ typedef stopwatch_accumulator_formatter type;
+ };
- template <
- typename CharT=char,
- typename Traits=std::char_traits<CharT>,
- class Alloc=std::allocator<CharT>
- >
- class basic_24_hours_formatter;
+ template <class Clock, class Accumulator>
+ struct wstopwatch_reporter_default_formatter<stopwatch_accumulator<Clock, Accumulator> > {
+ typedef wstopwatch_accumulator_formatter type;
+ };
- typedef basic_24_hours_formatter<char> t24_hours_formatter;
- typedef basic_24_hours_formatter<wchar_t> wt24_hours_formatter;
+ typedef <see below> system_stopwatch_accumulator;
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef <see below> monotonic_stopwatch_accumulator;
+ #endif
+ typedef <see below> high_resolution_stopwatch_accumulator;
- } }
+ typedef <see below> process_real_cpu_stopwatch_accumulator;
+ typedef <see below> process_user_cpu_stopwatch_accumulator;
+ typedef <see below> process_system_cpu_stopwatch_accumulator;
-[section Template Class `basic_24_hours_formatter<>`]
+ }}
- template <typename CharT, typename Traits, class Alloc>
- class basic_24_hours_formatter {
- public:
- static std::ostream & default_os();
- static const char * default_format();
- static int default_places();
- template <class Stopwatch >
- static void show_time( Stopwatch & stopwatch_
- , const char * format, int places, std::ostream & os
- , system::error_code & ec);
- };
+[section Template Class `stopwatch_accumulator<>`]
-The default places is given by default_places and is 3.
+A `stopwatch_accumulator<>` is a model of a [@boost_chrono/reference/stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req `Stopwatch`] that allows to accumulate the time in several times instead of at once as it is the case of the class `stopwatch<>`.
-The default format is "%d days(s) %h:%m:%s.%n\\n", where
+ template <class Clock> class stopwatch_accumulator {
+ public:
+ typedef Clock clock;
+ typedef typename Clock::duration duration;
+ typedef typename Clock::time_point time_point;
+ typedef Accumulator accumulator;
-* `%d` : days
-* `%h` : hours
-* `%m` : minutes
-* `%s` : seconds
-* `%n` : nanoseconds
+ stopwatch_accumulator();
-[endsect]
+ time_point start( system::error_code & ec = system::throws );
+ duration stop( system::error_code & ec = system::throws );
+ std::pair<duration,time_point> restart( system::error_code & ec = system::throws );
-[endsect]
+ duration suspend( system::error_code & ec = system::throws );
+ time_point resume( system::error_code & ec = system::throws );
-[endsect]
-[section Deprecated Headers]
-[/==================================================]
-[section:timer_hpp Deprecated Header `<boost/chrono/timer.hpp>`]
-[/==================================================]
+ duration elapsed(system::error_code & ec = system::throws);
-This header has been deprecated, use instead <boost/chrono/stopwatch.hpp>.
+ accumulator& accumulated( );
+ void reset();
- namespace boost { namespace chrono {
- template <class Clock=high_resolution_clock> class timer;
- typedef <see above> system_timer;
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef <see above> monotonic_timer;
- #endif
- typedef <see above> high_resolution_timer;
- }}
+ typedef stopwatch_runner<stopwatch_accumulator<Clock> > scoped_run;
+ typedef stopwatch_suspender<stopwatch_accumulator<Clock> > scoped_suspend;
+ typedef stopwatch_resumer<stopwatch_accumulator<Clock> > scoped_resume;
+ typedef stopwatch_reporter<stopwatch_accumulator<Clock> > reporter;
+ };
-[/
- typedef <see above> process_real_cpu_timer;
- typedef <see above> process_user_cpu_timer;
- typedef <see above> process_system_cpu_timer;
-]
-[section Template Class `timer<>`]
+[section:stopwatch_accumulator_c Constructor `stopwatch_accumulator()`]
-Knowing how long a part of a program takes to execute is useful in both test and production environments.
-A `timer` object measures elapsed time. It is recommended to use it with clocks that measure wall clock rather than CPU time since the intended use is performance measurement on systems where total elapsed time is more important than just process or CPU time.
+ stopwatch_accumulator();
-The maximum measurable elapsed time depends on the Clock parameter. The accuracy of timings depends on the
-accuracy of timing information provided the Clock, and this coudl varies a great deal from one clock to another.
+[*Effect:] Initialize the elapsed duration and the times counter to 0.
- template <class Clock> class timer {
- public:
- typedef Clock clock;
- typedef typename Clock::duration duration;
- typedef typename Clock::time_point time_point;
+[endsect]
+[section:stopwatch_accumulator_start Member Function `start()`]
- explicit timer( system::error_code & ec = system::throws );
+ time_point start( system::error_code & ec = system::throws );
- ~timer();
+[*Effect:] Starts running the stopwatch.
- void start( system::error_code & ec = system::throws );
- duration elapsed( system::error_code & ec = system::throws );
+[*Returns:] the starting time point.
- };
+[*Throw:] Any exception the Clock::now function can throw.
[endsect]
+[section:stopwatch_accumulator_stop Member Function `stop()`]
-[section `timer` useful typedefs]
+ duration stop( system::error_code & ec = system::throws );
- typedef boost::chrono::timer< boost::chrono::system_clock > system_timer;
- #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
- typedef boost::chrono::timer< boost::chrono::monotonic_clock > monotonic_timer;
- #endif
- typedef boost::chrono::timer< boost::chrono::high_resolution_clock > high_resolution_timer;
+[*Effect:] Stops running the stopwatch. Accumulates the elapsed time since the last start-like operation + the partial accumulated by resume/suspend operation.
-[/
- typedef boost::chrono::timer< boost::chrono::process_real_cpu_clock > process_real_cpu_timer;
- typedef boost::chrono::timer< boost::chrono::process_user_cpu_clock > process_user_cpu_timer;
- typedef boost::chrono::timer< boost::chrono::process_system_cpu_clock > process_system_cpu_timer;
-]
-[endsect]
-[endsect]
+[*Returns:] The cummulated elapsed time.
+[*Throw:] Any exception the Clock::now function can throw.
-[/==================================================================]
-[section:process_times_hpp Deprecated Header `<boost/chrono/process_times.hpp>`]
-[/==================================================================]
+[endsect]
+[section:stopwatch_accumulator_suspend Member Function `suspend()`]
-This header has been deprecated. Use instead `<boost/chrono/process_cpu_clocks.hpp>`, `<boost/chrono/stopwatch.hpp>`, `<boost/chrono/stopwatch_reporter.hpp>` and `<boost/chrono/stopclock.hpp>` files.
+ duration suspend( system::error_code & ec = system::throws );
- namespace boost { namespace chrono {
+[*Effect:] Suspends the stopwatch. Accumulates the elapsed time since the last start-like operation on a partial duration.
- class process_clock;
- typedef <see below> process_times;
- class process_timer;
- class run_timer;
+[*Throw:] Any exception the Clock::now function can throw.
- } }
+[endsect]
+[section:stopwatch_accumulator_resume Member Function `resume()`]
-[section Class `process_clock`]
+ time_point resume( system::error_code & ec = system::throws );
-`process_clock` doesn't satisfy the Clock Requirements as the function now do not follows the Clock prototype.
+[*Effect:] Resumes the stopwatch.
+
+[*Returns:] the starting time point.
-`process_clock` provides a thin wrapper around the operating system's process timer API. For POSIX-like systems, that's the times() function, while for Windows, it's the GetProcessTimes() function.
+[*Throw:] Any exception the Clock::now function can throw.
-The process relative real, user and system current time can be obtained at once by calling `process_clock::now()`.
+[endsect]
+[section:stopwatch_accumulator_restart Member Function `restart()`]
- class process_clock {
- public:
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- typedef chrono::time_point<process_clock> time_point;
- static const bool is_monotonic = true;
+ time_point restart( system::error_code & ec = system::throws );
- struct process_times;
- static void now( process_times & times,
- system::error_code & ec = system::throws );
- };
+[*Effect:] Stop/Start the stopwatch.
-[section Class `process_times`]
+[*Returns:] the starting time point.
- struct process_times {
- process_clock::duration real; // real (i.e wall clock) time
- process_clock::duration user; // user cpu time
- process_clock::duration system; // system cpu time
- };
+[*Throw:] Any exception the Clock::now function can throw.
[endsect]
+[section:stopwatch_accumulator_reset Member Function `reset()`]
-[endsect]
-[section Typedef `process_times`]
+ void reset( );
- typedef process_clock::process_times process_times;
+[*Effect:] Stop the stopwatch and reset the accumulator.
-This is a synonym of process_clock::process_times included for backward compatibility.
+[*Throw:] Nothing.
[endsect]
+[section:stopwatch_accumulator_elapsed Member Function `elapsed()`]
-[section Class `process_timer`]
+ duration elapsed(system::error_code & ec = system::throws) const;
-Knowing how long a program takes to execute is useful in both test and production environments. It is also helpful if such timing information is broken down into real (wall clock) time, CPU time spent by the user, and CPU time spent by the operating system servicing user requests.
+[*Returns:] the cumulated elapsed time.
-`process_timer<>` is the `timer<>` equivalent associated to the pseudo-clock `process_clock`. It behaves like `timer<>` but it uses the specific `process_clock:now()` function.
+[*Throw:] Nothing.
- class process_timer {
- public:
- typedef process_clock clock;
- typedef process_clock::duration duration;
- typedef process_clock::time_point time_point;
+[endsect]
- explicit process_timer( system::error_code & ec = system::throws );
+[section:stopwatch_accumulator_accumulated Member Function `accumulated()`]
- ~process_timer();
- void start( system::error_code & ec = system::throws );
- void elapsed( process_times & times, system::error_code & ec = system::throws );
- };
+ accumulator& accumulated();
-[endsect]
-[section Class `run_timer`]
+[*Returns:] the assocaited accumulator.
-class `run_timer` provides a complete run time reporting package that can be invoked in a single line of code. The reporting is controled by two parameters:
+[*Throw:] Nothing.
-* format : The output format
-* places(precission): the number of decimal placess used.
+[endsect]
-The default places is given by default_places and is 3.
+[endsect]
-The default format is "nreal %rs, cpu %cs (%p%), user %us, system %ss\\n", where
-
-* `%r` : real process clock
-* `%u` : user process clock
-* `%s` : system process clock
-* `%c` : user+system process clock
-* `%p` : percentage (user+system)/real process clock
+[section `stopwatch_accumulator` useful typedefs]
-All the units are given using the suffix "s" following the System International d'Unites Std.
+ typedef boost::chrono::stopwatch_accumulator< boost::chrono::system_clock > system_stopwatch_accumulator;
+#ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef boost::chrono::stopwatch_accumulator< boost::chrono::monotonic_clock > monotonic_stopwatch_accumulator;
+#endif
+ typedef boost::chrono::stopwatch_accumulator< boost::chrono::high_resolution_clock > high_resolution_stopwatch_accumulator;
- class run_timer : public process_timer {
- public:
- explicit run_timer( system::error_code & ec = system::throws );
- explicit run_timer( std::ostream & os,
- system::error_code & ec = system::throws );
+ typedef boost::chrono::stopwatch_accumulator< boost::chrono::process_real_cpu_clock > process_real_cpu_stopwatch_accumulator;
+ typedef boost::chrono::stopwatch_accumulator< boost::chrono::process_user_cpu_clock > process_user_cpu_stopwatch_accumulator;
+ typedef boost::chrono::stopwatch_accumulator< boost::chrono::process_system_cpu_clock > process_system_cpu_stopwatch_accumulator;
- explicit run_timer( const std::string & format,
- system::error_code & ec = system::throws );
- explicit run_timer( std::ostream & os, const std::string & format,
- system::error_code & ec = system::throws );
+[endsect]
+[endsect]
- explicit run_timer( const std::string & format, int places,
- system::error_code & ec = system::throws );
- explicit run_timer( std::ostream & os, const std::string & format, int places,
- system::error_code & ec = system::throws );
+[/==================================================]
+[section:stopwatch_scoped_hpp Header `<boost/chrono/stopwatch_scoped.hpp>`]
+[/==================================================]
- explicit run_timer( int places,
- system::error_code & ec = system::throws );
- explicit run_timer( std::ostream & os, int places,
- system::error_code & ec = system::throws );
+ namespace boost { namespace chrono {
+ template <class Clock> class stopwatch_runner;
+ template <class Clock> class stopwatch_suspender;
+ template <class Clock> class stopwatch_resumer;
+ }}
- explicit run_timer( int places, const std::string & format,
- system::error_code & ec = system::throws );
- explicit run_timer( std::ostream & os, int places, const std::string & format,
- system::error_code & ec = system::throws );
+Boost.Chrono provides some helper classes ensuring pairwised operations (start/stop, suspend/resume, resule/suspend).
- ~run_timer();
+[section Template Class `stopwatch_runner<>`]
- void start( system::error_code & ec = system::throws );
+This helper class ensures that the start/stop are pairwised. Start the associated accumulator at construction time, and stop it at destruction time.
- void report( system::error_code & ec = system::throws );
+ template <class Stopwatch> class stopwatch_runner {
+ public:
+ typedef Stopwatch stopwatch;
+ stopwatch_runner(stopwatch & a, system::error_code & ec = system::throws);
+ ~stopwatch_runner();
+ stopwatch_runner() = delete;
+ stopwatch_runner(const stopwatch_runner&) = delete;
+ stopwatch_runner& operator=(const stopwatch_runner&) = delete;
+ };
- void test_report( duration real_, duration user_, duration system_ );
- bool reported() const;
- static int default_places();
- };
+Usage
+ void f1()
+ {
+ static stopwatch_accumulator<> t;
+ stopwatch_runner<stopwatch_accumulator<> > _(t);
+ // ...
+ }
[endsect]
+[section Template Class `stopwatch_suspender<>`]
-[endsect]
+This helper class ensures that the suspend/resume are pairwised. Suspend the associated accumulator at construction time, and resume it at destruction time.
-[endsect]
+ template <class Stopwatch> class stopwatch_suspender {
+ public:
+ typedef Stopwatch stopwatch;
+ stopwatch_suspender(stopwatch & a, system::error_code & ec = system::throws);
+ ~stopwatch_suspender();
+ stopwatch_suspender() = delete;
+ stopwatch_suspender(const stopwatch_suspender&) = delete;
+ stopwatch_suspender& operator=(const stopwatch_suspender&) = delete;
+ }
-[endsect]
+Usage
+ void f1()
+ {
+ static stopwatch_accumulator<> t;
+ stopwatch_runner<stopwatch_accumulator<> > _(t);
+ // ...
-[/===============]
-[section Examples]
-[/===============]
+ // call to some function we don't want to measure
+ {
+ stopwatch_suspender<stopwatch_accumulator<> > _(t);
+ external_function();
+ }
+ }
-[/===============]
-[section SI-units]
-[/===============]
+[endsect]
-Type-safe "physics" code interoperating with boost::chrono::duration types and taking advantage of the boost::ratio infrastructure and design philosophy.
+[section Template Class `stopwatch_resumer<>`]
-length - mimics boost::chrono::duration except restricts representation to double.
-Uses boost::ratio facilities for length units conversions.
+This helper class ensures that the resume/suspend are pairwised. Resume the associated accumulator at construction time, and suspecd it at destruction time.
- template <class Ratio>
- class length {
- private:
- double len_;
+ template <class Stopwatch> class stopwatch_resumer {
public:
- typedef Ratio ratio;
- length() : len_(1) {}
- length(const double& len) : len_(len) {}
+ typedef Stopwatch stopwatch;
+ stopwatch_resumer(stopwatch & a, system::error_code & ec = system::throws);
+ ~stopwatch_resumer();
+ stopwatch_resumer() = delete;
+ stopwatch_resumer(const stopwatch_resumer&) = delete;
+ stopwatch_resumer& operator=(const stopwatch_resumer&) = delete;
+ }
- template <class R>
- length(const length<R>& d)
- : len_(d.count() * boost::ratio_divide<Ratio, R>::type::den /
- boost::ratio_divide<Ratio, R>::type::num) {}
+Usage
- double count() const {return len_;}
+ void f1()
+ {
+ static stopwatch_accumulator<> t;
+ stopwatch_runner<stopwatch_accumulator<> > _(t);
+ // ...
- length& operator+=(const length& d) {len_ += d.count(); return *this;}
- length& operator-=(const length& d) {len_ -= d.count(); return *this;}
+ // call to some function we don't want to measure
+ {
+ stopwatch_suspender<stopwatch_accumulator<> > _(t);
- length operator+() const {return *this;}
- length operator-() const {return length(-len_);}
+ {
+ stopwatch_resumer<stopwatch_accumulator<> > _(t);
- length& operator*=(double rhs) {len_ *= rhs; return *this;}
- length& operator/=(double rhs) {len_ /= rhs; return *this;}
- };
+ }
+ }
+ }
+[endsect]
-Sparse sampling of length units
+[endsect]
- typedef length<boost::ratio<1> > meter; // set meter as "unity"
- typedef length<boost::centi> centimeter; // 1/100 meter
- typedef length<boost::kilo> kilometer; // 1000 meters
- typedef length<boost::ratio<254, 10000> > inch; // 254/10000 meters
+[endsect]
+[section Stopwatch Reporters]
+[section `Formatter` Requirements]
-length takes ratio instead of two integral types so that definitions can be made like so:
+A Formatter outputs on a given ostream a formatted string combining informations from a Stopwatch and the format and the double precission.
- typedef length<boost::ratio_multiply<boost::ratio<12>, inch::ratio>::type> foot; // 12 inchs
- typedef length<boost::ratio_multiply<boost::ratio<5280>, foot::ratio>::type> mile; // 5280 feet
+A Stopwatch must meet the requirements in the following Table.
-Need a floating point definition of seconds
+In this table `F` denote Fromaters types, `S` is a Stopwatch and `s` is an instance of `S`, `f` is `const char *` , `p` is and int, and `os` is a `std::ostream`, ec is a system::error_code
- typedef boost::chrono::duration<double> seconds; // unity
+[table Stopwatch Requirements
+ [[expression] [return type] [operational semantics]]
+ [[`F::default_os()`] [std::otream&] [The output stream.]]
+ [[`F::default_places()`] [`std::size_t`] [The precission when displaying a double.]]
+ [[`F::default_format()`] [`const char*`] [The default format.]]
+ [[`F::show_time(s,f,p,os,ec)`] [`S::time_point`] [outputs on `os` a formatted string combining informations from the Stopwatch `s`, the format `f` and the double precission `p`.]]
+]
-Demo of (scientific) support for sub-nanosecond resolutions
- typedef boost::chrono::duration<double, boost::pico> picosecond; // 10^-12 seconds
- typedef boost::chrono::duration<double, boost::femto> femtosecond; // 10^-15 seconds
- typedef boost::chrono::duration<double, boost::atto> attosecond; // 10^-18 seconds
+Models of `Formatter`:
-A very brief proof-of-concept for SIUnits-like library. Hard-wired to floating point seconds and meters, but accepts other units.
+* [@boost_chrono/reference/stopwatch_formatters.html#boost_chrono.reference.stopwatch_formatters.stopwatch_formatter_hpp.template_class__basic_stopwatch_formatter___ `basic_stopwatch_formatter`]
+* [@boost_chrono.reference.stopwatch_formatters.stopwatch_accumulator_formatter_hpp.template_class__basic_stopwatch_accumulator_formatter___ `basic_stopwatch_accumulator_formatter`]
+* [@boost_chrono.reference.stopwatch_formatters.t24_hours_formatter_hpp.template_class__basic_24_hours_formatter___ `basic_24_hours_formatter`]
- template <class R1, class R2>
- class quantity
- {
- double q_;
- public:
- typedef R1 time_dim;
- typedef R2 distance_dim;
- quantity() : q_(1) {}
+[endsect]
- double get() const {return q_;}
- void set(double q) {q_ = q;}
- };
+[section `Formatter` related traits]
- template <>
- class quantity<boost::ratio<1>, boost::ratio<0> >
- {
- double q_;
- public:
- quantity() : q_(1) {}
- quantity(seconds d) : q_(d.count()) {} // note: only User1::seconds needed here
+ template <class Stopwatch>
+ struct stopwatch_reporter_default_formatter {
+ typedef <see below> type;
+ };
- double get() const {return q_;}
- void set(double q) {q_ = q;}
- };
+The nested typedef `type` defines the default formatter used by the `stopwatch_reporter` class when the `Formatter` parameter is not explicit.
- template <>
- class quantity<boost::ratio<0>, boost::ratio<1> >
- {
- double q_;
- public:
- quantity() : q_(1) {}
- quantity(meter d) : q_(d.count()) {} // note: only User1::meter needed here
+[endsect]
- double get() const {return q_;}
- void set(double q) {q_ = q;}
- };
+[/==================================================]
+[section:stopwatch_reporter_hpp Header `<boost/chrono/stopwatch_reporter.hpp>`]
+[/==================================================]
- template <>
- class quantity<boost::ratio<0>, boost::ratio<0> >
- {
- double q_;
- public:
- quantity() : q_(1) {}
- quantity(double d) : q_(d) {}
+ namespace boost { namespace chrono {
+ template <class Stopwatch>
+ struct basic_stopwatch_reporter_default_formatter;
+ template <class Stopwatch>
+ struct stopwatch_reporter_default_formatter;
+ template <class Stopwatch>
+ struct wstopwatch_reporter_default_formatter;
- double get() const {return q_;}
- void set(double q) {q_ = q;}
- };
+ template <class Stopwatch, class Formatter=typename stopwatch_reporter_default_formatter<Stopwatch>::type>
+ class stopwatch_reporter;
+ }}
-Example of SI-Units
+[section Template Class `basic_stopwatch_reporter<>`]
- typedef quantity<boost::ratio<0>, boost::ratio<0> > Scalar;
- typedef quantity<boost::ratio<1>, boost::ratio<0> > Time; // second
- typedef quantity<boost::ratio<0>, boost::ratio<1> > Distance; // meter
- typedef quantity<boost::ratio<-1>, boost::ratio<1> > Speed; // meter/second
- typedef quantity<boost::ratio<-2>, boost::ratio<1> > Acceleration; // meter/second^2
+class `basic_stopwatch_reporter` provides a everything a `Stopwatch` provides and it adds reporting capabilities that can be invoked in a single line of code. The reporting is controleed by two parameters:
-Quantity arithmetics
+* format : The output format
+* places(precission): the number of decimal placess used.
- template <class R1, class R2, class R3, class R4>
- quantity<typename boost::ratio_subtract<R1, R3>::type, typename boost::ratio_subtract<R2, R4>::type>
- operator/(const quantity<R1, R2>& x, const quantity<R3, R4>& y)
- {
- typedef quantity<typename boost::ratio_subtract<R1, R3>::type,
- typename boost::ratio_subtract<R2, R4>::type> R;
- R r;
- r.set(x.get() / y.get());
- return r;
- }
+The default places is given by Formatter::default_places().
- template <class R1, class R2, class R3, class R4>
- quantity<typename boost::ratio_add<R1, R3>::type, typename boost::ratio_add<R2, R4>::type>
- operator*(const quantity<R1, R2>& x, const quantity<R3, R4>& y)
- {
- typedef quantity<typename boost::ratio_add<R1, R3>::type,
- typename boost::ratio_add<R2, R4>::type> R;
- R r;
- r.set(x.get() * y.get());
- return r;
- }
+The default format is given by Formatter::default_format().
- template <class R1, class R2>
- quantity<R1, R2>
- operator+(const quantity<R1, R2>& x, const quantity<R1, R2>& y)
- {
- typedef quantity<R1, R2> R;
- R r;
- r.set(x.get() + y.get());
- return r;
- }
+ template <class Stopwatch, class Formatter>
+ class basic_stopwatch_reporter : public Stopwatch {
+ public:
+ typedef typename Stopwatch::clock clock;
+ typedef Stopwatch stopwatch;
+ typedef Formatter formatter;
- template <class R1, class R2>
- quantity<R1, R2>
- operator-(const quantity<R1, R2>& x, const quantity<R1, R2>& y)
- {
- typedef quantity<R1, R2> R;
- R r;
- r.set(x.get() - y.get());
- return r;
- }
+ explicit basic_stopwatch_reporter( system::error_code & ec = system::throws );
+ explicit basic_stopwatch_reporter( std::ostream & os,
+ system::error_code & ec = system::throws );
-Example type-safe physics function
+ explicit basic_stopwatch_reporter( const std::string & format,
+ system::error_code & ec = system::throws );
+ explicit basic_stopwatch_reporter( std::ostream & os, const std::string & format,
+ system::error_code & ec = system::throws );
- Distance
- compute_distance(Speed v0, Time t, Acceleration a)
+ explicit basic_stopwatch_reporter( const std::string & format, int places,
+ system::error_code & ec = system::throws );
+ explicit basic_stopwatch_reporter( std::ostream & os, const std::string & format, int places,
+ system::error_code & ec = system::throws );
+
+ explicit basic_stopwatch_reporter( int places,
+ system::error_code & ec = system::throws );
+ explicit basic_stopwatch_reporter( std::ostream & os, int places,
+ system::error_code & ec = system::throws );
+
+ explicit basic_stopwatch_reporter( int places, const std::string & format,
+ system::error_code & ec = system::throws );
+ explicit basic_stopwatch_reporter( std::ostream & os, int places, const std::string & format,
+ system::error_code & ec = system::throws );
+
+ ~basic_stopwatch_reporter();
+
+ void report( system::error_code & ec = system::throws );
+ bool reported() const;
+
+
+ typedef stopwatch_runner<basic_stopwatch_reporter<Stopwatch> > scoped_run;
+ typedef stopwatch_suspender<basic_stopwatch_reporter<Stopwatch> > scoped_suspend;
+ typedef stopwatch_resumer<basic_stopwatch_reporter<Stopwatch> > scoped_resume;
+ };
+
+[endsect]
+
+[section Template Class `stopwatch_reporter<>`]
+
+class `stopwatch_reporter` provides a everything a `Stopwatch` provides and it adds reporting capabilities that can be invoked in a single line of code. The reporting is controleed by two parameters:
+
+* format : The output format
+* places(precission): the number of decimal placess used.
+
+The default places is given by Formatter::default_places().
+
+The default format is given by Formatter::default_format().
+
+ template <class Stopwatch, class Formatter>
+ class stopwatch_reporter : public basic_stopwatch_reporter<Stopwatch,Formatter> {
+ public:
+ typedef typename Stopwatch::clock clock;
+ typedef Stopwatch stopwatch;
+ typedef Formatter formatter;
+
+ explicit stopwatch_reporter( system::error_code & ec = system::throws );
+ explicit stopwatch_reporter( std::ostream & os,
+ system::error_code & ec = system::throws );
+
+ explicit stopwatch_reporter( const std::string & format,
+ system::error_code & ec = system::throws );
+ explicit stopwatch_reporter( std::ostream & os, const std::string & format,
+ system::error_code & ec = system::throws );
+
+ explicit stopwatch_reporter( const std::string & format, int places,
+ system::error_code & ec = system::throws );
+ explicit stopwatch_reporter( std::ostream & os, const std::string & format, int places,
+ system::error_code & ec = system::throws );
+
+ explicit stopwatch_reporter( int places,
+ system::error_code & ec = system::throws );
+ explicit stopwatch_reporter( std::ostream & os, int places,
+ system::error_code & ec = system::throws );
+
+ explicit stopwatch_reporter( int places, const std::string & format,
+ system::error_code & ec = system::throws );
+ explicit stopwatch_reporter( std::ostream & os, int places, const std::string & format,
+ system::error_code & ec = system::throws );
+
+ ~stopwatch_reporter();
+
+ void report( system::error_code & ec = system::throws );
+ bool reported() const;
+
+
+ typedef stopwatch_runner<stopwatch_reporter<Stopwatch> > scoped_run;
+ typedef stopwatch_suspender<stopwatch_reporter<Stopwatch> > scoped_suspend;
+ typedef stopwatch_resumer<stopwatch_reporter<Stopwatch> > scoped_resume;
+ };
+
+Usage
+
+ void f1()
{
- return v0 * t + Scalar(.5) * a * t * t; // if a units mistake is made here it won't compile
+ typedef stopwatch_reporter<stopwatch_accumulator<> > accumulator;
+ static accumulator t;
+ accumulator::scoped_run _(t);
+ // ...
+
+ // call to some function we don't want to measure
+ {
+ accumulator::scoped_suspend _(t);
+ external_function();
+ }
}
+[endsect]
-Exercise example type-safe physics function and show interoperation
-of custom time durations (User1::seconds) and standard time durations (boost::hours).
-Though input can be arbitrary (but type-safe) units, output is always in SI-units
-(a limitation of the simplified Units lib demoed here).
+[section Template Class `wstopwatch_reporter<>`]
- int main()
- {
- typedef boost::ratio<8, BOOST_INTMAX_C(0x7FFFFFFFD)> R1;
- typedef boost::ratio<3, BOOST_INTMAX_C(0x7FFFFFFFD)> R2;
- typedef User1::quantity<boost::ratio_subtract<boost::ratio<0>, boost::ratio<1> >::type,
- boost::ratio_subtract<boost::ratio<1>, boost::ratio<0> >::type > RR;
- typedef boost::ratio_subtract<R1, R2>::type RS;
- std::cout << RS::num << '/' << RS::den << '\n';
+class `wstopwatch_reporter` provides a everything a `Stopwatch` provides and it adds reporting capabilities that can be invoked in a single line of code. The reporting is controleed by two parameters:
+* format : The output format
+* places(precission): the number of decimal placess used.
- std::cout << "*************\n";
- std::cout << "* testUser1 *\n";
- std::cout << "*************\n";
- User1::Distance d( User1::mile(110) );
- User1::Time t( boost::chrono::hours(2) );
+The default places is given by Formatter::default_places().
- RR r=d / t;
- //r.set(d.get() / t.get());
+The default format is given by Formatter::default_format().
- User1::Speed rc= r;
+ template <class Stopwatch, class Formatter>
+ class wstopwatch_reporter : public basic_wstopwatch_reporter<Stopwatch,Formatter> {
+ public:
+ typedef typename Stopwatch::clock clock;
+ typedef Stopwatch stopwatch;
+ typedef Formatter formatter;
- User1::Speed s = d / t;
- std::cout << "Speed = " << s.get() << " meters/sec\n";
- User1::Acceleration a = User1::Distance( User1::foot(32.2) ) / User1::Time() / User1::Time();
- std::cout << "Acceleration = " << a.get() << " meters/sec^2\n";
- User1::Distance df = compute_distance(s, User1::Time( User1::seconds(0.5) ), a);
- std::cout << "Distance = " << df.get() << " meters\n";
- std::cout << "There are " << User1::mile::ratio::den << '/' << User1::mile::ratio::num << " miles/meter";
- User1::meter mt = 1;
- User1::mile mi = mt;
- std::cout << " which is approximately " << mi.count() << '\n';
- std::cout << "There are " << User1::mile::ratio::num << '/' << User1::mile::ratio::den << " meters/mile";
- mi = 1;
- mt = mi;
- std::cout << " which is approximately " << mt.count() << '\n';
- User1::attosecond as(1);
- User1::seconds sec = as;
- std::cout << "1 attosecond is " << sec.count() << " seconds\n";
- std::cout << "sec = as; // compiles\n";
- sec = User1::seconds(1);
- as = sec;
- std::cout << "1 second is " << as.count() << " attoseconds\n";
- std::cout << "as = sec; // compiles\n";
- std::cout << "\n";
- return 0;
+ explicit wstopwatch_reporter( system::error_code & ec = system::throws );
+ explicit wstopwatch_reporter( std::ostream & os,
+ system::error_code & ec = system::throws );
+
+ explicit wstopwatch_reporter( const std::string & format,
+ system::error_code & ec = system::throws );
+ explicit wstopwatch_reporter( std::ostream & os, const std::string & format,
+ system::error_code & ec = system::throws );
+
+ explicit wstopwatch_reporter( const std::string & format, int places,
+ system::error_code & ec = system::throws );
+ explicit wstopwatch_reporter( std::ostream & os, const std::string & format, int places,
+ system::error_code & ec = system::throws );
+
+ explicit wstopwatch_reporter( int places,
+ system::error_code & ec = system::throws );
+ explicit wstopwatch_reporter( std::ostream & os, int places,
+ system::error_code & ec = system::throws );
+
+ explicit wstopwatch_reporter( int places, const std::string & format,
+ system::error_code & ec = system::throws );
+ explicit wstopwatch_reporter( std::ostream & os, int places, const std::string & format,
+ system::error_code & ec = system::throws );
+
+ ~wstopwatch_reporter();
+
+ void report( system::error_code & ec = system::throws );
+ bool reported() const;
+
+
+ typedef stopwatch_runner<wstopwatch_reporter<Stopwatch> > scoped_run;
+ typedef stopwatch_suspender<wstopwatch_reporter<Stopwatch> > scoped_suspend;
+ typedef stopwatch_resumer<wstopwatch_reporter<Stopwatch> > scoped_resume;
+ };
+
+Usage
+
+ void f1()
+ {
+ typedef wstopwatch_reporter<stopwatch_accumulator<> > accumulator;
+ static accumulator t;
+ accumulator::scoped_run _(t);
+ // ...
+
+ // call to some function we don't want to measure
+ {
+ accumulator::scoped_suspend _(t);
+ external_function();
+ }
}
-[/ratio_test_cpp]
+[endsect]
+
+[endsect]
+
+[/==================================================]
+[section:stopclock_hpp Header `<boost/chrono/stopclock.hpp>`]
+[/==================================================]
+
+ namespace boost { namespace chrono {
+ template < class Clock, class Formatter > class basic_stopclock;
+ template < class Clock, class Formatter > class stopclock;
+ template < class Clock, class Formatter > class wstopclock;
+
+ typedef <see above> system_stopclock;
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef <see above> monotonic_stopclock;
+ #endif
+ typedef <see above> high_resolution_stopclock;
+ typedef <see above> process_real_cpu_stopclock;
+ typedef <see above> process_user_cpu_stopclock;
+ typedef <see above> process_system_cpu_stopclock;
+
+ typedef <see above> system_wstopclock;
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef <see above> monotonic_wstopclock;
+ #endif
+ typedef <see above> high_resolution_wstopclock;
+ typedef <see above> process_real_cpu_wstopclock;
+ typedef <see above> process_user_cpu_wstopclock;
+ typedef <see above> process_system_cpu_wstopclock;
+ }}
+
+[section Template Class `basic_stopclock<>`]
+
+`basic_stopclock<Clock>` template class is a shortcut of `basic_stopwatch_reporter<stopwatch<Clock>>`
+
+ template< class Clock, class Formatter>
+ class basic_stopclock : public basic_stopwatch_reporter<stopwatch<Clock>, Formatter> {
+ public:
+ typedef Clock clock;
+ typedef stopwatch<Clock> stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit basic_stopclock( system::error_code & ec = system::throws );
+ explicit basic_stopclock( ostream_type & os,
+ system::error_code & ec = system::throws );
+ explicit basic_stopclock( const string_type & format,
+ system::error_code & ec = system::throws );
+ explicit basic_stopclock( int places,
+ system::error_code & ec = system::throws );
+
+ basic_stopclock( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws );
+ basic_stopclock( const string_type & format, int places,
+ system::error_code & ec = system::throws );
+ basic_stopclock( ostream_type & os, int places,
+ system::error_code & ec = system::throws );
+ basic_stopclock( int places, const string_type & format,
+ system::error_code & ec = system::throws );
+
+ basic_stopclock( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws );
+ basic_stopclock( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws );
+
+
+ typedef typename base_type::scoped_run scoped_run;
+ typedef typename base_type::scoped_suspend scoped_suspend;
+ typedef typename base_type::scoped_resume scoped_resume;
+ };
+
+[endsect]
+
+[section Template Class `stopclock<>`]
+
+`stopclock<Clock>` template class is a shortcut of `stopwatch_reporter<stopwatch<Clock>>` with a specific default formatter.
+
+ template
+ < class Clock=process_cpu_clock
+ , class Formatter=typename stopwatch_reporter_default_formatter<stopwatch<Clock>>::type
+ > class stopclock : public basic_stopclock<Clock, Formatter> {
+ public:
+ typedef Clock clock;
+ typedef stopwatch<Clock> stopwatch;
+ typedef Formatter formatter;
+ 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 );
+ explicit stopclock( ostream_type & os,
+ system::error_code & ec = system::throws );
+ explicit stopclock( const string_type & format,
+ system::error_code & ec = system::throws );
+ explicit stopclock( int places,
+ system::error_code & ec = system::throws );
+
+ stopclock( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws );
+ stopclock( const string_type & format, int places,
+ system::error_code & ec = system::throws );
+ stopclock( ostream_type & os, int places,
+ system::error_code & ec = system::throws );
+ stopclock( int places, const string_type & format,
+ system::error_code & ec = system::throws );
+
+ stopclock( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws );
+ stopclock( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws );
+
+
+ typedef typename base_type::scoped_run scoped_run;
+ typedef typename base_type::scoped_suspend scoped_suspend;
+ typedef typename base_type::scoped_resume scoped_resume;
+ };
+
+[endsect]
+[section `stopclock` useful typedefs]
+
+ typedef boost::chrono::stopclock< boost::chrono::system_clock > system_stopwatch_stopclock;
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef boost::chrono::stopclock< boost::chrono::monotonic_clock > monotonic_stopwatch_stopclock;
+ #endif
+ typedef boost::chrono::stopclock< boost::chrono::high_resolution_clock > high_resolution_stopclock;
+ typedef boost::chrono::stopclock< boost::chrono::process_real_cpu_clock > process_real_cpu_stopclock;
+ typedef boost::chrono::stopclock< boost::chrono::process_user_cpu_clock > process_user_cpu_stopclock;
+ typedef boost::chrono::stopclock< boost::chrono::process_system_cpu_clock > process_system_cpu_stopclock;
+
+[endsect]
+
+[section Template Class `wstopclock<>`]
+
+`wstopclock<Clock>` template class is a shortcut of `stopwatch_reporter<stopwatch<Clock>>` with a specific default formatter.
+
+ template
+ < class Clock=process_cpu_clock
+ , class Formatter=typename stopwatch_reporter_default_formatter<stopwatch<Clock>>::type
+ > class wstopclock : public basic_wstopclock<Clock, Formatter> {
+ public:
+ typedef Clock clock;
+ typedef stopwatch<Clock> stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit wstopclock( system::error_code & ec = system::throws );
+ explicit wstopclock( ostream_type & os,
+ system::error_code & ec = system::throws );
+ explicit wstopclock( const string_type & format,
+ system::error_code & ec = system::throws );
+ explicit wstopclock( int places,
+ system::error_code & ec = system::throws );
+
+ wstopclock( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws );
+ wstopclock( const string_type & format, int places,
+ system::error_code & ec = system::throws );
+ wstopclock( ostream_type & os, int places,
+ system::error_code & ec = system::throws );
+ wstopclock( int places, const string_type & format,
+ system::error_code & ec = system::throws );
+
+ wstopclock( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws );
+ wstopclock( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws );
+
+
+ typedef typename base_type::scoped_run scoped_run;
+ typedef typename base_type::scoped_suspend scoped_suspend;
+ typedef typename base_type::scoped_resume scoped_resume;
+ };
+
+[endsect]
+[section `wstopclock` useful typedefs]
+
+ typedef boost::chrono::wstopclock< boost::chrono::system_clock > system_stopwatch_wstopclock;
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef boost::chrono::wstopclock< boost::chrono::monotonic_clock > monotonic_stopwatch_wstopclock;
+ #endif
+ typedef boost::chrono::wstopclock< boost::chrono::high_resolution_clock > high_resolution_wstopclock;
+ typedef boost::chrono::wstopclock< boost::chrono::process_real_cpu_clock > process_real_cpu_wstopclock;
+ typedef boost::chrono::wstopclock< boost::chrono::process_user_cpu_clock > process_user_cpu_wstopclock;
+ typedef boost::chrono::wstopclock< boost::chrono::process_system_cpu_clock > process_system_cpu_wstopclock;
+
+[endsect]
+
+
+[endsect]
+
+[/==================================================]
+[section:stopclock_accumulator_hpp Header `<boost/chrono/stopclock_accumulator.hpp>`]
+[/==================================================]
+
+ namespace boost { namespace chrono {
+ template < class Clock, class Formatter >
+ class basic_stopclock_accumulator;
+ template < class Clock, class Formatter >
+ class stopclock_accumulator;
+ template < class Clock, class Formatter >
+ class wstopclock_accumulator;
+
+ typedef <see above> system_stopclock_accumulator;
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef <see above> monotonic_stopclock_accumulator;
+ #endif
+ typedef <see above> high_resolution_stopclock_accumulator;
+ typedef <see above> process_real_cpu_stopclock_accumulator;
+ typedef <see above> process_user_cpu_stopclock_accumulator;
+ typedef <see above> process_system_cpu_stopclock_accumulator;
+
+ typedef <see above> system_wstopclock_accumulator;
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef <see above> monotonic_wstopclock_accumulator;
+ #endif
+ typedef <see above> high_resolution_wstopclock_accumulator;
+ typedef <see above> process_real_cpu_wstopclock_accumulator;
+ typedef <see above> process_user_cpu_wstopclock_accumulator;
+ typedef <see above> process_system_cpu_wstopclock_accumulator;
+ }}
+
+[section Template Class `basic_stopclock_accumulator<>`]
+
+`basic_stopclock_accumulator<Clock>` template class is a shortcut of `stopwatch_reporter<stopwatch<Clock>>`
+
+ template
+ < class Clock=high_resolution_clock
+ , class Formatter=typename stopwatch_reporter_default_formatter<stopwatch_accumulator<Clock>>::type
+ > class basic_stopclock_accumulator
+ : public basic_stopwatch_reporter<stopwatch_accumulator<Clock>, Formatter> {
+ public:
+ typedef Clock clock;
+ typedef stopwatch_accumulator<Clock> stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit basic_stopclock_accumulator( system::error_code & ec = system::throws );
+ explicit basic_stopclock_accumulator( ostream_type & os,
+ system::error_code & ec = system::throws );
+ explicit basic_stopclock_accumulator( const string_type & format,
+ system::error_code & ec = system::throws );
+ explicit basic_stopclock_accumulator( int places,
+ system::error_code & ec = system::throws );
+
+ basic_stopclock_accumulator( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws );
+ basic_stopclock_accumulator( const string_type & format, int places,
+ system::error_code & ec = system::throws );
+ basic_stopclock_accumulator( ostream_type & os, int places,
+ system::error_code & ec = system::throws );
+ basic_stopclock_accumulator( int places, const string_type & format,
+ system::error_code & ec = system::throws );
+
+ basic_stopclock_accumulator( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws );
+ basic_stopclock_accumulator( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws );
+
+
+ typedef typename base_type::scoped_run scoped_run;
+ typedef typename base_type::scoped_suspend scoped_suspend;
+ typedef typename base_type::scoped_resume scoped_resume;
+ };
+
+[endsect]
+
+[section Template Class `stopclock_accumulator<>`]
+
+`stopclock_accumulator<Clock>` template class is a shortcut of `stopwatch_reporter<stopwatch<Clock>>` with a specific formatter.
+
+ template
+ < class Clock=high_resolution_clock
+ , class Formatter=typename stopwatch_reporter_default_formatter<stopwatch_accumulator<Clock>>::type
+ > class stopclock_accumulator
+ : public basic_stopclock_accumulator<Clock, Formatter> {
+ public:
+ typedef Clock clock;
+ typedef stopwatch_accumulator<Clock> stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
+
+ explicit stopclock_accumulator( system::error_code & ec = system::throws );
+ explicit stopclock_accumulator( ostream_type & os,
+ system::error_code & ec = system::throws );
+ explicit stopclock_accumulator( const string_type & format,
+ system::error_code & ec = system::throws );
+ explicit stopclock_accumulator( int places,
+ system::error_code & ec = system::throws );
+
+ stopclock_accumulator( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws );
+ stopclock_accumulator( const string_type & format, int places,
+ system::error_code & ec = system::throws );
+ stopclock_accumulator( ostream_type & os, int places,
+ system::error_code & ec = system::throws );
+ stopclock_accumulator( int places, const string_type & format,
+ system::error_code & ec = system::throws );
+
+ stopclock_accumulator( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws );
+ stopclock_accumulator( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws );
+
+
+ typedef typename base_type::scoped_run scoped_run;
+ typedef typename base_type::scoped_suspend scoped_suspend;
+ typedef typename base_type::scoped_resume scoped_resume;
+ };
[endsect]
+[section `stopclock_accumulator` useful typedefs]
-[/===============]
-[section How you override the duration's default constructor]
+ typedef boost::chrono::stopclock_accumulator< boost::chrono::system_clock > system_stopwatch_reporter;
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef boost::chrono::stopclock_accumulator< boost::chrono::monotonic_clock > monotonic_stopwatch_reporter;
+ #endif
+ typedef boost::chrono::stopclock_accumulator< boost::chrono::high_resolution_clock > high_resolution_stopclock_accumulator;
+ typedef boost::chrono::stopclock_accumulator< boost::chrono::process_real_cpu_clock > process_real_cpu_stopclock_accumulator;
+ typedef boost::chrono::stopclock_accumulator< boost::chrono::process_user_cpu_clock > process_user_cpu_stopclock_accumulator;
+ typedef boost::chrono::stopclock_accumulator< boost::chrono::process_system_cpu_clock > process_system_cpu_stopclock_accumulator;
-Next follows how you override the duration's default constructor to do anything you want (in this case zero). All we need to do is to change the representation
+[endsect]
+[section Template Class `wstopclock_accumulator<>`]
- namespace I_dont_like_the_default_duration_behavior {
+`wstopclock_accumulator<Clock>` template class is a shortcut of `stopwatch_reporter<stopwatch<Clock>>` with a specific formatter.
- template <class R>
- class zero_default
- {
+ template
+ < class Clock=high_resolution_clock
+ , class Formatter=typename stopwatch_reporter_default_formatter<stopwatch_accumulator<Clock>>::type
+ > class wstopclock_accumulator
+ : public basic_wstopclock_accumulator<Clock, Formatter> {
public:
- typedef R rep;
+ typedef Clock clock;
+ typedef stopwatch_accumulator<Clock> stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
- private:
- rep rep_;
- public:
- zero_default(rep i = 0) : rep_(i) {}
- operator rep() const {return rep_;}
+ explicit wstopclock_accumulator( system::error_code & ec = system::throws );
+ explicit wstopclock_accumulator( ostream_type & os,
+ system::error_code & ec = system::throws );
+ explicit wstopclock_accumulator( const string_type & format,
+ system::error_code & ec = system::throws );
+ explicit wstopclock_accumulator( int places,
+ system::error_code & ec = system::throws );
- zero_default& operator+=(zero_default x) {rep_ += x.rep_; return *this;}
- zero_default& operator-=(zero_default x) {rep_ -= x.rep_; return *this;}
- zero_default& operator*=(zero_default x) {rep_ *= x.rep_; return *this;}
- zero_default& operator/=(zero_default x) {rep_ /= x.rep_; return *this;}
+ wstopclock_accumulator( ostream_type & os, const string_type & format,
+ system::error_code & ec = system::throws );
+ wstopclock_accumulator( const string_type & format, int places,
+ system::error_code & ec = system::throws );
+ wstopclock_accumulator( ostream_type & os, int places,
+ system::error_code & ec = system::throws );
+ wstopclock_accumulator( int places, const string_type & format,
+ system::error_code & ec = system::throws );
- zero_default operator+ () const {return *this;}
- zero_default operator- () const {return zero_default(-rep_);}
- zero_default& operator++() {++rep_; return *this;}
- zero_default operator++(int) {return zero_default(rep_++);}
- zero_default& operator--() {--rep_; return *this;}
- zero_default operator--(int) {return zero_default(rep_--);}
+ wstopclock_accumulator( ostream_type & os, const string_type & format, int places,
+ system::error_code & ec = system::throws );
+ wstopclock_accumulator( ostream_type & os, int places, const string_type & format,
+ system::error_code & ec = system::throws );
- friend zero_default operator+(zero_default x, zero_default y) {return x += y;}
- friend zero_default operator-(zero_default x, zero_default y) {return x -= y;}
- friend zero_default operator*(zero_default x, zero_default y) {return x *= y;}
- friend zero_default operator/(zero_default x, zero_default y) {return x /= y;}
- friend bool operator==(zero_default x, zero_default y) {return x.rep_ == y.rep_;}
- friend bool operator!=(zero_default x, zero_default y) {return !(x == y);}
- friend bool operator< (zero_default x, zero_default y) {return x.rep_ < y.rep_;}
- friend bool operator<=(zero_default x, zero_default y) {return !(y < x);}
- friend bool operator> (zero_default x, zero_default y) {return y < x;}
- friend bool operator>=(zero_default x, zero_default y) {return !(x < y);}
+ typedef typename base_type::scoped_run scoped_run;
+ typedef typename base_type::scoped_suspend scoped_suspend;
+ typedef typename base_type::scoped_resume scoped_resume;
};
- typedef boost::chrono::duration<zero_default<long long>, boost::nano > nanoseconds;
- typedef boost::chrono::duration<zero_default<long long>, boost::micro > microseconds;
- typedef boost::chrono::duration<zero_default<long long>, boost::milli > milliseconds;
- typedef boost::chrono::duration<zero_default<long long> > seconds;
- typedef boost::chrono::duration<zero_default<long long>, boost::ratio<60> > minutes;
- typedef boost::chrono::duration<zero_default<long long>, boost::ratio<3600> > hours;
- }
-
-Usage
-
- using namespace I_dont_like_the_default_duration_behavior;
-
- milliseconds ms;
- std::cout << ms.count() << '\n';
+[endsect]
+[section `wstopclock_accumulator` useful typedefs]
-['See the file i_dont_like_the_default_duration_behavior.cpp]
+ typedef boost::chrono::wstopclock_accumulator< boost::chrono::system_clock > system_stopwatch_reporter;
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef boost::chrono::wstopclock_accumulator< boost::chrono::monotonic_clock > monotonic_stopwatch_reporter;
+ #endif
+ typedef boost::chrono::wstopclock_accumulator< boost::chrono::high_resolution_clock > high_resolution_wstopclock_accumulator;
+ typedef boost::chrono::wstopclock_accumulator< boost::chrono::process_real_cpu_clock > process_real_cpu_wstopclock_accumulator;
+ typedef boost::chrono::wstopclock_accumulator< boost::chrono::process_user_cpu_clock > process_user_cpu_wstopclock_accumulator;
+ typedef boost::chrono::wstopclock_accumulator< boost::chrono::process_system_cpu_clock > process_system_cpu_wstopclock_accumulator;
[endsect]
+[endsect]
-[/==================]
-[section min utility]
+[/==================================================]
+[section:scoped_stopclock_hpp Header `<boost/chrono/scoped_stopclock.hpp>`]
+[/==================================================]
-Returns the earliest time_point.
+ namespace boost { namespace chrono {
+ template < class Clock, class Formatter > class scoped_stopclock;
+ }}
- template <class Clock, class Duration1, class Duration2>
- typename boost::common_type<time_point<Clock, Duration1>,
- time_point<Clock, Duration2> >::type
- min(time_point<Clock, Duration1> t1, time_point<Clock, Duration2> t2)
- {
- return t2 < t1 ? t2 : t1;
- }
+[section Template Class `scoped_stopclock<>`]
-Being able to *easily* write this function is a major feature!
+`scoped_stopclock<>`is like a `stopclock<>` but that in addition will output a scoped trace. At construction time it will output
- typedef time_point<system_clock,
- boost::common_type<system_clock::duration, seconds>::type> T1;
- typedef time_point<system_clock,
- boost::common_type<system_clock::duration, nanoseconds>::type> T2;
- typedef boost::common_type<T1, T2>::type T3;
- /*auto*/ T1 t1 = system_clock::now() + seconds(3);
- /*auto*/ T2 t2 = system_clock::now() + nanoseconds(3);
- /*auto*/ T3 t3 = min(t1, t2);
+ {{{ <string>
+and at destruction time
-[endsect]
+ }}} <string> <output of stopwatch_reporter>
-[/==================]
-[section Cycle count]
+A typical ussage of this class is
- #include <boost/chrono/chrono.hpp>
- #include <boost/type_traits.hpp>
+ int f1(long j)
+ {
+ scoped_stopclock<> _(BOOST_CURRENT_FUNCTION);
- #include <iostream>
+ for ( long i = 0; i < j; ++i )
+ std::sqrt( 123.456L ); // burn some time
- using namespace boost::chrono;
+ return 0;
+ }
+ template < class Clock=process_cpu_clock
+ , class Formatter=typename stopwatch_reporter_default_formatter<stopwatch<Clock>>::type
+ > class scoped_stopclock
+ : public stopwatch_reporter<stopwatch<Clock>, Formatter> {
+ public:
+ typedef Clock clock;
+ typedef Stopwatch stopwatch;
+ typedef Formatter formatter;
+ typedef typename Formatter::string_type string_type;
+ typedef typename Formatter::char_type char_type;
+ typedef typename Formatter::ostream_type ostream_type;
- template <long long speed>
- struct cycle_count
- {
- typedef typename boost::ratio_multiply<boost::ratio<speed>, boost::mega>::type frequency; // Mhz
- typedef typename boost::ratio_divide<boost::ratio<1>, frequency>::type period;
- typedef long long rep;
- typedef boost::chrono::duration<rep, period> duration;
- typedef boost::chrono::time_point<cycle_count> time_point;
+ explicit scoped_stopclock( const std::string& func,
+ system::error_code & ec = system::throws );
+ scoped_stopclock( const std::string& func, ostream_type & os,
+ system::error_code & ec = system::throws );
- static time_point now()
- {
- static long long tick = 0;
- // return exact cycle count
- return time_point(duration(++tick)); // fake access to clock cycle count
- }
- };
+ scoped_stopclock( const std::string& func, const string_type & format,
+ system::error_code & ec = system::throws );
- template <long long speed>
- struct approx_cycle_count
- {
- static const long long frequency = speed * 1000000; // MHz
- typedef nanoseconds duration;
- typedef duration::rep rep;
- typedef duration::period period;
- static const long long nanosec_per_sec = period::den;
- typedef boost::chrono::time_point<approx_cycle_count> time_point;
+ scoped_stopclock( const std::string& func, int places,
+ system::error_code & ec = system::throws );
- static time_point now()
- {
- static long long tick = 0;
- // return cycle count as an approximate number of nanoseconds
- // compute as if nanoseconds is only duration in the std::lib
- return time_point(duration(++tick * nanosec_per_sec / frequency));
- }
- };
+ scoped_stopclock( const std::string& func, ostream_type & os,
+ const string_type & format,
+ system::error_code & ec = system::throws );
+ scoped_stopclock( const std::string& func, const string_type & format,
+ int places, system::error_code & ec = system::throws );
-['See the file libs/chrono/example/cycle_count.cpp]
+ scoped_stopclock( const std::string& func, ostream_type & os, int places,
+ system::error_code & ec = system::throws );
-[endsect]
+ scoped_stopclock( const std::string& func, int places,
+ const string_type & format, system::error_code & ec = system::throws );
-[/==================]
-[section xtime conversions]
+ scoped_stopclock( const std::string& func, ostream_type & os,
+ const string_type & format, int places,
+ system::error_code & ec = system::throws );
-Example round_up utility: converts d to To, rounding up for inexact conversions
-Being able to *easily* write this function is a major feature!
+ scoped_stopclock( const std::string& func, ostream_type & os, int places,
+ const string_type & format, system::error_code & ec = system::throws );
- #include <boost/chrono/chrono.hpp>
- #include <boost/type_traits.hpp>
+ ~scoped_stopclock();
- #include <iostream>
+ typedef typename base_type::scoped_run scoped_run;
+ typedef typename base_type::scoped_suspend scoped_suspend;
+ typedef typename base_type::scoped_resume scoped_resume;
+ };
- using namespace boost::chrono;
+[endsect]
- template <class To, class Rep, class Period>
- To
- round_up(duration<Rep, Period> d)
- {
- To result = duration_cast<To>(d);
- if (result < d)
- ++result;
- return result;
- }
+[endsect]
+[endsect]
+[section Stopwatch Formatters]
-Demonstrate interaction with xtime-like facility:
+[/==================================================]
+[section:stopwatch_formatter_hpp Header `<boost/chrono/stopwatch_formatter.hpp>`]
+[/==================================================]
+ namespace boost { namespace chrono {
+ template <
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
+ class Alloc=std::allocator<CharT>
+ >
+ class basic_stopwatch_formatter;
- struct xtime
- {
- long sec;
- unsigned long usec;
- };
+ typedef basic_stopwatch_formatter<char> stopwatch_formatter;
+ typedef basic_stopwatch_formatter<wchar_t> wstopwatch_formatter;
+ }}
- template <class Rep, class Period>
- xtime
- to_xtime_truncate(duration<Rep, Period> d)
- {
- xtime xt;
- xt.sec = static_cast<long>(duration_cast<seconds>(d).count());
- xt.usec = static_cast<long>(duration_cast<microseconds>(d - seconds(xt.sec)).count());
- return xt;
- }
+[section Template Class `basic_stopwatch_formatter<>`]
- template <class Rep, class Period>
- xtime
- to_xtime_round_up(duration<Rep, Period> d)
- {
- xtime xt;
- xt.sec = static_cast<long>(duration_cast<seconds>(d).count());
- xt.usec = static_cast<unsigned long>(round_up<microseconds>(d - seconds(xt.sec)).count());
- return xt;
- }
+`stopwatch_formatter` is a model of `Formatter`.
- microseconds
- from_xtime(xtime xt)
- {
- return seconds(xt.sec) + microseconds(xt.usec);
- }
+ template <
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
+ class Alloc=std::allocator<CharT>
+ >
+ class basic_stopwatch_formatter {
+ 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 char_type * default_format();
+ static int default_places();
- void print(xtime xt)
- {
- std::cout << '{' << xt.sec << ',' << xt.usec << "}\n";
- }
+ template < class Stopwatch >
+ static void show_time( Stopwatch & stopwatch_, const char * format, int places, std::ostream & os, system::error_code & ec);
+ };
-Usage
+The default places is given by default_places and is 3.
- xtime xt = to_xtime_truncate(seconds(3) + milliseconds(251));
- print(xt);
- milliseconds ms = duration_cast<milliseconds>(from_xtime(xt));
- std::cout << ms.count() << " milliseconds\n";
- xt = to_xtime_round_up(ms);
- print(xt);
- xt = to_xtime_truncate(seconds(3) + nanoseconds(999));
- print(xt);
- xt = to_xtime_round_up(seconds(3) + nanoseconds(999));
- print(xt);
+The default format is "%ts\\n", where
+* `%d` : the result of elapsed() when the reporting is done.
-[/xtime_cpp]
+The time is given using the suffix "s" following the System International d'Unites Std.
[endsect]
+[endsect]
-[/==================]
-[section xtime_clock]
+[/==================================================]
+[section:stopwatch_accumulator_formatter_hpp Header `<boost/chrono/stopwatch_accumulator_formatter.hpp>`]
+[/==================================================]
-This example demonstrates the use of a timeval-like struct to be used as the representation
-type for both duraiton and time_point.
+ namespace boost { namespace chrono {
+ template <
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
+ class Alloc=std::allocator<CharT>
+ > basic_stopwatch_accumulator_formatter;
+ typedef basic_stopwatch_formatter<char> stopwatch_formatter;
+ typedef basic_stopwatch_formatter<wchar_t> wstopwatch_formatter;
+ }}
- class xtime {
- private:
- long tv_sec;
- long tv_usec;
+[section Template Class `basic_stopwatch_accumulator_formatter<>`]
- void fixup() {
- if (tv_usec < 0) {
- tv_usec += 1000000;
- --tv_sec;
- }
- }
+`stopwatch_accumulator_formatter` is a model of `Formatter`
+ template <
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
+ class Alloc=std::allocator<CharT>
+ class basic_stopwatch_accumulator_formatter {
public:
- explicit xtime(long sec, long usec) {
- tv_sec = sec;
- tv_usec = usec;
- if (tv_usec < 0 || tv_usec >= 1000000) {
- tv_sec += tv_usec / 1000000;
- tv_usec %= 1000000;
- fixup();
- }
- }
-
- explicit xtime(long long usec) {
- tv_usec = static_cast<long>(usec % 1000000);
- tv_sec = static_cast<long>(usec / 1000000);
- fixup();
- }
-
- // explicit
- operator long long() const {return static_cast<long long>(tv_sec) * 1000000 + tv_usec;}
+ 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 char_type * default_format();
+ static int default_places();
- xtime& operator += (xtime rhs) {
- tv_sec += rhs.tv_sec;
- tv_usec += rhs.tv_usec;
- if (tv_usec >= 1000000) {
- tv_usec -= 1000000;
- ++tv_sec;
- }
- return *this;
- }
+ template <class Stopwatch >
+ static void show_time( Stopwatch & stopwatch_, const char * format, int places, std::ostream & os, system::error_code & ec);
+ };
- xtime& operator -= (xtime rhs) {
- tv_sec -= rhs.tv_sec;
- tv_usec -= rhs.tv_usec;
- fixup();
- return *this;
- }
+The default places is given by default_places and is 3.
- xtime& operator %= (xtime rhs) {
- long long t = tv_sec * 1000000 + tv_usec;
- long long r = rhs.tv_sec * 1000000 + rhs.tv_usec;
- t %= r;
- tv_sec = static_cast<long>(t / 1000000);
- tv_usec = static_cast<long>(t % 1000000);
- fixup();
- return *this;
- }
+The default format is "%c times, sum=%ss, min=%ms, max=%Ms, mean=%as, frequency=%fHz, lifetime=%ls, percentage=%p\%\\n", where
- friend xtime operator+(xtime x, xtime y) {return x += y;}
- friend xtime operator-(xtime x, xtime y) {return x -= y;}
- friend xtime operator%(xtime x, xtime y) {return x %= y;}
+* `%c` : the counter of the number of times the pair srat/stop has been called.
+* `%s` : the sum of the samples of elapsed time between the call to start/stop.
+* `%m` : the min of the samples of elapsed time between the call to start/stop.
+* `%M` : the max of the samples of elapsed time between the call to start/stop.
+* `%a` : the mean of the samples of elapsed time between the call to start/stop.
+* `%f` : the frequency of calls to start.
+* `%l` : the lifetime of the stopwatch_accumulator.
+* `%p` : the percentage of time spent by this stopwatch respect to its lifetime.
- friend bool operator==(xtime x, xtime y)
- { return (x.tv_sec == y.tv_sec && x.tv_usec == y.tv_usec); }
+The time is given using the suffix "s", the frequency is given using the suffix "Hz", both following the System International d'Unites Std.
- friend bool operator<(xtime x, xtime y) {
- if (x.tv_sec == y.tv_sec)
- return (x.tv_usec < y.tv_usec);
- return (x.tv_sec < y.tv_sec);
- }
+[endsect]
- friend bool operator!=(xtime x, xtime y) { return !(x == y); }
- friend bool operator> (xtime x, xtime y) { return y < x; }
- friend bool operator<=(xtime x, xtime y) { return !(y < x); }
- friend bool operator>=(xtime x, xtime y) { return !(x < y); }
+[endsect]
- friend std::ostream& operator<<(std::ostream& os, xtime x)
- {return os << '{' << x.tv_sec << ',' << x.tv_usec << '}';}
- };
+[/==================================================================]
+[section:time_formatter_hpp Header `<boost/chrono/time_formatter.hpp>`]
+[/==================================================================]
-Clock based on timeval-like struct.
- class xtime_clock
- {
- public:
- typedef xtime rep;
- typedef boost::micro period;
- typedef boost::chrono::duration<rep, period> duration;
- typedef boost::chrono::time_point<xtime_clock> time_point;
+ namespace boost { namespace chrono {
- static time_point now()
- {
- #if defined(BOOST_CHRONO_WINDOWS_API)
- time_point t(duration(xtime(0)));
- gettimeofday((timeval*)&t, 0);
- return t;
+ template <
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
+ class Alloc=std::allocator<CharT>
+ >
+ class basic_time_formatter;
- #elif defined(BOOST_CHRONO_MAC_API)
+ typedef basic_time_formatter<char> time_formatter;
+ typedef basic_time_formatter<wchar_t> wtime_formatter;
- time_point t(duration(xtime(0)));
- gettimeofday((timeval*)&t, 0);
- return t;
+ template <>
+ struct stopwatch_reporter_default_formatter<stopwatch<process_cpu_clock> > {
+ typedef time_formatter type;
+ };
- #elif defined(BOOST_CHRONO_POSIX_API)
- //time_point t(0,0);
+ } }
- timespec ts;
- ::clock_gettime( CLOCK_REALTIME, &ts );
+[section Template Class `basic_time_formatter<>`]
- xtime xt( ts.tv_sec, ts.tv_nsec/1000);
- return time_point(duration(xt));
+ template <typename CharT, typename Traits, class Alloc>
+ class basic_time_formatter {
+ 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 char_type * default_format();
+ static int default_places();
- #endif // POSIX
- }
+ template <class Stopwatch >
+ static void show_time( Stopwatch & stopwatch_
+ , const char * format, int places, std::ostream & os
+ , system::error_code & ec);
};
-Usage of xtime_clock
+The default places is given by default_places and is 3.
- using namespace boost::chrono;
- std::cout << "sizeof xtime_clock::time_point = " << sizeof(xtime_clock::time_point) << '\n';
- std::cout << "sizeof xtime_clock::duration = " << sizeof(xtime_clock::duration) << '\n';
- std::cout << "sizeof xtime_clock::rep = " << sizeof(xtime_clock::rep) << '\n';
- xtime_clock::duration delay(milliseconds(5));
- xtime_clock::time_point start = xtime_clock::now();
- while (xtime_clock::now() - start <= delay) {}
- xtime_clock::time_point stop = xtime_clock::now();
- xtime_clock::duration elapsed = stop - start;
- std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
+The default format is "nreal %rs, cpu %cs (%p%), user %us, system %ss\\n", where
+
+* `%r` : real process clock
+* `%u` : user process clock
+* `%s` : system process clock
+* `%c` : user+system process clock
+* `%p` : percentage (user+system)/real process clock
+
+All the units are given using the suffix "s" following the System International d'Unites Std.
[endsect]
-[/=========================]
-[section runtime_resolution]
+[endsect]
-Handle duration with resolution not known until run time
+[/==================================================]
+[section:t24_hours_hpp Header `<boost/chrono/t24_hours.hpp>`]
+[/==================================================]
- class duration
- {
- public:
- typedef long long rep;
- private:
- rep rep_;
+ namespace boost { namespace chrono {
+ class t24_hours;
+ }}
- static const double ticks_per_nanosecond;
+[section Class `t24_hours`]
+ class t24_hours {
public:
- typedef boost::chrono::duration<double, boost::nano> tonanosec;
+ typedef boost::chrono::duration<boost::int_least32_t, ratio<24*3600> > days;
+ typedef boost::chrono::hours hours;
+ typedef boost::chrono::minutes minutes;
+ typedef boost::chrono::seconds seconds;
+ typedef boost::chrono::nanoseconds nanoseconds;
- duration() {} // = default;
- explicit duration(const rep& r) : rep_(r) {}
+ days days_;
+ hours hours_;
+ minutes minutes_;
+ seconds seconds_;
+ nanoseconds nanoseconds_;
- // conversions
- explicit duration(const tonanosec& d)
- : rep_(static_cast<rep>(d.count() * ticks_per_nanosecond)) {}
+ template <class Rep, class Period>
+ explicit t24_hours(const boost::chrono::duration<Rep, Period>& d);
+ };
- // explicit
- operator tonanosec() const {return tonanosec(rep_/ticks_per_nanosecond);}
+[endsect]
+[endsect]
- // observer
+[/==================================================================]
+[section:t24_hours_formatter_hpp Header `<boost/chrono/t24_hours_formatter.hpp>`]
+[/==================================================================]
- rep count() const {return rep_;}
- // arithmetic
+ namespace boost { namespace chrono {
- duration& operator+=(const duration& d) {rep_ += d.rep_; return *this;}
- duration& operator-=(const duration& d) {rep_ += d.rep_; return *this;}
- duration& operator*=(rep rhs) {rep_ *= rhs; return *this;}
- duration& operator/=(rep rhs) {rep_ /= rhs; return *this;}
+ template <
+ typename CharT=char,
+ typename Traits=std::char_traits<CharT>,
+ class Alloc=std::allocator<CharT>
+ >
+ class basic_24_hours_formatter;
- duration operator+() const {return *this;}
- duration operator-() const {return duration(-rep_);}
- duration& operator++() {++rep_; return *this;}
- duration operator++(int) {return duration(rep_++);}
- duration& operator--() {--rep_; return *this;}
- duration operator--(int) {return duration(rep_--);}
+ typedef basic_24_hours_formatter<char> t24_hours_formatter;
+ typedef basic_24_hours_formatter<wchar_t> wt24_hours_formatter;
- friend duration operator+(duration x, duration y) {return x += y;}
- friend duration operator-(duration x, duration y) {return x -= y;}
- friend duration operator*(duration x, rep y) {return x *= y;}
- friend duration operator*(rep x, duration y) {return y *= x;}
- friend duration operator/(duration x, rep y) {return x /= y;}
+ } }
- friend bool operator==(duration x, duration y) {return x.rep_ == y.rep_;}
- friend bool operator!=(duration x, duration y) {return !(x == y);}
- friend bool operator< (duration x, duration y) {return x.rep_ < y.rep_;}
- friend bool operator<=(duration x, duration y) {return !(y < x);}
- friend bool operator> (duration x, duration y) {return y < x;}
- friend bool operator>=(duration x, duration y) {return !(x < y);}
- };
+[section Template Class `basic_24_hours_formatter<>`]
+ template <typename CharT, typename Traits, class Alloc>
+ class basic_24_hours_formatter {
+ public:
+ static std::ostream & default_os();
+ static const char * default_format();
+ static int default_places();
-['See the file libs/chrono/example/runtime_resolution.cpp]
+ template <class Stopwatch >
+ static void show_time( Stopwatch & stopwatch_
+ , const char * format, int places, std::ostream & os
+ , system::error_code & ec);
+ };
-[endsect]
+The default places is given by default_places and is 3.
-[/=======================================================]
-[section Simulated thread interface demonstration program]
+The default format is "%d days(s) %h:%m:%s.%n\\n", where
-[/simulated_thread_interface_demo_cpp]
+* `%d` : days
+* `%h` : hours
+* `%m` : minutes
+* `%s` : seconds
+* `%n` : nanoseconds
-Free sleep functions
+[endsect]
- namespace boost { namespace this_thread {
+[endsect]
- template <class Rep, class Period>
- void sleep_for(const boost::chrono::duration<Rep, Period>& d) {
- boost::chrono::microseconds t = boost::chrono::duration_cast<boost::chrono::microseconds>(d);
- if (t < d)
- ++t;
- if (t > boost::chrono::microseconds(0))
- std::cout << "sleep_for " << t.count() << " microseconds\n";
- }
+[endsect]
+[section Deprecated Headers]
+[/==================================================]
+[section:timer_hpp Deprecated Header `<boost/chrono/timer.hpp>`]
+[/==================================================]
- template <class Clock, class Duration>
- void sleep_until(const boost::chrono::time_point<Clock, Duration>& t) {
- using namespace boost::chrono;
- typedef time_point<Clock, Duration> Time;
- typedef system_clock::time_point SysTime;
- if (t > Clock::now()) {
- typedef typename boost::common_type<typename Time::duration,
- typename SysTime::duration>::type D;
- /* auto */ D d = t - Clock::now();
- microseconds us = duration_cast<microseconds>(d);
- if (us < d)
- ++us;
- SysTime st = system_clock::now() + us;
- std::cout << "sleep_until ";
- detail::print_time(st);
- std::cout << " which is " << (st - system_clock::now()).count() << " microseconds away\n";
- }
- }
+This header has been deprecated, use instead <boost/chrono/stopwatch.hpp>.
+ namespace boost { namespace chrono {
+ template <class Clock=high_resolution_clock> class timer;
+ typedef <see above> system_timer;
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef <see above> monotonic_timer;
+ #endif
+ typedef <see above> high_resolution_timer;
}}
+[/
+ typedef <see above> process_real_cpu_timer;
+ typedef <see above> process_user_cpu_timer;
+ typedef <see above> process_system_cpu_timer;
+]
+[section Template Class `timer<>`]
-timed_mutex modified fuctions
+Knowing how long a part of a program takes to execute is useful in both test and production environments.
+A `timer` object measures elapsed time. It is recommended to use it with clocks that measure wall clock rather than CPU time since the intended use is performance measurement on systems where total elapsed time is more important than just process or CPU time.
- namespace boost {
- struct timed_mutex {
- // ...
+The maximum measurable elapsed time depends on the Clock parameter. The accuracy of timings depends on the
+accuracy of timing information provided the Clock, and this coudl varies a great deal from one clock to another.
- template <class Rep, class Period>
- bool try_lock_for(const boost::chrono::duration<Rep, Period>& d) {
- boost::chrono::microseconds t = boost::chrono::duration_cast<boost::chrono::microseconds>(d);
- if (t <= boost::chrono::microseconds(0))
- return try_lock();
- std::cout << "try_lock_for " << t.count() << " microseconds\n";
- return true;
- }
+ template <class Clock> class timer {
+ public:
+ typedef Clock clock;
+ typedef typename Clock::duration duration;
+ typedef typename Clock::time_point time_point;
- template <class Clock, class Duration>
- bool try_lock_until(const boost::chrono::time_point<Clock, Duration>& t)
- {
- using namespace boost::chrono;
- typedef time_point<Clock, Duration> Time;
- typedef system_clock::time_point SysTime;
- if (t <= Clock::now())
- return try_lock();
- typedef typename boost::common_type<typename Time::duration,
- typename Clock::duration>::type D;
- /* auto */ D d = t - Clock::now();
- microseconds us = duration_cast<microseconds>(d);
- SysTime st = system_clock::now() + us;
- std::cout << "try_lock_until ";
- detail::print_time(st);
- std::cout << " which is " << (st - system_clock::now()).count()
- << " microseconds away\n";
- return true;
- }
- };
- }
+ explicit timer( system::error_code & ec = system::throws );
-condition_variable modified fuctions
+ ~timer();
- namespace boost {
- struct condition_variable
- {
- // ...
+ void start( system::error_code & ec = system::throws );
+ duration elapsed( system::error_code & ec = system::throws );
- template <class Rep, class Period>
- bool wait_for(mutex&, const boost::chrono::duration<Rep, Period>& d) {
- boost::chrono::microseconds t = boost::chrono::duration_cast<boost::chrono::microseconds>(d);
- std::cout << "wait_for " << t.count() << " microseconds\n";
- return true;
- }
+ };
- template <class Clock, class Duration>
- bool wait_until(mutex&, const boost::chrono::time_point<Clock, Duration>& t) {
- using namespace boost::chrono;
- typedef time_point<Clock, Duration> Time;
- typedef system_clock::time_point SysTime;
- if (t <= Clock::now())
- return false;
- typedef typename boost::common_type<typename Time::duration,
- typename Clock::duration>::type D;
- /* auto */ D d = t - Clock::now();
- microseconds us = duration_cast<microseconds>(d);
- SysTime st = system_clock::now() + us;
- std::cout << "wait_until ";
- detail::print_time(st);
- std::cout << " which is " << (st - system_clock::now()).count()
- << " microseconds away\n";
- return true;
- }
- };
- }
+[endsect]
-Usage
+[section `timer` useful typedefs]
- boost::mutex m;
- boost::timed_mutex mut;
- boost::condition_variable cv;
+ typedef boost::chrono::timer< boost::chrono::system_clock > system_timer;
+ #ifdef BOOST_CHRONO_HAS_CLOCK_MONOTONIC
+ typedef boost::chrono::timer< boost::chrono::monotonic_clock > monotonic_timer;
+ #endif
+ typedef boost::chrono::timer< boost::chrono::high_resolution_clock > high_resolution_timer;
- using namespace boost;
- using namespace boost::chrono;
+[/
+ typedef boost::chrono::timer< boost::chrono::process_real_cpu_clock > process_real_cpu_timer;
+ typedef boost::chrono::timer< boost::chrono::process_user_cpu_clock > process_user_cpu_timer;
+ typedef boost::chrono::timer< boost::chrono::process_system_cpu_clock > process_system_cpu_timer;
+]
+[endsect]
+[endsect]
- this_thread::sleep_for(seconds(3));
- this_thread::sleep_for(nanoseconds(300));
- system_clock::time_point time_limit = system_clock::now() + seconds(4) + milliseconds(500);
- this_thread::sleep_until(time_limit);
- mut.try_lock_for(milliseconds(30));
- mut.try_lock_until(time_limit);
+[/==================================================================]
+[section:process_times_hpp Deprecated Header `<boost/chrono/process_times.hpp>`]
+[/==================================================================]
- cv.wait_for(m, minutes(1)); // real code would put this in a loop
- cv.wait_until(m, time_limit); // real code would put this in a loop
+This header has been deprecated. Use instead `<boost/chrono/process_cpu_clocks.hpp>`, `<boost/chrono/stopwatch.hpp>`, `<boost/chrono/stopwatch_reporter.hpp>` and `<boost/chrono/stopclock.hpp>` files.
- // For those who prefer floating point
- this_thread::sleep_for(duration<double>(0.25));
- this_thread::sleep_until(system_clock::now() + duration<double>(1.5));
+ namespace boost { namespace chrono {
+ class process_clock;
+ typedef <see below> process_times;
+ class process_timer;
+ class run_timer;
-[/See the file libs/chrono/example/simulated_thread_interface_demo.cpp]
+ } }
-[endsect]
+[section Class `process_clock`]
-[/================]
-[section Saturating]
+`process_clock` doesn't satisfy the Clock Requirements as the function now do not follows the Clock prototype.
-A "saturating" signed integral type is developed. This type has +/- infinity and a nan (like IEEE floating point) but otherwise obeys signed integral arithmetic. This class is subsequently used as the rep in boost::chrono::duration to demonstrate a duration class that does not silently ignore overflow.
+`process_clock` provides a thin wrapper around the operating system's process time API. For POSIX-like systems, that's the times() function, while for Windows, it's the GetProcessTimes() function.
-['See the file libs/chrono/example/satutating.cpp]
+The process relative real, user and system current time can be obtained at once by calling `process_clock::now()`.
-[endsect]
-[/======================================================]
-[section Howard Hinnant's original demonstration program]
+ class process_clock {
+ public:
+ typedef nanoseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef chrono::time_point<process_clock> time_point;
+ static const bool is_monotonic = true;
-['See the file libs/chrono/example/time2_demo.cpp]
+ struct process_times;
+ static void now( process_times & times,
+ system::error_code & ec = system::throws );
+ };
-[endsect]
+[section Class `process_times`]
-[/===============================================================]
-[section A tiny program that times how long until a key is struck]
+ struct process_times {
+ process_clock::duration real; // real (i.e wall clock) time
+ process_clock::duration user; // user cpu time
+ process_clock::duration system; // system cpu time
+ };
-[/await_keystroke_cpp]
+[endsect]
- #include <boost/chrono/chrono.hpp>
- #include <iostream>
- #include <iomanip>
+[endsect]
+[section Typedef `process_times`]
- using namespace boost::chrono;
+ typedef process_clock::process_times process_times;
- template< class Clock >
- class timer
- {
- typename Clock::time_point start;
- public:
+This is a synonym of process_clock::process_times included for backward compatibility.
- timer() : start( Clock::now() ) {}
+[endsect]
- typename Clock::duration elapsed() const
- {
- return Clock::now() - start;
- }
+[section Class `process_timer`]
- double seconds() const
- {
- return elapsed().count() * ((double)Clock::period::num/Clock::period::den);
- }
- };
+Knowing how long a program takes to execute is useful in both test and production environments. It is also helpful if such timing information is broken down into real (wall clock) time, CPU time spent by the user, and CPU time spent by the operating system servicing user requests.
- int main()
- {
- timer<system_clock> t1;
- timer<monotonic_clock> t2;
- timer<high_resolution_clock> t3;
+`process_timer<>` is the `timer<>` equivalent associated to the pseudo-clock `process_clock`. It behaves like `timer<>` but it uses the specific `process_clock:now()` function.
- std::cout << "Strike any key: ";
- std::cin.get();
+ class process_timer {
+ public:
+ typedef process_clock clock;
+ typedef process_clock::duration duration;
+ typedef process_clock::time_point time_point;
- std::cout << std::fixed << std::setprecision(9);
- std::cout << "system_clock-----------: "
- << t1.seconds() << " seconds\n";
- std::cout << "monotonic_clock--------: "
- << t2.seconds() << " seconds\n";
- std::cout << "high_resolution_clock--: "
- << t3.seconds() << " seconds\n";
+ explicit process_timer( system::error_code & ec = system::throws );
- system_clock::time_point d4 = system_clock::now();
- system_clock::time_point d5 = system_clock::now();
+ ~process_timer();
+ void start( system::error_code & ec = system::throws );
+ void elapsed( process_times & times, system::error_code & ec = system::throws );
+ };
- std::cout << "\nsystem_clock latency-----------: " << (d5 - d4).count() << std::endl;
+[endsect]
+[section Class `run_timer`]
- monotonic_clock::time_point d6 = monotonic_clock::now();
- monotonic_clock::time_point d7 = monotonic_clock::now();
+class `run_timer` provides a complete run time reporting package that can be invoked in a single line of code. The reporting is controled by two parameters:
- std::cout << "monotonic_clock latency--------: " << (d7 - d6).count() << std::endl;
+* format : The output format
+* places(precission): the number of decimal placess used.
- high_resolution_clock::time_point d8 = high_resolution_clock::now();
- high_resolution_clock::time_point d9 = high_resolution_clock::now();
+The default places is given by default_places and is 3.
- std::cout << "high_resolution_clock latency--: " << (d9 - d8).count() << std::endl;
+The default format is "nreal %rs, cpu %cs (%p%), user %us, system %ss\\n", where
- std::time_t now = system_clock::to_time_t(system_clock::now());
+* `%r` : real process clock
+* `%u` : user process clock
+* `%s` : system process clock
+* `%c` : user+system process clock
+* `%p` : percentage (user+system)/real process clock
- std::cout << "\nsystem_clock::now() reports UTC is "
- << std::asctime(std::gmtime(&now)) << "\n";
+All the units are given using the suffix "s" following the System International d'Unites Std.
- return 0;
- }
+ class run_timer : public process_timer {
+ public:
+ explicit run_timer( system::error_code & ec = system::throws );
+ explicit run_timer( std::ostream & os,
+ system::error_code & ec = system::throws );
-[endsect]
+ explicit run_timer( const std::string & format,
+ system::error_code & ec = system::throws );
+ explicit run_timer( std::ostream & os, const std::string & format,
+ system::error_code & ec = system::throws );
-[/============================]
-[section stopclock_example.cpp]
+ explicit run_timer( const std::string & format, int places,
+ system::error_code & ec = system::throws );
+ explicit run_timer( std::ostream & os, const std::string & format, int places,
+ system::error_code & ec = system::throws );
-Here is the stopclock_example.cpp program supplied with the Boost Chrono library:
+ explicit run_timer( int places,
+ system::error_code & ec = system::throws );
+ explicit run_timer( std::ostream & os, int places,
+ system::error_code & ec = system::throws );
-[/stopclock_example_cpp]
+ explicit run_timer( int places, const std::string & format,
+ system::error_code & ec = system::throws );
+ explicit run_timer( std::ostream & os, int places, const std::string & format,
+ system::error_code & ec = system::throws );
-When the stopclock<> t object is created, it starts timing. When it is destroyed at the end of the program, its destructor stops the timer and displays timing information on cout.
+ ~run_timer();
- #include <boost/chrono/stopclock.hpp>
- #include <cmath>
+ void start( system::error_code & ec = system::throws );
- int main()
- {
- boost::chrono::stopclock<> t;
+ void report( system::error_code & ec = system::throws );
- for ( long i = 0; i < 10000000; ++i )
- std::sqrt( 123.456L ); // burn some time
+ void test_report( duration real_, duration user_, duration system_ );
+ bool reported() const;
+ static int default_places();
+ };
- return 0;
- }
-The output of this program run on a circa 2006 processor looks was this:
+[endsect]
- wall 0.42 s, user 0.41 s + system 0.00 s = total cpu 0.41 s, (96.3%)
+[endsect]
-In other words, this program ran in 0.42 seconds as would be measured by a clock on the wall, the operating system charged it for 0.41 seconds of user CPU time and 0 seconds of system CPU time, the total of these two was 0.41, and that represented 96.3 percent of the wall clock time.
+[endsect]
[endsect]
-[/=============================]
-[section stopclock_example2.cpp]
+[/=================]
+[section Appendices]
+[/=================]
+[/==================================]
+[section:history Appendix A: History]
+[/==================================]
-The stopclock_example2.cpp program is the same, except that it supplies additional constructor arguments from the command line:
- #include <boost/chrono/stopclock.hpp>
- #include <cmath>
+[section [*Version 0.4.5, June 26, 2010] ['Documentation update]]
- int main( int argc, char * argv[] )
- {
- const char * format = argc > 1 ? argv[1] : "%t cpu seconds\n";
- int places = argc > 2 ? std::atoi( argv[2] ) : 2;
+[*Documentation]
- boost::chrono::stopclock<> t( format, places );
+* Overview rewriting
+* Added missing thread_clock reference.
+* How to implement a thread_clock tutorial removed.
+* References section renamed to External Resources.
+* Added links to source examples.
+* Added links between Models and Concepts.
+* Added macros descriptions.
+* Cleanup.
- for ( long i = 0; i < 10000000; ++i )
- std::sqrt( 123.456L ); // burn some time
+[*Bug Fixes]
- return 0;
- }
+* Valgrind fixes: Conditional jump or move depends on uninitialised value(s)
-Here is the output for this program for several sets of command line arguments:
- stopclock_example2
- 0.42 cpu seconds
+[endsect]
- stopclock_example2 "%w wall clock seconds\n"
- 0.41 wall clock seconds
+[section [*Version 0.4.4, February 22, 2010] [' Warning fixes]]
- stopclock_example2 "%w wall clock seconds\n" 6
- 0.421875 wall clock seconds
+[*Bug Fixes]
- stopclock_example2 "%t total CPU seconds\n" 3
- 0.422 total CPU seconds
+* scoped_suspend warning removal
+* error_code management completed
[endsect]
-[/===============================================================]
-[section time command]
+[section [*Version 0.4.3, June 18, 2010] ['Missing file fixe]]
- #include <boost/chrono/stopclock.hpp>
- #include <cstdlib>
- #include <string>
- #include <iostream>
+[*Bug Fixes]
- int main( int argc, char * argv[] )
- {
- if ( argc == 1 )
- {
- std::cout << "invoke: timex [-v] command [args...]\n"
- " command will be executed and timings displayed\n"
- " -v option causes command and args to be displayed\n";
- return 1;
- }
+* boost/thread/detail/cv_status.hpp file was not commited.
- std::string s;
+[endsect]
- bool verbose = false;
- if ( argc > 1 && *argv[1] == '-' && *(argv[1]+1) == 'v' )
- {
- verbose = true;
- ++argv;
- --argc;
- }
+[section [*Version 0.4.2, June 18, 2010] ['Packaging fixe]]
- for ( int i = 1; i < argc; ++i )
- {
- if ( i > 1 ) s += ' ';
- s += argv[i];
- }
+* Conversion library, used by Boost.Thread porting to Boost.Chrono was not packaged.
- if ( verbose )
- { std::cout << "command: \"" << s.c_str() << "\"\n"; }
+[endsect]
- boost::chrono::stopclock<> t;
+[section [*Version 0.4.1, June 17, 2010] ['Added thread clock implementation on Windows]]
- return std::system( s.c_str() );
- }
+[*New Features:]
-[endsect]
+* Added thread clock implementation on Windows
+* Added Boost.Thread using Boost.Chrono
[endsect]
-[/=================]
-[section Appendices]
-[/=================]
-[/==================================]
-[section:history Appendix A: History]
-[/==================================]
-
[section [*Version 0.4, February 28, 2010] ['New thread clock and Suspendible clock ]]
@@ -5477,7 +5731,7 @@
Thus, as common_type<A,B>::type is undefined, common_type<A,B,C>::type is also undefined.
-[heading Why does stopwatch_reporter only display millisecond place precision when the underlying timer has nanosecond precision?]
+[heading Why does stopwatch_reporter only display millisecond place precision when the underlying Clock has nanosecond precision?]
To avoid giving the impression of precision where none exists. See Caveat emptor. You can always specify additional decimal places if you want to live dangerously.
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -6,7 +6,8 @@
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
<link rel="start" href="../index.html" title="Boost.Chrono">
<link rel="up" href="../index.html" title="Boost.Chrono">
-<link rel="prev" href="examples/time_command.html" title="time command">
+<link rel="prev" href="reference/deprecated_headers.html" title="Deprecated
+ Headers">
<link rel="next" href="appendices/history.html" title=" Appendix A: History">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
@@ -20,7 +21,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="examples/time_command.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="appendices/history.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="reference/deprecated_headers.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="appendices/history.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
@@ -29,6 +30,15 @@
<div class="toc"><dl>
<dt><span class="section"> Appendix A: History</span></dt>
<dd><dl>
+<dt><span class="section"><a href="appendices/history.html#boost_chrono.appendices.history.__version_0_4_5__june_26__2010____documentation_update_"><span class="bold"><strong>Version 0.4.5, June 26, 2010</strong></span> <span class="emphasis"><em>Documentation
+ update</em></span></a></span></dt>
+<dt><span class="section"><a href="appendices/history.html#boost_chrono.appendices.history.__version_0_4_4__february_22__2010_____warning_fixes_"><span class="bold"><strong>Version 0.4.4, February 22, 2010</strong></span> <span class="emphasis"><em>Warning
+ fixes</em></span></a></span></dt>
+<dt><span class="section"><a href="appendices/history.html#boost_chrono.appendices.history.__version_0_4_3__june_18__2010____missing_file_fixe_"><span class="bold"><strong>Version 0.4.3, June 18, 2010</strong></span> <span class="emphasis"><em>Missing file
+ fixe</em></span></a></span></dt>
+<dt><span class="section">Version 0.4.2, June 18, 2010 Packaging fixe</span></dt>
+<dt><span class="section"><a href="appendices/history.html#boost_chrono.appendices.history.__version_0_4_1__june_17__2010____added_thread_clock_implementation_on_windows_"><span class="bold"><strong>Version 0.4.1, June 17, 2010</strong></span> <span class="emphasis"><em>Added thread
+ clock implementation on Windows</em></span></a></span></dt>
<dt><span class="section"><a href="appendices/history.html#boost_chrono.appendices.history.__version_0_4__february_28__2010____new_thread_clock_and_suspendible_clock__"><span class="bold"><strong>Version 0.4, February 28, 2010</strong></span> <span class="emphasis"><em>New thread
clock and Suspendible clock </em></span></a></span></dt>
<dt><span class="section"><a href="appendices/history.html#boost_chrono.appendices.history.__version_0_3_2__january_25__2010____new_frequency__lifetime_and_percentage_stopwatch_accumulator_features_"><span class="bold"><strong>Version 0.3.2, January 25, 2010</strong></span> <span class="emphasis"><em>New frequency,
@@ -72,7 +82,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="examples/time_command.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="appendices/history.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="reference/deprecated_headers.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="appendices/history.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
</body>
</html>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/faq.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/faq.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/faq.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -29,7 +29,7 @@
<a name="boost_chrono.appendices.faq"></a> Appendix D: FAQ
</h3></div></div></div>
<a name="boost_chrono.appendices.faq.how_important_is_the_order_of_the_common_type_lt__gt__template_arguments_"></a><h4>
-<a name="id4931191"></a>
+<a name="id4936054"></a>
<a href="faq.html#boost_chrono.appendices.faq.how_important_is_the_order_of_the_common_type_lt__gt__template_arguments_">How
important is the order of the common_type<> template arguments?</a>
</h4>
@@ -59,11 +59,11 @@
Thus, as common_type<A,B>::type is undefined, common_type<A,B,C>::type
is also undefined.
</p>
-<a name="boost_chrono.appendices.faq.why_does_stopwatch_reporter_only_display_millisecond_place_precision_when_the_underlying_timer_has_nanosecond_precision_"></a><h4>
-<a name="id4931601"></a>
- <a href="faq.html#boost_chrono.appendices.faq.why_does_stopwatch_reporter_only_display_millisecond_place_precision_when_the_underlying_timer_has_nanosecond_precision_">Why
+<a name="boost_chrono.appendices.faq.why_does_stopwatch_reporter_only_display_millisecond_place_precision_when_the_underlying_clock_has_nanosecond_precision_"></a><h4>
+<a name="id4936464"></a>
+ <a href="faq.html#boost_chrono.appendices.faq.why_does_stopwatch_reporter_only_display_millisecond_place_precision_when_the_underlying_clock_has_nanosecond_precision_">Why
does stopwatch_reporter only display millisecond place precision when the
- underlying timer has nanosecond precision?</a>
+ underlying Clock has nanosecond precision?</a>
</h4>
<p>
To avoid giving the impression of precision where none exists. See Caveat
@@ -71,7 +71,7 @@
dangerously.
</p>
<a name="boost_chrono.appendices.faq.why_does_stopwatch_reporter_sometimes_report_more_cpu_seconds_than_real_seconds_"></a><h4>
-<a name="id4931642"></a>
+<a name="id4936506"></a>
<a href="faq.html#boost_chrono.appendices.faq.why_does_stopwatch_reporter_sometimes_report_more_cpu_seconds_than_real_seconds_">Why
does stopwatch_reporter sometimes report more cpu seconds than real seconds?</a>
</h4>
@@ -81,7 +81,7 @@
be reporting at times.
</p>
<a name="boost_chrono.appendices.faq.can_i_obtain_statistics_of_the_time_elapsed_between_calls_to_a_function_"></a><h4>
-<a name="id4931676"></a>
+<a name="id4936539"></a>
<a href="faq.html#boost_chrono.appendices.faq.can_i_obtain_statistics_of_the_time_elapsed_between_calls_to_a_function_">Can
I obtain statistics of the time elapsed between calls to a function?</a>
</h4>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/history.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/history.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/history.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -27,6 +27,15 @@
<a name="boost_chrono.appendices.history"></a> Appendix A: History
</h3></div></div></div>
<div class="toc"><dl>
+<dt><span class="section"><a href="history.html#boost_chrono.appendices.history.__version_0_4_5__june_26__2010____documentation_update_"><span class="bold"><strong>Version 0.4.5, June 26, 2010</strong></span> <span class="emphasis"><em>Documentation
+ update</em></span></a></span></dt>
+<dt><span class="section"><a href="history.html#boost_chrono.appendices.history.__version_0_4_4__february_22__2010_____warning_fixes_"><span class="bold"><strong>Version 0.4.4, February 22, 2010</strong></span> <span class="emphasis"><em>Warning
+ fixes</em></span></a></span></dt>
+<dt><span class="section"><a href="history.html#boost_chrono.appendices.history.__version_0_4_3__june_18__2010____missing_file_fixe_"><span class="bold"><strong>Version 0.4.3, June 18, 2010</strong></span> <span class="emphasis"><em>Missing file
+ fixe</em></span></a></span></dt>
+<dt><span class="section">Version 0.4.2, June 18, 2010 Packaging fixe</span></dt>
+<dt><span class="section"><a href="history.html#boost_chrono.appendices.history.__version_0_4_1__june_17__2010____added_thread_clock_implementation_on_windows_"><span class="bold"><strong>Version 0.4.1, June 17, 2010</strong></span> <span class="emphasis"><em>Added thread
+ clock implementation on Windows</em></span></a></span></dt>
<dt><span class="section"><a href="history.html#boost_chrono.appendices.history.__version_0_4__february_28__2010____new_thread_clock_and_suspendible_clock__"><span class="bold"><strong>Version 0.4, February 28, 2010</strong></span> <span class="emphasis"><em>New thread
clock and Suspendible clock </em></span></a></span></dt>
<dt><span class="section"><a href="history.html#boost_chrono.appendices.history.__version_0_3_2__january_25__2010____new_frequency__lifetime_and_percentage_stopwatch_accumulator_features_"><span class="bold"><strong>Version 0.3.2, January 25, 2010</strong></span> <span class="emphasis"><em>New frequency,
@@ -43,6 +52,106 @@
</dl></div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.appendices.history.__version_0_4_5__june_26__2010____documentation_update_"></a><a href="history.html#boost_chrono.appendices.history.__version_0_4_5__june_26__2010____documentation_update_" title="Version 0.4.5, June 26, 2010 Documentation
+ update"><span class="bold"><strong>Version 0.4.5, June 26, 2010</strong></span> <span class="emphasis"><em>Documentation
+ update</em></span></a>
+</h4></div></div></div>
+<p>
+ <span class="bold"><strong>Documentation</strong></span>
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ Overview rewriting
+ </li>
+<li>
+ Added missing thread_clock reference.
+ </li>
+<li>
+ How to implement a thread_clock tutorial removed.
+ </li>
+<li>
+ References section renamed to External Resources.
+ </li>
+<li>
+ Added links to source examples.
+ </li>
+<li>
+ Added links between Models and Concepts.
+ </li>
+<li>
+ Added macros descriptions.
+ </li>
+<li>
+ Cleanup.
+ </li>
+</ul></div>
+<p>
+ <span class="bold"><strong>Bug Fixes</strong></span>
+ </p>
+<div class="itemizedlist"><ul type="disc"><li>
+ Valgrind fixes: Conditional jump or move depends on uninitialised value(s)
+ </li></ul></div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.appendices.history.__version_0_4_4__february_22__2010_____warning_fixes_"></a><a href="history.html#boost_chrono.appendices.history.__version_0_4_4__february_22__2010_____warning_fixes_" title="Version 0.4.4, February 22, 2010 Warning
+ fixes"><span class="bold"><strong>Version 0.4.4, February 22, 2010</strong></span> <span class="emphasis"><em>Warning
+ fixes</em></span></a>
+</h4></div></div></div>
+<p>
+ <span class="bold"><strong>Bug Fixes</strong></span>
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ scoped_suspend warning removal
+ </li>
+<li>
+ error_code management completed
+ </li>
+</ul></div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.appendices.history.__version_0_4_3__june_18__2010____missing_file_fixe_"></a><a href="history.html#boost_chrono.appendices.history.__version_0_4_3__june_18__2010____missing_file_fixe_" title="Version 0.4.3, June 18, 2010 Missing file
+ fixe"><span class="bold"><strong>Version 0.4.3, June 18, 2010</strong></span> <span class="emphasis"><em>Missing file
+ fixe</em></span></a>
+</h4></div></div></div>
+<p>
+ <span class="bold"><strong>Bug Fixes</strong></span>
+ </p>
+<div class="itemizedlist"><ul type="disc"><li>
+ boost/thread/detail/cv_status.hpp file was not commited.
+ </li></ul></div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.appendices.history.__version_0_4_2__june_18__2010____packaging_fixe_"></a>Version 0.4.2, June 18, 2010 Packaging fixe
+</h4></div></div></div>
+<div class="itemizedlist"><ul type="disc"><li>
+ Conversion library, used by Boost.Thread porting to Boost.Chrono was
+ not packaged.
+ </li></ul></div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.appendices.history.__version_0_4_1__june_17__2010____added_thread_clock_implementation_on_windows_"></a><a href="history.html#boost_chrono.appendices.history.__version_0_4_1__june_17__2010____added_thread_clock_implementation_on_windows_" title="Version 0.4.1, June 17, 2010 Added thread
+ clock implementation on Windows"><span class="bold"><strong>Version 0.4.1, June 17, 2010</strong></span> <span class="emphasis"><em>Added thread
+ clock implementation on Windows</em></span></a>
+</h4></div></div></div>
+<p>
+ <span class="bold"><strong>New Features:</strong></span>
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+ Added thread clock implementation on Windows
+ </li>
+<li>
+ Added Boost.Thread using Boost.Chrono
+ </li>
+</ul></div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
<a name="boost_chrono.appendices.history.__version_0_4__february_28__2010____new_thread_clock_and_suspendible_clock__"></a><a href="history.html#boost_chrono.appendices.history.__version_0_4__february_28__2010____new_thread_clock_and_suspendible_clock__" title="Version 0.4, February 28, 2010 New thread
clock and Suspendible clock "><span class="bold"><strong>Version 0.4, February 28, 2010</strong></span> <span class="emphasis"><em>New thread
clock and Suspendible clock </em></span></a>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/perf.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/perf.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/perf.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -69,7 +69,7 @@
with a variable lifetime.
</p>
<a name="boost_chrono.appendices.perf.single_threaded_recursive_function"></a><h4>
-<a name="id4935021"></a>
+<a name="id4939886"></a>
<a href="perf.html#boost_chrono.appendices.perf.single_threaded_recursive_function">Single-Threaded
Recursive function</a>
</h4>
@@ -92,7 +92,7 @@
and thread_clock.
</p>
<a name="boost_chrono.appendices.perf.multi_threaded_recursive_function"></a><h4>
-<a name="id4935070"></a>
+<a name="id4939935"></a>
<a href="perf.html#boost_chrono.appendices.perf.multi_threaded_recursive_function">Multi-Threaded
Recursive function</a>
</h4>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/rationale.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/rationale.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/rationale.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -33,7 +33,7 @@
are an extract from this document.
</p>
<a name="boost_chrono.appendices.rationale.is_it_possible_for_the_user_to_pass_a__code__phrase_role__identifier__duration__phrase___code__to_a_function_with_the_units_being_ambiguous_"></a><h4>
-<a name="id4929975"></a>
+<a name="id4934837"></a>
<a href="rationale.html#boost_chrono.appendices.rationale.is_it_possible_for_the_user_to_pass_a__code__phrase_role__identifier__duration__phrase___code__to_a_function_with_the_units_being_ambiguous_">Is
it possible for the user to pass a <code class="computeroutput"><span class="identifier">duration</span></code>
to a function with the units being ambiguous?</a>
@@ -45,7 +45,7 @@
<pre class="programlisting"><span class="identifier">f</span><span class="special">(</span><span class="number">3</span><span class="special">);</span> <span class="comment">// Will not compile, 3 is not implicitly convertible to any `duration`
</span></pre>
<a name="boost_chrono.appendices.rationale.why_duration_needs_operator_"></a><h4>
-<a name="id4930064"></a>
+<a name="id4934927"></a>
<a href="rationale.html#boost_chrono.appendices.rationale.why_duration_needs_operator_">Why
duration needs operator%</a>
</h4>
@@ -73,7 +73,7 @@
<span class="special">};</span>
</pre>
<a name="boost_chrono.appendices.rationale.why_ratio_needs_copyconstruction_and_assignment_from_ratios_having_the_same_normalized_form"></a><h4>
-<a name="id4930645"></a>
+<a name="id4935507"></a>
<a href="rationale.html#boost_chrono.appendices.rationale.why_ratio_needs_copyconstruction_and_assignment_from_ratios_having_the_same_normalized_form">Why
ratio needs CopyConstruction and Assignment from ratios having the same normalized
form</a>
@@ -101,7 +101,7 @@
ratio<1,3> and the compilation succeeds.
</p>
<a name="boost_chrono.appendices.rationale.why_ratio_needs_the_nested_normalizer_typedef_type"></a><h4>
-<a name="id4930958"></a>
+<a name="id4935821"></a>
<a href="rationale.html#boost_chrono.appendices.rationale.why_ratio_needs_the_nested_normalizer_typedef_type">Why
ratio needs the nested normalizer typedef type</a>
</h4>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/todo.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/todo.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/appendices/todo.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -26,7 +26,7 @@
<a name="boost_chrono.appendices.todo"></a> Appendix I: Future plans
</h3></div></div></div>
<a name="boost_chrono.appendices.todo.tasks_to_do_before_review"></a><h4>
-<a name="id4935136"></a>
+<a name="id4940002"></a>
<a href="todo.html#boost_chrono.appendices.todo.tasks_to_do_before_review">Tasks
to do before review</a>
</h4>
@@ -42,7 +42,7 @@
</li>
</ul></div>
<a name="boost_chrono.appendices.todo.for_later_releases"></a><h4>
-<a name="id4935176"></a>
+<a name="id4940041"></a>
<a href="todo.html#boost_chrono.appendices.todo.for_later_releases">For later
releases</a>
</h4>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/a_tiny_program_that_times_how_long_until_a_key_is_struck.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/a_tiny_program_that_times_how_long_until_a_key_is_struck.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/a_tiny_program_that_times_how_long_until_a_key_is_struck.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -95,6 +95,9 @@
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
</pre>
+<p>
+ <span class="emphasis"><em>See the source file example/await_keystroke.cpp</em></span>
+ </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/cycle_count.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/cycle_count.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/cycle_count.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -71,7 +71,7 @@
<span class="special">};</span>
</pre>
<p>
- <span class="emphasis"><em>See the file libs/chrono/example/cycle_count.cpp</em></span>
+ <span class="emphasis"><em>See the source file here</em></span>
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/how_you_override_the_duration_s_default_constructor.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/how_you_override_the_duration_s_default_constructor.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/how_you_override_the_duration_s_default_constructor.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -89,7 +89,7 @@
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">ms</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="char">'\n'</span><span class="special">;</span>
</pre>
<p>
- <span class="emphasis"><em>See the file i_dont_like_the_default_duration_behavior.cpp</em></span>
+ <span class="emphasis"><em>See the source file example/i_dont_like_the_default_duration_behavior.cpp</em></span>
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/howard_hinnant_s_original_demonstration_program.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/howard_hinnant_s_original_demonstration_program.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/howard_hinnant_s_original_demonstration_program.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -31,7 +31,7 @@
Hinnant's original demonstration program</a>
</h3></div></div></div>
<p>
- <span class="emphasis"><em>See the file libs/chrono/example/time2_demo.cpp</em></span>
+ <span class="emphasis"><em>See the source file example/time2_demo.cpp</em></span>
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/min_utility.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/min_utility.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/min_utility.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -51,6 +51,9 @@
<span class="comment">/*auto*/</span> <span class="identifier">T2</span> <span class="identifier">t2</span> <span class="special">=</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">nanoseconds</span><span class="special">(</span><span class="number">3</span><span class="special">);</span>
<span class="comment">/*auto*/</span> <span class="identifier">T3</span> <span class="identifier">t3</span> <span class="special">=</span> <span class="identifier">min</span><span class="special">(</span><span class="identifier">t1</span><span class="special">,</span> <span class="identifier">t2</span><span class="special">);</span>
</pre>
+<p>
+ <span class="emphasis"><em>See the source file example/min_time_point.cpp</em></span>
+ </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/runtime_resolution.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/runtime_resolution.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/runtime_resolution.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -85,7 +85,7 @@
<span class="special">};</span>
</pre>
<p>
- <span class="emphasis"><em>See the file libs/chrono/example/runtime_resolution.cpp</em></span>
+ <span class="emphasis"><em>See the source file here</em></span>
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/saturating.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/saturating.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/saturating.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -35,7 +35,7 @@
to demonstrate a duration class that does not silently ignore overflow.
</p>
<p>
- <span class="emphasis"><em>See the file libs/chrono/example/satutating.cpp</em></span>
+ <span class="emphasis"><em>See the source file example/satutating.cpp</em></span>
</p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/si_units.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/si_units.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/si_units.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -258,6 +258,9 @@
<span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>
</pre>
+<p>
+ <span class="emphasis"><em>See the source file test/ratio_test.cpp</em></span>
+ </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/simulated_thread_interface_demonstration_program.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/simulated_thread_interface_demonstration_program.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/simulated_thread_interface_demonstration_program.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -163,6 +163,9 @@
</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">sleep_for</span><span class="special">(</span><span class="identifier">duration</span><span class="special"><</span><span class="keyword">double</span><span class="special">>(</span><span class="number">0.25</span><span class="special">));</span>
<span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">sleep_until</span><span class="special">(</span><span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">duration</span><span class="special"><</span><span class="keyword">double</span><span class="special">>(</span><span class="number">1.5</span><span class="special">));</span>
</pre>
+<p>
+ <span class="emphasis"><em>See the source file example/simulated_thread_interface_demo.cpp</em></span>
+ </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/stopclock_example2_cpp.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/stopclock_example2_cpp.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/stopclock_example2_cpp.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -61,6 +61,9 @@
<span class="identifier">stopclock_example2</span> <span class="string">"%t total CPU seconds\n"</span> <span class="number">3</span>
<span class="number">0.422</span> <span class="identifier">total</span> <span class="identifier">CPU</span> <span class="identifier">seconds</span>
</pre>
+<p>
+ <span class="emphasis"><em>See the source file example/stopclock_example2.cpp</em></span>
+ </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/stopclock_example_cpp.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/stopclock_example_cpp.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/stopclock_example_cpp.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -60,6 +60,9 @@
user CPU time and 0 seconds of system CPU time, the total of these two was
0.41, and that represented 96.3 percent of the wall clock time.
</p>
+<p>
+ <span class="emphasis"><em>See the source file example/stopclock_example.cpp</em></span>
+ </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/time_command.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/time_command.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/time_command.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -65,6 +65,9 @@
<span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">system</span><span class="special">(</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">c_str</span><span class="special">()</span> <span class="special">);</span>
<span class="special">}</span>
</pre>
+<p>
+ <span class="emphasis"><em>See the source file example/timex.cpp</em></span>
+ </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/xtime_clock.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/xtime_clock.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/xtime_clock.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -162,6 +162,9 @@
<span class="identifier">xtime_clock</span><span class="special">::</span><span class="identifier">duration</span> <span class="identifier">elapsed</span> <span class="special">=</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"paused "</span> <span class="special"><<</span> <span class="identifier">nanoseconds</span><span class="special">(</span><span class="identifier">elapsed</span><span class="special">).</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" nanoseconds\n"</span><span class="special">;</span>
</pre>
+<p>
+ <span class="emphasis"><em>See the source file example/timeval_demo.cpp</em></span>
+ </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/xtime_conversions.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/xtime_conversions.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/examples/xtime_conversions.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -102,6 +102,9 @@
<span class="identifier">xt</span> <span class="special">=</span> <span class="identifier">to_xtime_round_up</span><span class="special">(</span><span class="identifier">seconds</span><span class="special">(</span><span class="number">3</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">nanoseconds</span><span class="special">(</span><span class="number">999</span><span class="special">));</span>
<span class="identifier">print</span><span class="special">(</span><span class="identifier">xt</span><span class="special">);</span>
</pre>
+<p>
+ <span class="emphasis"><em>See the source file here</em></span>
+ </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/overview.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/overview.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/overview.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -37,103 +37,89 @@
<dt><span class="section">Time Point</span></dt>
<dt><span class="section">Stopwatches</span></dt>
</dl></dd>
-<dt><span class="section">Caveat emptor</span></dt>
+<dt><span class="section"> Caveat emptor</span></dt>
</dl></div>
<a name="boost_chrono.overview.description"></a><h3>
-<a name="id4762509"></a>
+<a name="id4765019"></a>
<a href="overview.html#boost_chrono.overview.description">Description</a>
</h3>
<p>
- The Boost Chrono library provides:
+ The <span class="bold"><strong>Boost.Chrono</strong></span> library provides:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
- The C++0x Standard Library's <code class="computeroutput"><span class="identifier">common_type</span></code>.
+ One facility for representing time durations: <code class="computeroutput"><span class="identifier">duration</span></code>.
+ Examples of time durations include seconds, minutes and nanoseconds. All
+ of these units of time duration are united with a generic interface by the
+ duration facility.
+ </li>
+<li>
+ One facility for representing points in time: <code class="computeroutput"><span class="identifier">time_point</span></code>.
+ A time_point represents an epoch plus or minus a duration. This paper leaves
+ epochs unspecified. A time_point is associated with a clock.
+ </li>
+<li>
+ Several clocks, some of which may not be available on any given platform:
+ <code class="computeroutput"><span class="identifier">system_clock</span></code>, <code class="computeroutput"><span class="identifier">monotonic_clock</span></code> and <code class="computeroutput"><span class="identifier">high_resolution_clock</span></code>.
+ A clock is a symbolic bundle of a native <code class="computeroutput"><span class="identifier">time_point</span></code>
+ and <code class="computeroutput"><span class="identifier">duration</span></code>, and a function
+ which returns a <code class="computeroutput"><span class="identifier">time_point</span></code>
+ representing <span class="emphasis"><em>now</em></span>.
</li>
-<li>
- The C++0x Standard Library's compile-time rational arithmetic.
- </li>
-<li>
- The C++0x Standard Library's time utilities, including:
- <div class="itemizedlist"><ul type="circle">
-<li>
- Class template <code class="computeroutput"><span class="identifier">duration</span></code>
-</li>
-<li>
- Class template <code class="computeroutput"><span class="identifier">time_point</span></code>
-</li>
-<li>
- Clocks:
- <div class="itemizedlist"><ul type="square">
-<li><code class="computeroutput"><span class="identifier">system_clock</span></code></li>
-<li><code class="computeroutput"><span class="identifier">monotonic_clock</span></code></li>
-<li><code class="computeroutput"><span class="identifier">high_resolution_clock</span></code></li>
</ul></div>
-</li>
-<li>
- typeof registration for classes <code class="computeroutput"><span class="identifier">duration</span></code>
- and <code class="computeroutput"><span class="identifier">time_point</span></code>
-</li>
-</ul></div>
-</li>
-<li>
- Process clocks:
- <div class="itemizedlist"><ul type="circle">
-<li>
-<code class="computeroutput"><span class="identifier">process_real_CPU_clocks</span></code>,
- capturing real-CPU times.
- </li>
-<li>
-<code class="computeroutput"><span class="identifier">process_user_CPU_clocks</span></code>,
- capturing user-CPU times.
- </li>
-<li>
-<code class="computeroutput"><span class="identifier">process_system_CPU_clocks</span></code>,
- capturing system-CPU times.
- </li>
+<p>
+ Additionally, a minimal amount of general purpose infrastructure is provided
+ which will support both the interface and implementation of the clocks, time_points
+ and durations proposed herein. It is expected that these general purpose facilities
+ will also find utility in far ranging user applications as well.
+ </p>
+<div class="itemizedlist"><ul type="disc">
<li>
-<code class="computeroutput"><span class="identifier">process_cpu_clock</span></code>, tuple-like
- class capturing at once real, user-CPU, and system-CPU times.
- </li>
-</ul></div>
-</li>
+ common_type is a facility which is useful in specifying the type of the result
+ of functions and operators which take a variety of types (e.g. "mixed
+ mode" complex arithmetic).
+ </li>
<li>
- Thread clock
+ ratio is a facility which is useful in specifying compile time rational constants.
+ Compile time rational arithmetic is supported with protection against overflow
+ and divide by zero. Such a facility is very handy when needing to efficiently
+ represent 1/3 of a nanosecond, or specifying an inch in terms of meters (for
+ example 254/10000 meters - which ratio will reduce to 127/5000 meters).
</li>
+</ul></div>
+<p>
+ Knowing how long a program takes to execute is useful in both test and production
+ environments. On top of the standard facilities <span class="bold"><strong>Boost.Chrono</strong></span>
+ includes:
+ </p>
+<div class="itemizedlist"><ul type="disc">
<li>
- Suspendible Clock
+ a Stopwatch middle layer: providing operations to start, stop, suspend or
+ resume a <code class="computeroutput"><span class="identifier">Stopwatch</span></code> to measure
+ the elapsed time.
<div class="itemizedlist"><ul type="circle">
<li>
- Suspendible Clock concept
+<code class="computeroutput"><span class="identifier">Stopwatch</span></code> concept
</li>
<li>
- template class suspendible_clock<>
+ Scoped helper classes allowing to pairwise start/stop operations, suspend/resume
+ and resume/suspend a <code class="computeroutput"><span class="identifier">Stopwatch</span></code>.
</li>
<li>
- Added scope_suspend which do suspend/resume if the Clock is a model of
- Suspendible Clock concept, and nothing otherwise.
- </li>
-</ul></div>
-</li>
-<li>
- Stopwatches:
- <div class="itemizedlist"><ul type="circle">
-<li>
-<code class="computeroutput"><span class="identifier">stopwatch</span></code>, capturing
- elapsed Clock times.
+<code class="computeroutput"><span class="identifier">stopwatch</span></code>, model of
+ <code class="computeroutput"><span class="identifier">Stopwatch</span></code> capturing elapsed
+ Clock times.
</li>
<li>
<code class="computeroutput"><span class="identifier">stopwatch_accumulator</span></code>,
- capturing cummulated elapsed Clock times.
- </li>
-<li>
- scoped helper classes allowing to pairwise start/stop operations, suspend/resume
- and resume/suspend a Stopwatch.
+ model of <code class="computeroutput"><span class="identifier">Stopwatch</span></code> capturing
+ cummulated elapsed Clock times.
</li>
</ul></div>
</li>
<li>
- Stopclocks or Stopwatch reporters:
+ a Stopclocks higher layer: provide a complete stopclock reporting package
+ that can be invoked in a single line of code.
<div class="itemizedlist"><ul type="circle">
<li>
<code class="computeroutput"><span class="identifier">stopwatch_reporter</span></code>, convenient
@@ -149,8 +135,42 @@
</ul></div>
</li>
</ul></div>
+<p>
+ It is also helpful if such timing information is broken down into real (wall
+ clock) time, CPU time spent by the user, and CPU time spent by the operating
+ system servicing user requests. process clocks provide a thin wrapper around
+ the operating system's process timer API. For POSIX-like systems, that's the
+ times() function, while for Windows, it's the GetProcessTimes() function.
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>
+<code class="computeroutput"><span class="identifier">process_real_CPU_clocks</span></code>,
+ capturing real-CPU times.
+ </li>
+<li>
+<code class="computeroutput"><span class="identifier">process_user_CPU_clocks</span></code>,
+ capturing user-CPU times.
+ </li>
+<li>
+<code class="computeroutput"><span class="identifier">process_system_CPU_clocks</span></code>,
+ capturing system-CPU times.
+ </li>
+<li>
+<code class="computeroutput"><span class="identifier">process_cpu_clock</span></code>, tuple-like
+ class capturing at once real, user-CPU, and system-CPU times.
+ </li>
+</ul></div>
+<p>
+ To complete the clocks <span class="bold"><strong>Boost.Chrono</strong></span> provides,
+ in platforms support them, thread clocks.
+ </p>
+<p>
+ Last, <span class="bold"><strong>Boost.Chrono</strong></span> include typeof registration
+ for classes <code class="computeroutput"><span class="identifier">duration</span></code> and <code class="computeroutput"><span class="identifier">time_point</span></code> so you can used auto emulated
+ on C++03 compilers.
+ </p>
<a name="boost_chrono.overview.how_to_use_this_documentation"></a><h3>
-<a name="id4765251"></a>
+<a name="id4803618"></a>
<a href="overview.html#boost_chrono.overview.how_to_use_this_documentation">How to
Use This Documentation</a>
</h3>
Added: sandbox/chrono/libs/chrono/doc/html/boost_chrono/overview/caveat.html
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/overview/caveat.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,51 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title> Caveat emptor</title>
+<link rel="stylesheet" href="../../../../../../doc/html/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
+<link rel="start" href="../../index.html" title="Boost.Chrono">
+<link rel="up" href="../overview.html" title="Overview">
+<link rel="prev" href="motivation.html" title="Motivation">
+<link rel="next" href="../users_guide.html" title=" Users'Guide">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="motivation.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../overview.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../users_guide.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_chrono.overview.caveat"></a> Caveat emptor
+</h3></div></div></div>
+<p>
+ The underlying clocks provided by operating systems are subject to many seemingly
+ arbitrary policies and implementation irregularities. That's a polite way
+ of saying they tend to be flakey, and each operating system or even each
+ clock has its own cruel and unusual forms of flakiness. Don't bet the farm
+ on their accuracy, unless you have become deeply familiar with exactly what
+ the specific operating system is guaranteeing, which is often very little.
+ </p>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2008 Howard Hinnant<br>Copyright © 2006 , 2008 Beman Dawes<br>Copyright © 2009 -2010 Vicente J. Botet Escriba<p>
+ 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)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="motivation.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../overview.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../users_guide.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/overview/motivation.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/overview/motivation.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/overview/motivation.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -7,7 +7,7 @@
<link rel="start" href="../../index.html" title="Boost.Chrono">
<link rel="up" href="../overview.html" title="Overview">
<link rel="prev" href="../overview.html" title="Overview">
-<link rel="next" href="caveat_emptor.html" title="Caveat emptor">
+<link rel="next" href="caveat.html" title=" Caveat emptor">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
@@ -20,7 +20,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="../overview.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../overview.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="caveat_emptor.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="../overview.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../overview.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="caveat.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
@@ -36,10 +36,34 @@
<dt><span class="section">Stopwatches</span></dt>
</dl></div>
<p>
+ We all deal with time every day of our lives. We've intuitively known it
+ since birth. Thus we are all very familiar with it and believe it to be a
+ simple matter. The modeling of time in computer programs should be similarly
+ simple.
+ </p>
+<p>
+ The unfortunate truth is that this perceived simplicity is only skin deep.
+ Fortunately however, we do not need a terribly complicated solution to meet
+ the bulk of our needs. However, overly simplistic solutions are fraught with
+ danger, inherent inefficiency, and lack the ability to adapt as the computer
+ industry evolves over decades.
+ </p>
+<p>
+ <span class="bold"><strong>Boost.Chrono</strong></span> proposes a solution that is
+ precision neutral, with a very simple end user interface which supports multiple
+ clocks, multiple precisions (both coarser and finer than we will ever need),
+ separate types for points in time and time durations, efficiency, and compile
+ time enforced safety.
+ </p>
+<p>
+ In addition to the clocks provided by the standard proposal, <span class="bold"><strong>Boost.Chrono</strong></span>
+ provides specific process clocks and a thread clock.
+ </p>
+<p>
See N2661 - A Foundation to Sleep On which is
very informative and provides motivation for key design decisions for <code class="computeroutput"><span class="identifier">common_type</span></code>, <code class="computeroutput"><span class="identifier">ratio</span></code>
- and <code class="computeroutput"><span class="identifier">chrono</span></code>. The following
- sections are an extract from this document.
+ and <code class="computeroutput"><span class="identifier">chrono</span></code>. This documentation
+ contains a lot of extracts from this document.
</p>
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
@@ -116,7 +140,7 @@
</p>
<p>
<code class="computeroutput"><span class="identifier">ratio</span></code> is a template taking
- two intmax_ts, with the second defaulted to 1. In addition to cop^y constructors
+ two intmax_ts, with the second defaulted to 1. In addition to copy constructors
and assignement, it only has two public members, both of which are static
const intmax_t. One is the numerator of the <code class="computeroutput"><span class="identifier">ratio</span></code>
and the other is the denominator. The <code class="computeroutput"><span class="identifier">ratio</span></code>
@@ -237,7 +261,7 @@
needs only 23 bits to cover that range.
</p>
<a name="boost_chrono.overview.motivation.duration.so_what_exactly_is_a__code__phrase_role__identifier__duration__phrase___code__and_how_do_i_use_one_"></a><h5>
-<a name="id4759591"></a>
+<a name="id4759703"></a>
<a href="motivation.html#boost_chrono.overview.motivation.duration.so_what_exactly_is_a__code__phrase_role__identifier__duration__phrase___code__and_how_do_i_use_one_">So
What Exactly is a <code class="computeroutput"><span class="identifier">duration</span></code>
and How Do I Use One?</a>
@@ -295,7 +319,7 @@
instead of inheritance).
</p>
<a name="boost_chrono.overview.motivation.duration.what_happens_if_i_assign__code__phrase_role__identifier__m3__phrase___phrase_role__special_____phrase___phrase_role__identifier__us3__phrase___code__to__code__phrase_role__identifier__minutes__phrase___code__instead_of__code__phrase_role__identifier__microseconds__phrase___code__"></a><h5>
-<a name="id4813283"></a>
+<a name="id4813430"></a>
<a href="motivation.html#boost_chrono.overview.motivation.duration.what_happens_if_i_assign__code__phrase_role__identifier__m3__phrase___phrase_role__special_____phrase___phrase_role__identifier__us3__phrase___code__to__code__phrase_role__identifier__minutes__phrase___code__instead_of__code__phrase_role__identifier__microseconds__phrase___code__">What
happens if I assign <code class="computeroutput"><span class="identifier">m3</span> <span class="special">+</span> <span class="identifier">us3</span></code>
to <code class="computeroutput"><span class="identifier">minutes</span></code> instead of
@@ -312,7 +336,7 @@
ignored. This is similar to the problem of assigning a double to an <code class="computeroutput"><span class="keyword">int</span></code>: the fractional part gets silently discarded.
</p>
<a name="boost_chrono.overview.motivation.duration.but_what_if_the_truncation_behavior_is_what_i_want_to_do_"></a><h5>
-<a name="id4813452"></a>
+<a name="id4813599"></a>
<a href="motivation.html#boost_chrono.overview.motivation.duration.but_what_if_the_truncation_behavior_is_what_i_want_to_do_">But
what if the truncation behavior is what I want to do?</a>
</h5>
@@ -332,7 +356,7 @@
as often as it can.
</p>
<a name="boost_chrono.overview.motivation.duration.i_m_trafficking_in_floating_point__code__phrase_role__identifier__duration__phrase___code_s__i_don_t_want_to_deal_with_writing__code__phrase_role__identifier__duration_cast__phrase___code__all_over_the_place__i_m_content_with_the_precision_of_my_floating_point_representation"></a><h5>
-<a name="id4813589"></a>
+<a name="id4813736"></a>
<a href="motivation.html#boost_chrono.overview.motivation.duration.i_m_trafficking_in_floating_point__code__phrase_role__identifier__duration__phrase___code_s__i_don_t_want_to_deal_with_writing__code__phrase_role__identifier__duration_cast__phrase___code__all_over_the_place__i_m_content_with_the_precision_of_my_floating_point_representation">I'm
trafficking in floating point <code class="computeroutput"><span class="identifier">duration</span></code>s.
I don't want to deal with writing <code class="computeroutput"><span class="identifier">duration_cast</span></code>
@@ -347,7 +371,7 @@
<span class="identifier">dminutes</span> <span class="identifier">dm4</span> <span class="special">=</span> <span class="identifier">m3</span> <span class="special">+</span> <span class="identifier">us3</span><span class="special">;</span> <span class="comment">// dm4.count() == 5.000000083333333
</span></pre>
<a name="boost_chrono.overview.motivation.duration.how_expensive_is_all_of_this_"></a><h5>
-<a name="id4813751"></a>
+<a name="id4813898"></a>
<a href="motivation.html#boost_chrono.overview.motivation.duration.how_expensive_is_all_of_this_">How
expensive is all of this?</a>
</h5>
@@ -361,7 +385,7 @@
tick counts.
</p>
<a name="boost_chrono.overview.motivation.duration.how_complicated_is_it_to_build_a_function_taking_a__code__phrase_role__identifier__duration__phrase___code__parameter_"></a><h5>
-<a name="id4813801"></a>
+<a name="id4813948"></a>
<a href="motivation.html#boost_chrono.overview.motivation.duration.how_complicated_is_it_to_build_a_function_taking_a__code__phrase_role__identifier__duration__phrase___code__parameter_">How
complicated is it to build a function taking a <code class="computeroutput"><span class="identifier">duration</span></code>
parameter?</a>
@@ -483,7 +507,8 @@
</li>
</ol></div>
<p>
- <span class="bold"><strong>Boost.Chrono</strong></span> provides 3 concrete clocks:
+ <span class="bold"><strong>Boost.Chrono</strong></span> provides the standard concrete
+ clocks:
</p>
<div class="orderedlist"><ol type="1">
<li>
@@ -583,7 +608,7 @@
the relationship between the epochs associated with each clock is known.
</p>
<a name="boost_chrono.overview.motivation.time_point.so_what_exactly_is_a__code__phrase_role__identifier__time_point__phrase___code__and_how_do_i_use_one_"></a><h5>
-<a name="id4815607"></a>
+<a name="id4815754"></a>
<a href="motivation.html#boost_chrono.overview.motivation.time_point.so_what_exactly_is_a__code__phrase_role__identifier__time_point__phrase___code__and_how_do_i_use_one_">So
What Exactly is a <code class="computeroutput"><span class="identifier">time_point</span></code>
and How Do I Use One?</a>
@@ -671,9 +696,11 @@
<p>
Knowing how long a program, a function or a specific block takes to execute
is useful in both test and production environments. <span class="bold"><strong>Boost.Chrono</strong></span>
- introduces the Stopwatch concept which captures the mechanism to measure
- the elapsed time. A Stopwatch allows to start, stop, suspend and resume
- the measure of the eleapsed time. <code class="computeroutput"><span class="identifier">stopwatch</span><span class="special"><></span></code> is the basic model of Stopwatch
+ introduces the <code class="computeroutput"><span class="identifier">Stopwatch</span></code>
+ concept which captures the mechanism to measure the elapsed time. A Stopwatch
+ allows to start, stop, suspend and resume the measure of the eleapsed time.
+ <code class="computeroutput"><span class="identifier">stopwatch</span><span class="special"><></span></code>
+ is the basic model of <code class="computeroutput"><span class="identifier">Stopwatch</span></code>
allowing to make a single measure.
</p>
<p>
@@ -706,7 +733,7 @@
<span class="number">0.017</span><span class="identifier">s</span>
</pre>
<a name="boost_chrono.overview.motivation.stopwatches.stopwatches_accumulation_and_statistics"></a><h5>
-<a name="id4816710"></a>
+<a name="id4816875"></a>
<a href="motivation.html#boost_chrono.overview.motivation.stopwatches.stopwatches_accumulation_and_statistics">Stopwatches
accumulation and statistics</a>
</h5>
@@ -743,7 +770,7 @@
<pre class="programlisting"><span class="number">3</span> <span class="identifier">times</span><span class="special">,</span> <span class="identifier">sum</span><span class="special">=</span><span class="number">0.034</span><span class="identifier">s</span><span class="special">,</span> <span class="identifier">min</span><span class="special">=</span><span class="number">0.006</span><span class="identifier">s</span><span class="special">,</span> <span class="identifier">max</span><span class="special">=</span><span class="number">0.017</span><span class="identifier">s</span><span class="special">,</span> <span class="identifier">mean</span><span class="special">=</span><span class="number">0.011</span><span class="identifier">s</span>
</pre>
<a name="boost_chrono.overview.motivation.stopwatches.wall_clock_versus_system_and_user_time"></a><h5>
-<a name="id4817228"></a>
+<a name="id4817393"></a>
<a href="motivation.html#boost_chrono.overview.motivation.stopwatches.wall_clock_versus_system_and_user_time">Wall
clock versus system and user time</a>
</h5>
@@ -799,62 +826,70 @@
</span><span class="special">}</span>
</pre>
<a name="boost_chrono.overview.motivation.stopwatches.how_reliable_are_these_measures_"></a><h5>
-<a name="id4817615"></a>
+<a name="id4817780"></a>
<a href="motivation.html#boost_chrono.overview.motivation.stopwatches.how_reliable_are_these_measures_">How
reliable are these measures?</a>
</h5>
-<p>
- [info this section need to be reworked, the ideas are there, but ...]
- </p>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/html/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ this section need to be reworked, the ideas are there, but ...
+ </p></td></tr>
+</table></div>
<p>
There are three context on which you can get unreliable measures:
</p>
-<div class="orderedlist"><ol type="1">
-<li>
- the precission of your clock. If the precission of your clock is 10ms
- you can not be able to measure the time spent by blocks of code that
- takes the same order of magnitude. The library provides a hig_resolution_clock
+<div class="itemizedlist"><ul type="disc"><li>
+ Precission of your clock. If the precission of your clock is 10ms you
+ can not be able to measure the time spent by blocks of code that takes
+ the same order of magnitude. The library provides a hig_resolution_clock
that gives you the higher resolution available on your platform. Respect
to the precission, nothing to do except to take the clock with the highest
resolution and measures blocks of code that will spent time having more
than one order of magnitude the precission of the clock.
- <div class="orderedlist"><ol type="a"><li>
- include <boost/chrono/thread_clock.hpp> ... stopclock<high_resolution_clock>
- _;
- </li></ol></div>
-</li>
-<li>
+ </li></ul></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+ <span class="special">...</span>
+ <span class="identifier">stopclock</span><span class="special"><</span><span class="identifier">high_resolution_clock</span><span class="special">></span> <span class="identifier">_</span><span class="special">;</span>
+</pre>
+<p>
+ </p>
+<div class="itemizedlist"><ul type="disc"><li>
When your application is multithreaded, and you use a process clock,
the time you get is the delay during which your block has been executed,
in concurrency with the other threads of execution. If what you want
is the time spent by this specific thread another clock is needed. The
- library provide a thread_clock that returns the time spent by the thread
- on platforms providing this kind of data. It can be used as follows
- <div class="orderedlist"><ol type="a">
-<li>
- include <boost/chrono/thread_clock.hpp> ...
- </li>
-<li>
- if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) stopclock<thread_clock>
- _;
- </li>
-<li>
- else stopclock<process_real_cpu_clock> _;
- </li>
-<li>
- endif
- </li>
-</ol></div>
-</li>
-<li>
+ library provide a <code class="computeroutput"><span class="identifier">thread_clock</span></code>
+ that returns the time spent by the thread on platforms providing this
+ kind of data. It can be used as follows
+ </li></ul></div>
+<p>
+
+</p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">thread_clock</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+<span class="special">...</span>
+<span class="preprocessor">#if</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_CHRONO_HAS_THREAD_CLOCK</span><span class="special">)</span>
+ <span class="identifier">stopclock</span><span class="special"><</span><span class="identifier">thread_clock</span><span class="special">></span> <span class="identifier">_</span><span class="special">;</span>
+<span class="preprocessor">#else</span>
+ <span class="identifier">stopclock</span><span class="special"><</span><span class="identifier">process_real_cpu_clock</span><span class="special">></span> <span class="identifier">_</span><span class="special">;</span>
+<span class="preprocessor">#endif</span>
+</pre>
+<p>
+ </p>
+<div class="itemizedlist"><ul type="disc"><li>
Nested stopclocks (usually nested function calls where each function
contains a stopclock). When the nesting is deep enough, the cumulative
overhead of all the stopclock functionality make the data unreliable
except for the inner-most trace points. The question is, how much time
is related to the application code we want to measure and how much to
the fact we are meassuring and logging in inner blocks?
- </li>
-</ol></div>
+ </li></ul></div>
<p>
Some measures let us think that most of the time spent by the stopclock
mechanism is associated to the logging part. There are two things we can
@@ -896,7 +931,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="../overview.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../overview.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="caveat_emptor.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="../overview.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../overview.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="caveat.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
</body>
</html>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -6,7 +6,7 @@
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
<link rel="start" href="../index.html" title="Boost.Chrono">
<link rel="up" href="../index.html" title="Boost.Chrono">
-<link rel="prev" href="users_guide/ext_references.html" title=" References">
+<link rel="prev" href="users_guide/ext_references.html" title=" External Resources">
<link rel="next" href="reference/cpp0x.html" title=" Included on the C++0x
recommendation">
</head>
@@ -38,18 +38,29 @@
<dt><span class="section"><a href="reference/cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp"> Header
<code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
<dt><span class="section"><a href="reference/cpp0x.html#boost_chrono.reference.cpp0x.chrono_typeof_hpp"> Header
- <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">typeof</span><span class="special">/</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">chorno</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+ <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">typeof</span><span class="special">/</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
</dl></dd>
<dt><span class="section">Other clocks</span></dt>
-<dd><dl><dt><span class="section"><a href="reference/other_clocks.html#boost_chrono.reference.other_clocks.process_cpu_clocks_hpp">
- Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">process_cpu_clocks</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt></dl></dd>
+<dd><dl>
+<dt><span class="section"><a href="reference/other_clocks.html#boost_chrono.reference.other_clocks.process_cpu_clocks_hpp">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">process_cpu_clocks</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dt><span class="section"><a href="reference/other_clocks.html#boost_chrono.reference.other_clocks.thread_clock_hpp">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">thread_clock</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dt><span class="section"><a href="reference/other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_req">
+ <code class="computeroutput"><span class="identifier">SuspendibleClock</span></code> requirements</a></span></dt>
+<dt><span class="section"><a href="reference/other_clocks.html#boost_chrono.reference.other_clocks.scoped_suspend_hpp">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">scoped_suspend</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dt><span class="section"><a href="reference/other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_hpp">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">suspendible_clock</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+</dl></dd>
<dt><span class="section">Stopwatches</span></dt>
<dd><dl>
<dt><span class="section"><a href="reference/stopwatches.html#boost_chrono.reference.stopwatches.stopwatches_hpp">
Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">stopwatches</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
<dt><span class="section"><a href="reference/stopwatches.html#boost_chrono.reference.stopwatches.chrono_stopwatches_hpp">
Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">stopwatches</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
-<dt><span class="section">Stopwatch
Requirements</span></dt>
+<dt><span class="section"><a href="reference/stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req">
+ <code class="computeroutput"><span class="identifier">Stopwatch</span></code> Requirements</a></span></dt>
<dt><span class="section"><a href="reference/stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_hpp">
Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">stopwatch</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
<dt><span class="section"><a href="reference/stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_accumulator_hpp">
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/cpp0x.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/cpp0x.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/cpp0x.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -49,7 +49,8 @@
<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp"> Header
<code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
<dd><dl>
-<dt><span class="section">Clock
Requirements</span></dt>
+<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.clock">
+ <code class="computeroutput"><span class="identifier">Clock</span></code> Requirements</a></span></dt>
<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.time_related_traits">Time-related
traits</a></span></dt>
<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class_template__duration_">Class
@@ -68,13 +69,15 @@
comparisons</a></span></dt>
<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_">Class
<code class="computeroutput"><span class="identifier">system_clock</span></code></a></span></dt>
+<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.macro__boost_chrono_has_clock_monotonic_">Macro
+ <code class="computeroutput"><span class="identifier">BOOST_CHRONO_HAS_CLOCK_MONOTONIC</span></code></a></span></dt>
<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__monotonic_clock_">Class
<code class="computeroutput"><span class="identifier">monotonic_clock</span></code></a></span></dt>
<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__high_resolution_clock_">Class
<code class="computeroutput"><span class="identifier">high_resolution_clock</span></code></a></span></dt>
</dl></dd>
<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_typeof_hpp"> Header
- <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">typeof</span><span class="special">/</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">chorno</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+ <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">typeof</span><span class="special">/</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
</dl></div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
@@ -434,7 +437,8 @@
<code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>
</h4></div></div></div>
<div class="toc"><dl>
-<dt><span class="section">Clock
Requirements</span></dt>
+<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.clock">
+ <code class="computeroutput"><span class="identifier">Clock</span></code> Requirements</a></span></dt>
<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.time_related_traits">Time-related
traits</a></span></dt>
<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class_template__duration_">Class
@@ -453,12 +457,17 @@
comparisons</a></span></dt>
<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_">Class
<code class="computeroutput"><span class="identifier">system_clock</span></code></a></span></dt>
+<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.macro__boost_chrono_has_clock_monotonic_">Macro
+ <code class="computeroutput"><span class="identifier">BOOST_CHRONO_HAS_CLOCK_MONOTONIC</span></code></a></span></dt>
<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__monotonic_clock_">Class
<code class="computeroutput"><span class="identifier">monotonic_clock</span></code></a></span></dt>
<dt><span class="section"><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__high_resolution_clock_">Class
<code class="computeroutput"><span class="identifier">high_resolution_clock</span></code></a></span></dt>
</dl></div>
-<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
+<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_SYSTEM_CLOCK_DURATION</span>
+<span class="preprocessor">#define</span> <span class="identifier">BOOST_CHRONO_HAS_CLOCK_MONOTONIC</span>
+
+<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
<span class="keyword">namespace</span> <span class="identifier">chrono</span> <span class="special">{</span>
<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span> <span class="special">=</span> <span class="identifier">ratio</span><span class="special"><</span><span class="number">1</span><span class="special">></span> <span class="special">></span> <span class="keyword">class</span> <span class="identifier">duration</span><span class="special">;</span>
@@ -589,7 +598,9 @@
</pre>
<div class="section" lang="en">
<div class="titlepage"><div><div><h5 class="title">
-<a name="boost_chrono.reference.cpp0x.chrono_chrono_hpp._clock__requirements"></a>Clock
Requirements
+<a name="boost_chrono.reference.cpp0x.chrono_chrono_hpp.clock"></a><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.clock" title="
+ Clock Requirements">
+ <code class="computeroutput"><span class="identifier">Clock</span></code> Requirements</a>
</h5></div></div></div>
<p>
A clock represents a bundle consisting of a native <code class="computeroutput"><span class="identifier">duration</span></code>,
@@ -608,7 +619,7 @@
and both of these calls happen before <code class="computeroutput"><span class="identifier">C1</span><span class="special">::</span><span class="identifier">time_point</span><span class="special">::</span><span class="identifier">max</span><span class="special">()</span></code>.
</p>
<div class="table">
-<a name="id4837668"></a><p class="title"><b>Table 1. Clock Requirements</b></p>
+<a name="id4866118"></a><p class="title"><b>Table 1. Clock Requirements</b></p>
<table class="table" summary="Clock Requirements">
<colgroup>
<col>
@@ -752,6 +763,18 @@
</tbody>
</table>
</div>
+<p>
+ Models of Clock:
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>system_clock</li>
+<li>monotonic_clock</li>
+<li>high_resolution_clock</li>
+<li>process_real_cpu_clock</li>
+<li>process_user_cpu_clock</li>
+<li>process_system_cpu_clock</li>
+<li>thread_clock</li>
+</ul></div>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h5 class="title">
@@ -1794,7 +1817,8 @@
<span class="special">};</span>
</pre>
<p>
- Clock must meet the Clock Requirements.
+ Clock must meet the <a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_" target="_top">Clock
+ Requirements</a>.
</p>
<p>
Duration must be an instantiation of <code class="computeroutput"><span class="identifier">duration</span></code>,
@@ -2162,7 +2186,8 @@
</pre>
<p>
<code class="computeroutput"><span class="identifier">system_clock</span></code> satisfy
- the Clock Requirements. In addition:
+ the <a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_" target="_top">Clock
+ Requirements</a>. In addition:
</p>
<div class="itemizedlist"><ul type="disc"><li>
<code class="computeroutput"><span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">duration</span><span class="special">::</span><span class="identifier">min</span><span class="special">()</span> <span class="special"><</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">duration</span><span class="special">::</span><span class="identifier">zero</span><span class="special">()</span></code> is <code class="computeroutput"><span class="keyword">true</span></code>.
@@ -2203,13 +2228,24 @@
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.reference.cpp0x.chrono_chrono_hpp.macro__boost_chrono_has_clock_monotonic_"></a><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.macro__boost_chrono_has_clock_monotonic_" title="Macro
+ BOOST_CHRONO_HAS_CLOCK_MONOTONIC">Macro
+ <code class="computeroutput"><span class="identifier">BOOST_CHRONO_HAS_CLOCK_MONOTONIC</span></code></a>
+</h5></div></div></div>
+<p>
+ Defined if the platform support monotonic clocks.
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
<a name="boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__monotonic_clock_"></a><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__monotonic_clock_" title="Class
monotonic_clock">Class
<code class="computeroutput"><span class="identifier">monotonic_clock</span></code></a>
</h5></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">monotonic_clock</span></code> satisfy
- the Clock Requirements.
+ the <a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_" target="_top">Clock
+ Requirements</a>.
</p>
<p>
<code class="computeroutput"><span class="identifier">monotonic_clock</span></code> class
@@ -2240,7 +2276,8 @@
</h5></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">high_resolution_clock</span></code>
- satisfy the Clock Requirements.
+ satisfy the <a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_" target="_top">Clock
+ Requirements</a>.
</p>
<pre class="programlisting"><span class="preprocessor">#ifdef</span> <span class="identifier">BOOST_CHRONO_HAS_CLOCK_MONOTONIC</span>
<span class="keyword">typedef</span> <span class="identifier">monotonic_clock</span> <span class="identifier">high_resolution_clock</span><span class="special">;</span> <span class="comment">// as permitted by [time.clock.hires]
@@ -2253,8 +2290,8 @@
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
<a name="boost_chrono.reference.cpp0x.chrono_typeof_hpp"></a><a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_typeof_hpp" title=" Header
- <boost/chrono/typeof/boost/chrono/chorno.hpp>"> Header
- <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">typeof</span><span class="special">/</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">chorno</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>
+ <boost/chrono/typeof/boost/chrono/chrono.hpp>"> Header
+ <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">typeof</span><span class="special">/</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>
</h4></div></div></div>
<p>
Register <code class="computeroutput"><span class="identifier">duration</span><span class="special"><></span></code>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/deprecated_headers.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/deprecated_headers.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/deprecated_headers.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -9,7 +9,7 @@
<link rel="up" href="../reference.html" title=" Reference ">
<link rel="prev" href="stopwatch_formatters.html" title="Stopwatch
Formatters">
-<link rel="next" href="../examples.html" title="Examples">
+<link rel="next" href="../appendices.html" title="Appendices">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
@@ -22,7 +22,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="stopwatch_formatters.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../examples.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="stopwatch_formatters.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../appendices.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
@@ -166,7 +166,7 @@
</p>
<p>
<code class="computeroutput"><span class="identifier">process_clock</span></code> provides
- a thin wrapper around the operating system's process timer API. For POSIX-like
+ a thin wrapper around the operating system's process time API. For POSIX-like
systems, that's the times() function, while for Windows, it's the GetProcessTimes()
function.
</p>
@@ -349,7 +349,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="stopwatch_formatters.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../examples.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="stopwatch_formatters.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../appendices.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
</body>
</html>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/other_clocks.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/other_clocks.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/other_clocks.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -40,6 +40,38 @@
<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.process_cpu_clocks_hpp.class__process_cpu_clock_">Class
<code class="computeroutput"><span class="identifier">process_cpu_clock</span></code></a></span></dt>
</dl></dd>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.thread_clock_hpp">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">thread_clock</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dd><dl>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.thread_clock_hpp.macro__boost_chrono_has_thread_clock_">Macro
+ <code class="computeroutput"><span class="identifier">BOOST_CHRONO_HAS_THREAD_CLOCK</span></code></a></span></dt>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.thread_clock_hpp.macro__boost_chrono_thread_clock_is_monotonic_">Macro
+ <code class="computeroutput"><span class="identifier">BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC</span></code></a></span></dt>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.thread_clock_hpp.class__thread_clock_">Class
+ <code class="computeroutput"><span class="identifier">thread_clock</span></code></a></span></dt>
+</dl></dd>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_req">
+ <code class="computeroutput"><span class="identifier">SuspendibleClock</span></code> requirements</a></span></dt>
+<dd><dl>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_req.SuspendibleClock_suspend">
+ Static Member Function <code class="computeroutput"><span class="identifier">suspend</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_req.SuspendibleClock_resume">
+ Static Member Function <code class="computeroutput"><span class="identifier">resume</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_req.SuspendibleClock_suspended">
+ Static Member Function <code class="computeroutput"><span class="identifier">suspended</span><span class="special">()</span></code></a></span></dt>
+</dl></dd>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.scoped_suspend_hpp">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">scoped_suspend</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dd><dl>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.scoped_suspend_hpp.meta_function_class__is_suspendible_">Meta
+ Function Class <code class="computeroutput"><span class="identifier">is_suspendible</span></code></a></span></dt>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.scoped_suspend_hpp.template_class__scoped_suspend_">Template
+ Class <code class="computeroutput"><span class="identifier">scoped_suspend</span></code></a></span></dt>
+</dl></dd>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_hpp">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">suspendible_clock</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
+<dd><dl><dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_hpp.template_class__suspendible_clock___">Template
+ Class <code class="computeroutput"><span class="identifier">suspendible_clock</span><span class="special"><></span></code></a></span></dt></dl></dd>
</dl></div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
@@ -80,7 +112,8 @@
</h5></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">process_real_cpu_clock</span></code>
- satisfy the Clock Requirements.
+ satisfy the <a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_" target="_top">Clock
+ Requirements</a>.
</p>
<p>
<code class="computeroutput"><span class="identifier">process_real_cpu_clock</span></code>
@@ -108,7 +141,8 @@
</h5></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">process_user_cpu_clock</span></code>
- satisfy the Clock Requirements.
+ satisfy the <a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_" target="_top">Clock
+ Requirements</a>.
</p>
<p>
<code class="computeroutput"><span class="identifier">process_user_cpu_clock</span></code>
@@ -136,7 +170,8 @@
</h5></div></div></div>
<p>
<code class="computeroutput"><span class="identifier">process_system_cpu_clock</span></code>
- satisfy the Clock Requirements.
+ satisfy the <a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_" target="_top">Clock
+ Requirements</a>.
</p>
<p>
<code class="computeroutput"><span class="identifier">process_system_cpu_clock</span></code>
@@ -174,7 +209,7 @@
</p>
<p>
<code class="computeroutput"><span class="identifier">process_cpu_clock</span></code> provides
- a thin wrapper around the operating system's process timer API. For POSIX-like
+ a thin wrapper around the operating system's process time API. For POSIX-like
systems, that's the times() function, while for Windows, it's the GetProcessTimes()
function.
</p>
@@ -255,6 +290,359 @@
</div>
</div>
</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.reference.other_clocks.thread_clock_hpp"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.thread_clock_hpp" title="
+ Header <boost/chrono/thread_clock.hpp>">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">thread_clock</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>
+</h4></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.thread_clock_hpp.macro__boost_chrono_has_thread_clock_">Macro
+ <code class="computeroutput"><span class="identifier">BOOST_CHRONO_HAS_THREAD_CLOCK</span></code></a></span></dt>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.thread_clock_hpp.macro__boost_chrono_thread_clock_is_monotonic_">Macro
+ <code class="computeroutput"><span class="identifier">BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC</span></code></a></span></dt>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.thread_clock_hpp.class__thread_clock_">Class
+ <code class="computeroutput"><span class="identifier">thread_clock</span></code></a></span></dt>
+</dl></div>
+<p>
+ Knowing the time a thread takes to execute is useful in both test and production
+ environments.
+ </p>
+<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">BOOST_CHRONO_HAS_THREAD_CLOCK</span>
+<span class="preprocessor">#define</span> <span class="identifier">BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC</span>
+<span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">chrono</span> <span class="special">{</span>
+
+ <span class="keyword">class</span> <span class="identifier">thread_clock</span><span class="special">;</span>
+
+<span class="special">}</span> <span class="special">}</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.reference.other_clocks.thread_clock_hpp.macro__boost_chrono_has_thread_clock_"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.thread_clock_hpp.macro__boost_chrono_has_thread_clock_" title="Macro
+ BOOST_CHRONO_HAS_THREAD_CLOCK">Macro
+ <code class="computeroutput"><span class="identifier">BOOST_CHRONO_HAS_THREAD_CLOCK</span></code></a>
+</h5></div></div></div>
+<p>
+ This macro is defined if the platform supports thread clocks.
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.reference.other_clocks.thread_clock_hpp.macro__boost_chrono_thread_clock_is_monotonic_"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.thread_clock_hpp.macro__boost_chrono_thread_clock_is_monotonic_" title="Macro
+ BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC">Macro
+ <code class="computeroutput"><span class="identifier">BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC</span></code></a>
+</h5></div></div></div>
+<p>
+ This macro is defined if the platform has a thread clockIts value is
+ true if it is monotonic and false otherwise.
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.reference.other_clocks.thread_clock_hpp.class__thread_clock_"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.thread_clock_hpp.class__thread_clock_" title="Class
+ thread_clock">Class
+ <code class="computeroutput"><span class="identifier">thread_clock</span></code></a>
+</h5></div></div></div>
+<p>
+ <code class="computeroutput"><span class="identifier">thread_clock</span></code> satisfy
+ the <a href="cpp0x.html#boost_chrono.reference.cpp0x.chrono_chrono_hpp.class__system_clock_" target="_top">Clock
+ Requirements</a>.
+ </p>
+<p>
+ <code class="computeroutput"><span class="identifier">thread_clock</span></code> class provides
+ access to the real thread wall-clock, i.e. the real CPU-time clock of
+ the calling thread. The thread relative current time can be obtained
+ by calling <code class="computeroutput"><span class="identifier">thread_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()</span></code>.
+ </p>
+<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">thread_clock</span> <span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">typedef</span> <span class="identifier">nanoseconds</span> <span class="identifier">duration</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">duration</span><span class="special">::</span><span class="identifier">rep</span> <span class="identifier">rep</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">duration</span><span class="special">::</span><span class="identifier">period</span> <span class="identifier">period</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">thread_clock</span><span class="special">></span> <span class="identifier">time_point</span><span class="special">;</span>
+ <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_monotonic</span> <span class="special">=</span> <span class="identifier">BOOST_CHRONO_THREAD_CLOCK_IS_MONOTONIC</span><span class="special">;</span>
+
+ <span class="keyword">static</span> <span class="identifier">time_point</span> <span class="identifier">now</span><span class="special">(</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">=</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span> <span class="special">);</span>
+<span class="special">};</span>
+</pre>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.reference.other_clocks.suspendible_clock_req"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_req" title="
+ SuspendibleClock requirements">
+ <code class="computeroutput"><span class="identifier">SuspendibleClock</span></code> requirements</a>
+</h4></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_req.SuspendibleClock_suspend">
+ Static Member Function <code class="computeroutput"><span class="identifier">suspend</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_req.SuspendibleClock_resume">
+ Static Member Function <code class="computeroutput"><span class="identifier">resume</span><span class="special">()</span></code></a></span></dt>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_req.SuspendibleClock_suspended">
+ Static Member Function <code class="computeroutput"><span class="identifier">suspended</span><span class="special">()</span></code></a></span></dt>
+</dl></div>
+<p>
+ A <code class="computeroutput"><span class="identifier">SuspendibleClock</span></code> is a
+ Clock that in addition supports <code class="computeroutput"><span class="identifier">suspend</span></code>/<code class="computeroutput"><span class="identifier">resume</span></code> operations.
+ </p>
+<p>
+ A <code class="computeroutput"><span class="identifier">SuspendibleClock</span></code> must
+ meet the requirements in the following Table.
+ </p>
+<p>
+ In this table <code class="computeroutput"><span class="identifier">C</span></code> denote
+ <code class="computeroutput"><span class="identifier">clock</span></code> types.
+ </p>
+<div class="table">
+<a name="id4889842"></a><p class="title"><b>Table 2. SuspendibleClock Requirements</b></p>
+<table class="table" summary="SuspendibleClock Requirements">
+<colgroup>
+<col>
+<col>
+<col>
+</colgroup>
+<thead><tr>
+<th>
+ <p>
+ expression
+ </p>
+ </th>
+<th>
+ <p>
+ return type
+ </p>
+ </th>
+<th>
+ <p>
+ operational semantics
+ </p>
+ </th>
+</tr></thead>
+<tbody>
+<tr>
+<td>
+ <p>
+ <code class="computeroutput"><span class="identifier">C</span><span class="special">::</span><span class="identifier">suspend</span><span class="special">()</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ <code class="computeroutput"><span class="keyword">void</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ Suspends the time counting of the clock C.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <code class="computeroutput"><span class="identifier">C</span><span class="special">::</span><span class="identifier">resume</span><span class="special">()</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ <code class="computeroutput"><span class="keyword">void</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ Resumes the time counting of the clock C.
+ </p>
+ </td>
+</tr>
+<tr>
+<td>
+ <p>
+ <code class="computeroutput"><span class="identifier">C</span><span class="special">::</span><span class="identifier">suspended</span><span class="special">()</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ <code class="computeroutput"><span class="identifier">duration</span></code>
+ </p>
+ </td>
+<td>
+ <p>
+ Returns the delay(duration during which the clock has been suspended.
+ </p>
+ </td>
+</tr>
+</tbody>
+</table>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.reference.other_clocks.suspendible_clock_req.SuspendibleClock_suspend"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_req.SuspendibleClock_suspend" title="
+ Static Member Function suspend()">
+ Static Member Function <code class="computeroutput"><span class="identifier">suspend</span><span class="special">()</span></code></a>
+</h5></div></div></div>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">suspend</span><span class="special">(</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">=</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span> <span class="special">);</span>
+</pre>
+<p>
+ <span class="bold"><strong>Effect:</strong></span> Suspends the SuspendibleClock.
+ </p>
+<p>
+ <span class="bold"><strong>Throw:</strong></span> Any exception the <code class="computeroutput"><span class="identifier">Clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">(</span><span class="identifier">ec</span><span class="special">)</span></code>
+ function can throw. Otherwise <code class="computeroutput"><span class="identifier">ec</span></code>
+ is set with the correspoding error code set by <code class="computeroutput"><span class="identifier">Clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">(</span><span class="identifier">ec</span><span class="special">)</span></code>.
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.reference.other_clocks.suspendible_clock_req.SuspendibleClock_resume"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_req.SuspendibleClock_resume" title="
+ Static Member Function resume()">
+ Static Member Function <code class="computeroutput"><span class="identifier">resume</span><span class="special">()</span></code></a>
+</h5></div></div></div>
+<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">resume</span><span class="special">(</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">=</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span> <span class="special">);</span>
+</pre>
+<p>
+ <span class="bold"><strong>Effect:</strong></span> Resumes the <code class="computeroutput"><span class="identifier">SuspendibleClock</span></code>.
+ </p>
+<p>
+ <span class="bold"><strong>Throw:</strong></span> Any exception the <code class="computeroutput"><span class="identifier">Clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">(</span><span class="identifier">ec</span><span class="special">)</span></code>
+ can throw. Otherwise <code class="computeroutput"><span class="identifier">ec</span></code>
+ is set with the correspoding error code set by <code class="computeroutput"><span class="identifier">Clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">(</span><span class="identifier">ec</span><span class="special">)</span></code>.
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.reference.other_clocks.suspendible_clock_req.SuspendibleClock_suspended"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_req.SuspendibleClock_suspended" title="
+ Static Member Function suspended()">
+ Static Member Function <code class="computeroutput"><span class="identifier">suspended</span><span class="special">()</span></code></a>
+</h5></div></div></div>
+<pre class="programlisting"><span class="identifier">duration</span> <span class="identifier">suspended</span><span class="special">(</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">=</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span> <span class="special">);</span>
+</pre>
+<p>
+ <span class="bold"><strong>Returns:</strong></span> the cumalative elapsed duration
+ during which the <code class="computeroutput"><span class="identifier">SuspendibleClock</span></code>
+ has been suspendeed.
+ </p>
+<p>
+ <span class="bold"><strong>Throw:</strong></span> Any exception the Clock::now
+ function can throw if <code class="computeroutput"><span class="identifier">ec</span> <span class="special">==</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span></code>.
+ Otherwise <code class="computeroutput"><span class="identifier">ec</span></code> is set with
+ the correspoding error code set by <code class="computeroutput"><span class="identifier">Clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">(</span><span class="identifier">ec</span><span class="special">)</span></code>.
+ </p>
+</div>
+<p>
+ Models of <code class="computeroutput"><span class="identifier">SuspendibleClock</span></code>:
+ </p>
+<div class="itemizedlist"><ul type="disc"><li>suspendible_clock<Clock>
</li></ul></div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.reference.other_clocks.scoped_suspend_hpp"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.scoped_suspend_hpp" title="
+ Header <boost/chrono/scoped_suspend.hpp>">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">scoped_suspend</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>
+</h4></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.scoped_suspend_hpp.meta_function_class__is_suspendible_">Meta
+ Function Class <code class="computeroutput"><span class="identifier">is_suspendible</span></code></a></span></dt>
+<dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.scoped_suspend_hpp.template_class__scoped_suspend_">Template
+ Class <code class="computeroutput"><span class="identifier">scoped_suspend</span></code></a></span></dt>
+</dl></div>
+<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">chrono</span> <span class="special">{</span>
+ <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">></span> <span class="keyword">struct</span> <span class="identifier">is_suspendible</span><span class="special">;</span>
+ <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">></span> <span class="keyword">class</span> <span class="identifier">scoped_suspend</span><span class="special">;</span>
+<span class="special">}}</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.reference.other_clocks.scoped_suspend_hpp.meta_function_class__is_suspendible_"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.scoped_suspend_hpp.meta_function_class__is_suspendible_" title="Meta
+ Function Class is_suspendible">Meta
+ Function Class <code class="computeroutput"><span class="identifier">is_suspendible</span></code></a>
+</h5></div></div></div>
+<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">></span>
+<span class="keyword">struct</span> <span class="identifier">is_suspendible</span> <span class="special">:</span> <span class="identifier">mpl</span><span class="special">::</span> <span class="identifier">false_</span> <span class="special">{};</span>
+</pre>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.reference.other_clocks.scoped_suspend_hpp.template_class__scoped_suspend_"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.scoped_suspend_hpp.template_class__scoped_suspend_" title="Template
+ Class scoped_suspend">Template
+ Class <code class="computeroutput"><span class="identifier">scoped_suspend</span></code></a>
+</h5></div></div></div>
+<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">></span>
+<span class="keyword">class</span> <span class="identifier">scoped_suspend</span> <span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">scoped_suspend</span><span class="special">(</span><span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">=</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span><span class="special">)</span> <span class="special">{}</span>
+ <span class="special">~</span><span class="identifier">scoped_suspend</span><span class="special">()</span> <span class="special">{}</span>
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">scoped_suspend</span><span class="special">();</span> <span class="comment">// = delete;
+</span> <span class="identifier">scoped_suspend</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">scoped_suspend</span><span class="special">&);</span> <span class="comment">// = delete;
+</span> <span class="identifier">scoped_suspend</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">=(</span><span class="keyword">const</span> <span class="identifier">scoped_suspend</span><span class="special">&);</span> <span class="comment">// = delete;
+</span><span class="special">};</span>
+</pre>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.reference.other_clocks.suspendible_clock_hpp"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_hpp" title="
+ Header <boost/chrono/suspendible_clock.hpp>">
+ Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">suspendible_clock</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a>
+</h4></div></div></div>
+<div class="toc"><dl><dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_hpp.template_class__suspendible_clock___">Template
+ Class <code class="computeroutput"><span class="identifier">suspendible_clock</span><span class="special"><></span></code></a></span></dt></dl></div>
+<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">chrono</span> <span class="special">{</span>
+
+ <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">></span>
+ <span class="keyword">class</span> <span class="identifier">suspendible_clock</span><span class="special">;</span>
+
+ <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">></span>
+ <span class="keyword">struct</span> <span class="identifier">is_suspendible</span><span class="special"><</span><span class="identifier">suspendible_clock</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">></span> <span class="special">></span> <span class="special">:</span> <span class="identifier">mpl</span><span class="special">::</span> <span class="identifier">true_</span> <span class="special">{};</span>
+
+ <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">></span>
+ <span class="keyword">class</span> <span class="identifier">scoped_suspend</span><span class="special"><</span><span class="identifier">suspendible_clock</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">></span> <span class="special">>;</span>
+
+<span class="special">}}</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.reference.other_clocks.suspendible_clock_hpp.template_class__suspendible_clock___"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_hpp.template_class__suspendible_clock___" title="Template
+ Class suspendible_clock<>">Template
+ Class <code class="computeroutput"><span class="identifier">suspendible_clock</span><span class="special"><></span></code></a>
+</h5></div></div></div>
+<div class="toc"><dl><dt><span class="section"><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_hpp.template_class__suspendible_clock___._scoped_suspend__specialization_for__suspendible_clock___"><code class="computeroutput"><span class="identifier">scoped_suspend</span></code> specialization for
+ <code class="computeroutput"><span class="identifier">suspendible_clock</span><span class="special"><></span></code></a></span></dt></dl></div>
+<p>
+ Given a <code class="computeroutput"><span class="identifier">Clock</span></code>, <code class="computeroutput"><span class="identifier">suspendible_clock</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">></span></code>
+ is a model of SuspendibleClock.
+ </p>
+<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span> <span class="keyword">class</span> <span class="identifier">Clock</span> <span class="special">></span>
+<span class="keyword">class</span> <span class="identifier">suspendible_clock</span> <span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">duration</span> <span class="identifier">duration</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">rep</span> <span class="identifier">rep</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">period</span> <span class="identifier">period</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">suspendible_clock</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">></span> <span class="special">></span> <span class="identifier">time_point</span><span class="special">;</span>
+ <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_monotonic</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">;</span>
+
+ <span class="keyword">static</span> <span class="identifier">time_point</span> <span class="identifier">now</span><span class="special">(</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">=</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span> <span class="special">);</span>
+
+ <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">suspend</span><span class="special">(</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">=</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span> <span class="special">);</span>
+ <span class="keyword">static</span> <span class="keyword">void</span> <span class="identifier">resume</span><span class="special">(</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">=</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span> <span class="special">);</span>
+ <span class="keyword">static</span> <span class="identifier">duration</span> <span class="identifier">suspended</span><span class="special">(</span><span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">=</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span><span class="special">);</span>
+<span class="special">};</span>
+</pre>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h6 class="title">
+<a name="boost_chrono.reference.other_clocks.suspendible_clock_hpp.template_class__suspendible_clock___._scoped_suspend__specialization_for__suspendible_clock___"></a><a href="other_clocks.html#boost_chrono.reference.other_clocks.suspendible_clock_hpp.template_class__suspendible_clock___._scoped_suspend__specialization_for__suspendible_clock___" title="scoped_suspend specialization for
+ suspendible_clock<>"><code class="computeroutput"><span class="identifier">scoped_suspend</span></code> specialization for
+ <code class="computeroutput"><span class="identifier">suspendible_clock</span><span class="special"><></span></code></a>
+</h6></div></div></div>
+<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">></span>
+<span class="keyword">class</span> <span class="identifier">scoped_suspend</span><span class="special"><</span><span class="identifier">suspendible_clock</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">></span> <span class="special">></span> <span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">scoped_suspend</span><span class="special">(</span><span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">=</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span><span class="special">);</span>
+ <span class="special">~</span><span class="identifier">scoped_suspend</span><span class="special">();</span>
+<span class="special">};</span>
+</pre>
+</div>
+</div>
+</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/stopwatch_reporters.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/stopwatch_reporters.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/stopwatch_reporters.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -94,7 +94,7 @@
<code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span></code>, ec is a system::error_code
</p>
<div class="table">
-<a name="id4870154"></a><p class="title"><b>Table 3. Stopwatch Requirements</b></p>
+<a name="id4902237"></a><p class="title"><b>Table 4. Stopwatch Requirements</b></p>
<table class="table" summary="Stopwatch Requirements">
<colgroup>
<col>
@@ -194,6 +194,14 @@
</tbody>
</table>
</div>
+<p>
+ Models of <code class="computeroutput"><span class="identifier">Formatter</span></code>:
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>basic_stopwatch_formatter
</li>
+<li>basic_stopwatch_accumulator_formatter
</li>
+<li>basic_24_hours_formatter
</li>
+</ul></div>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
@@ -245,9 +253,9 @@
</h5></div></div></div>
<p>
class <code class="computeroutput"><span class="identifier">basic_stopwatch_reporter</span></code>
- provides a everything a Timer provides and it adds reporting capabilities
- that can be invoked in a single line of code. The reporting is controleed
- by two parameters:
+ provides a everything a <code class="computeroutput"><span class="identifier">Stopwatch</span></code>
+ provides and it adds reporting capabilities that can be invoked in a
+ single line of code. The reporting is controleed by two parameters:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
@@ -314,9 +322,9 @@
</h5></div></div></div>
<p>
class <code class="computeroutput"><span class="identifier">stopwatch_reporter</span></code>
- provides a everything a Timer provides and it adds reporting capabilities
- that can be invoked in a single line of code. The reporting is controleed
- by two parameters:
+ provides a everything a <code class="computeroutput"><span class="identifier">Stopwatch</span></code>
+ provides and it adds reporting capabilities that can be invoked in a
+ single line of code. The reporting is controleed by two parameters:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
@@ -400,9 +408,9 @@
</h5></div></div></div>
<p>
class <code class="computeroutput"><span class="identifier">wstopwatch_reporter</span></code>
- provides a everything a Timer provides and it adds reporting capabilities
- that can be invoked in a single line of code. The reporting is controleed
- by two parameters:
+ provides a everything a <code class="computeroutput"><span class="identifier">Stopwatch</span></code>
+ provides and it adds reporting capabilities that can be invoked in a
+ single line of code. The reporting is controleed by two parameters:
</p>
<div class="itemizedlist"><ul type="disc">
<li>
@@ -623,9 +631,9 @@
<div class="titlepage"><div><div><h5 class="title">
<a name="boost_chrono.reference.stopwatch_reporters.stopclock_hpp._stopclock__useful_typedefs"></a>stopclock
useful typedefs
</h5></div></div></div>
-<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">stopclock</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">system_clock</span> <span class="special">></span> <span class="identifier">system_stopwatch_reporter</span><span class="special">;</span>
+<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">stopclock</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">system_clock</span> <span class="special">></span> <span class="identifier">system_stopwatch_stopclock</span><span class="special">;</span>
<span class="preprocessor">#ifdef</span> <span class="identifier">BOOST_CHRONO_HAS_CLOCK_MONOTONIC</span>
-<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">stopclock</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">monotonic_clock</span> <span class="special">></span> <span class="identifier">monotonic_stopwatch_reporter</span><span class="special">;</span>
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">stopclock</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">monotonic_clock</span> <span class="special">></span> <span class="identifier">monotonic_stopwatch_stopclock</span><span class="special">;</span>
<span class="preprocessor">#endif</span>
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">stopclock</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">high_resolution_clock</span> <span class="special">></span> <span class="identifier">high_resolution_stopclock</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">stopclock</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">process_real_cpu_clock</span> <span class="special">></span> <span class="identifier">process_real_cpu_stopclock</span><span class="special">;</span>
@@ -688,9 +696,9 @@
<div class="titlepage"><div><div><h5 class="title">
<a name="boost_chrono.reference.stopwatch_reporters.stopclock_hpp._wstopclock__useful_typedefs"></a>wstopclock
useful typedefs
</h5></div></div></div>
-<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">wstopclock</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">system_clock</span> <span class="special">></span> <span class="identifier">system_stopwatch_reporter</span><span class="special">;</span>
+<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">wstopclock</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">system_clock</span> <span class="special">></span> <span class="identifier">system_stopwatch_wstopclock</span><span class="special">;</span>
<span class="preprocessor">#ifdef</span> <span class="identifier">BOOST_CHRONO_HAS_CLOCK_MONOTONIC</span>
-<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">wstopclock</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">monotonic_clock</span> <span class="special">></span> <span class="identifier">monotonic_stopwatch_reporter</span><span class="special">;</span>
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">wstopclock</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">monotonic_clock</span> <span class="special">></span> <span class="identifier">monotonic_stopwatch_wstopclock</span><span class="special">;</span>
<span class="preprocessor">#endif</span>
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">wstopclock</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">high_resolution_clock</span> <span class="special">></span> <span class="identifier">high_resolution_wstopclock</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">wstopclock</span><span class="special"><</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">process_real_cpu_clock</span> <span class="special">></span> <span class="identifier">process_real_cpu_wstopclock</span><span class="special">;</span>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/stopwatches.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/stopwatches.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/reference/stopwatches.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -32,17 +32,18 @@
Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">stopwatches</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches.chrono_stopwatches_hpp">
Header <code class="computeroutput"><span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">stopwatches</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span></code></a></span></dt>
-<dt><span class="section">Stopwatch
Requirements</span></dt>
+<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req">
+ <code class="computeroutput"><span class="identifier">Stopwatch</span></code> Requirements</a></span></dt>
<dd><dl>
-<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_start">
+<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_start">
Member Function <code class="computeroutput"><span class="identifier">start</span><span class="special">()</span></code></a></span></dt>
-<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_stop">
+<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_stop">
Member Function <code class="computeroutput"><span class="identifier">stop</span><span class="special">()</span></code></a></span></dt>
-<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_suspend">
+<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_suspend">
Member Function <code class="computeroutput"><span class="identifier">suspend</span><span class="special">()</span></code></a></span></dt>
-<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_resume">
+<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_resume">
Member Function <code class="computeroutput"><span class="identifier">resume</span><span class="special">()</span></code></a></span></dt>
-<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_restart">
+<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_restart">
Member Function <code class="computeroutput"><span class="identifier">restart</span><span class="special">()</span></code></a></span></dt>
</dl></dd>
<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_hpp">
@@ -108,18 +109,20 @@
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
-<a name="boost_chrono.reference.stopwatches._stopwatch__requirements"></a>Stopwatch
Requirements
+<a name="boost_chrono.reference.stopwatches.stopwatch_req"></a><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req" title="
+ Stopwatch Requirements">
+ <code class="computeroutput"><span class="identifier">Stopwatch</span></code> Requirements</a>
</h4></div></div></div>
<div class="toc"><dl>
-<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_start">
+<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_start">
Member Function <code class="computeroutput"><span class="identifier">start</span><span class="special">()</span></code></a></span></dt>
-<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_stop">
+<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_stop">
Member Function <code class="computeroutput"><span class="identifier">stop</span><span class="special">()</span></code></a></span></dt>
-<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_suspend">
+<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_suspend">
Member Function <code class="computeroutput"><span class="identifier">suspend</span><span class="special">()</span></code></a></span></dt>
-<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_resume">
+<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_resume">
Member Function <code class="computeroutput"><span class="identifier">resume</span><span class="special">()</span></code></a></span></dt>
-<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_restart">
+<dt><span class="section"><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_restart">
Member Function <code class="computeroutput"><span class="identifier">restart</span><span class="special">()</span></code></a></span></dt>
</dl></div>
<p>
@@ -135,7 +138,7 @@
is an instance of <code class="computeroutput"><span class="identifier">S</span></code>.
</p>
<div class="table">
-<a name="id4861424"></a><p class="title"><b>Table 2. Stopwatch Requirements</b></p>
+<a name="id4893436"></a><p class="title"><b>Table 3. Stopwatch Requirements</b></p>
<table class="table" summary="Stopwatch Requirements">
<colgroup>
<col>
@@ -320,7 +323,7 @@
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h5 class="title">
-<a name="boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_start"></a><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_start" title="
+<a name="boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_start"></a><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_start" title="
Member Function start()">
Member Function <code class="computeroutput"><span class="identifier">start</span><span class="special">()</span></code></a>
</h5></div></div></div>
@@ -339,7 +342,7 @@
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h5 class="title">
-<a name="boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_stop"></a><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_stop" title="
+<a name="boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_stop"></a><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_stop" title="
Member Function stop()">
Member Function <code class="computeroutput"><span class="identifier">stop</span><span class="special">()</span></code></a>
</h5></div></div></div>
@@ -358,7 +361,7 @@
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h5 class="title">
-<a name="boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_suspend"></a><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_suspend" title="
+<a name="boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_suspend"></a><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_suspend" title="
Member Function suspend()">
Member Function <code class="computeroutput"><span class="identifier">suspend</span><span class="special">()</span></code></a>
</h5></div></div></div>
@@ -374,7 +377,7 @@
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h5 class="title">
-<a name="boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_resume"></a><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_resume" title="
+<a name="boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_resume"></a><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_resume" title="
Member Function resume()">
Member Function <code class="computeroutput"><span class="identifier">resume</span><span class="special">()</span></code></a>
</h5></div></div></div>
@@ -393,7 +396,7 @@
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h5 class="title">
-<a name="boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_restart"></a><a href="stopwatches.html#boost_chrono.reference.stopwatches._stopwatch__requirements.stopwatch_restart" title="
+<a name="boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_restart"></a><a href="stopwatches.html#boost_chrono.reference.stopwatches.stopwatch_req.stopwatch_restart" title="
Member Function restart()">
Member Function <code class="computeroutput"><span class="identifier">restart</span><span class="special">()</span></code></a>
</h5></div></div></div>
@@ -410,6 +413,13 @@
function can throw.
</p>
</div>
+<p>
+ Models of <code class="computeroutput"><span class="identifier">Stopwatch</span></code>:
+ </p>
+<div class="itemizedlist"><ul type="disc">
+<li>stopwatch
</li>
+<li>stopwatch_accumulator
</li>
+</ul></div>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
@@ -458,7 +468,7 @@
Member Function <code class="computeroutput"><span class="identifier">elapsed</span><span class="special">()</span></code></a></span></dt></dl></div>
<p>
<code class="computeroutput"><span class="identifier">stopwatch</span><span class="special"><></span></code>
- is a model of a <code class="computeroutput"><span class="identifier">Stopwatch</span></code>.
+ is a model of a Stopwatch
.
</p>
<p>
Knowing how long a part of a program takes to execute is useful in both
@@ -482,7 +492,7 @@
<span class="keyword">explicit</span> <span class="identifier">stopwatch</span><span class="special">(</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">=</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span> <span class="special">);</span>
<span class="keyword">explicit</span> <span class="identifier">stopwatch</span><span class="special">(</span> <span class="keyword">const</span> <span class="identifier">dont_start_t</span><span class="special">&</span> <span class="identifier">t</span> <span class="special">);</span>
- <span class="special">~</span><span class="identifier">timer</span><span class="special">();</span>
+ <span class="special">~</span><span class="identifier">stopwatch</span><span class="special">();</span>
<span class="identifier">time_point</span> <span class="identifier">start</span><span class="special">(</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">=</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span> <span class="special">);</span>
<span class="identifier">duration</span> <span class="identifier">stop</span><span class="special">(</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">=</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">throws</span> <span class="special">);</span>
@@ -600,9 +610,9 @@
Member Function <code class="computeroutput"><span class="identifier">accumulated</span><span class="special">()</span></code></a></span></dt>
</dl></div>
<p>
- A <code class="computeroutput"><span class="identifier">stopwatch_accumulator</span><span class="special"><></span></code> is a model of a Stopwatch that
- allows to accumulate the time in several times instead of at once as
- it is the case of the class <code class="computeroutput"><span class="identifier">stopwatch</span><span class="special"><></span></code>.
+ A <code class="computeroutput"><span class="identifier">stopwatch_accumulator</span><span class="special"><></span></code> is a model of a Stopwatch
that allows to accumulate
+ the time in several times instead of at once as it is the case of the
+ class <code class="computeroutput"><span class="identifier">stopwatch</span><span class="special"><></span></code>.
</p>
<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">></span> <span class="keyword">class</span> <span class="identifier">stopwatch_accumulator</span> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -6,7 +6,7 @@
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
<link rel="start" href="../index.html" title="Boost.Chrono">
<link rel="up" href="../index.html" title="Boost.Chrono">
-<link rel="prev" href="overview/caveat_emptor.html" title="Caveat emptor">
+<link rel="prev" href="overview/caveat.html" title=" Caveat emptor">
<link rel="next" href="users_guide/getting_started.html" title=" Getting Started">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
@@ -20,7 +20,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="overview/caveat_emptor.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="users_guide/getting_started.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="overview/caveat.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="users_guide/getting_started.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
@@ -36,23 +36,41 @@
</dl></dd>
<dt><span class="section">Tutorial</span></dt>
<dd><dl>
-<dt><span class="section"><a href="users_guide/tutorial.html#boost_chrono.users_guide.tutorial.how_to_define_a_thread_clock">How
- to define a thread clock</a></span></dt>
-<dt><span class="section"><a href="users_guide/tutorial.html#boost_chrono.users_guide.tutorial.how_can_i_prefix_each_report_with__boost_current_function__function_signature_">How
- can I prefix each report with <code class="computeroutput"><span class="identifier">BOOST_CURRENT_FUNCTION</span></code>
- function signature?</a></span></dt>
-<dt><span class="section"><a href="users_guide/tutorial.html#boost_chrono.users_guide.tutorial.how_can_i_prefix_each_report_with____file_____line_____pattern_">How
- can I prefix each report with <code class="computeroutput"><span class="identifier">__FILE__</span><span class="special">[</span><span class="identifier">__LINE__</span><span class="special">]</span></code> pattern?</a></span></dt>
-<dt><span class="section"><a href="users_guide/tutorial.html#boost_chrono.users_guide.tutorial.can_i_use_an_stopclock_accumulator_which_is_not_static_">Can
- I use an stopclock accumulator which is not static?</a></span></dt>
-<dt><span class="section"><a href="users_guide/tutorial.html#boost_chrono.users_guide.tutorial.how_can_i_suspend_a_stopwatch_">How
- can I suspend a stopwatch?</a></span></dt>
-<dt><span class="section"><a href="users_guide/tutorial.html#boost_chrono.users_guide.tutorial.how_to_get_specific_statistics_from_stopwatches_accumulator_">How
- to get specific statistics from stopwatches accumulator?</a></span></dt>
-<dt><span class="section"><a href="users_guide/tutorial.html#boost_chrono.users_guide.tutorial.how_can_i_make_a_specific_formatter_when_the_default_do_not_satisfy_my_expectations">How
- can I make a specific formatter when the default do not satisfy my expectations</a></span></dt>
+<dt><span class="section"><a href="users_guide/tutorial.html#boost_chrono.users_guide.tutorial.common_type">Common
+ Type</a></span></dt>
+<dt><span class="section">Ratio</span></dt>
+<dt><span class="section"><a href="users_guide/tutorial.html#boost_chrono.users_guide.tutorial.clocks__time_point_and_duration">Clocks,
+ time_point and duration</a></span></dt>
+<dt><span class="section"><a href="users_guide/tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks">Stopwatches
+ and Stopclocks</a></span></dt>
+<dt><span class="section">Formatters</span></dt>
</dl></dd>
-<dt><span class="section"> References</span></dt>
+<dt><span class="section">Examples</span></dt>
+<dd><dl>
+<dt><span class="section">Clocks</span></dt>
+<dt><span class="section"><a href="users_guide/examples.html#boost_chrono.users_guide.examples.how_you_override_the_duration_s_default_constructor">How
+ you override the duration's default constructor</a></span></dt>
+<dt><span class="section"><a href="users_guide/examples.html#boost_chrono.users_guide.examples.min_utility">min
+ utility</a></span></dt>
+<dt><span class="section"><a href="users_guide/examples.html#boost_chrono.users_guide.examples.cycle_count">Cycle
+ count</a></span></dt>
+<dt><span class="section"><a href="users_guide/examples.html#boost_chrono.users_guide.examples.xtime_conversions">xtime
+ conversions</a></span></dt>
+<dt><span class="section">xtime_clock</span></dt>
+<dt><span class="section">runtime_resolution</span></dt>
+<dt><span class="section"><a href="users_guide/examples.html#boost_chrono.users_guide.examples.simulated_thread_interface_demonstration_program">Simulated
+ thread interface demonstration program</a></span></dt>
+<dt><span class="section">Saturating</span></dt>
+<dt><span class="section"><a href="users_guide/examples.html#boost_chrono.users_guide.examples.howard_hinnant_s_original_demonstration_program">Howard
+ Hinnant's original demonstration program</a></span></dt>
+<dt><span class="section"><a href="users_guide/examples.html#boost_chrono.users_guide.examples.a_tiny_program_that_times_how_long_until_a_key_is_struck">A
+ tiny program that times how long until a key is struck</a></span></dt>
+<dt><span class="section">stopclock_example.cpp</span></dt>
+<dt><span class="section">stopclock_example2.cpp</span></dt>
+<dt><span class="section"><a href="users_guide/examples.html#boost_chrono.users_guide.examples.time_command">time
+ command</a></span></dt>
+</dl></dd>
+<dt><span class="section"> External Resources</span></dt>
</dl></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
@@ -65,7 +83,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="overview/caveat_emptor.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="users_guide/getting_started.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="overview/caveat.html"><img src="../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="users_guide/getting_started.html"><img src="../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
</body>
</html>
Added: sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/examples.html
==============================================================================
--- (empty file)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/examples.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -0,0 +1,1151 @@
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
+<title>Examples</title>
+<link rel="stylesheet" href="../../../../../../doc/html/boostbook.css" type="text/css">
+<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
+<link rel="start" href="../../index.html" title="Boost.Chrono">
+<link rel="up" href="../users_guide.html" title=" Users'Guide">
+<link rel="prev" href="tutorial.html" title="Tutorial">
+<link rel="next" href="ext_references.html" title=" External Resources">
+</head>
+<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
+<table cellpadding="2" width="100%"><tr>
+<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
+<td align="center">Home</td>
+<td align="center">Libraries</td>
+<td align="center">People</td>
+<td align="center">FAQ</td>
+<td align="center">More</td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="tutorial.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../users_guide.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="ext_references.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h3 class="title">
+<a name="boost_chrono.users_guide.examples"></a>Examples
+</h3></div></div></div>
+<div class="toc"><dl>
+<dt><span class="section">Clocks</span></dt>
+<dd><dl><dt><span class="section">SI-units</span></dt></dl></dd>
+<dt><span class="section"><a href="examples.html#boost_chrono.users_guide.examples.how_you_override_the_duration_s_default_constructor">How
+ you override the duration's default constructor</a></span></dt>
+<dt><span class="section"><a href="examples.html#boost_chrono.users_guide.examples.min_utility">min
+ utility</a></span></dt>
+<dt><span class="section"><a href="examples.html#boost_chrono.users_guide.examples.cycle_count">Cycle
+ count</a></span></dt>
+<dt><span class="section"><a href="examples.html#boost_chrono.users_guide.examples.xtime_conversions">xtime
+ conversions</a></span></dt>
+<dt><span class="section">xtime_clock</span></dt>
+<dt><span class="section">runtime_resolution</span></dt>
+<dt><span class="section"><a href="examples.html#boost_chrono.users_guide.examples.simulated_thread_interface_demonstration_program">Simulated
+ thread interface demonstration program</a></span></dt>
+<dt><span class="section">Saturating</span></dt>
+<dt><span class="section"><a href="examples.html#boost_chrono.users_guide.examples.howard_hinnant_s_original_demonstration_program">Howard
+ Hinnant's original demonstration program</a></span></dt>
+<dt><span class="section"><a href="examples.html#boost_chrono.users_guide.examples.a_tiny_program_that_times_how_long_until_a_key_is_struck">A
+ tiny program that times how long until a key is struck</a></span></dt>
+<dt><span class="section">stopclock_example.cpp</span></dt>
+<dt><span class="section">stopclock_example2.cpp</span></dt>
+<dt><span class="section"><a href="examples.html#boost_chrono.users_guide.examples.time_command">time
+ command</a></span></dt>
+</dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.clocks"></a>Clocks
+</h4></div></div></div>
+<div class="toc"><dl><dt><span class="section">SI-units</span></dt></dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.users_guide.examples.clocks.si_units"></a>SI-units
+</h5></div></div></div>
+<p>
+ Type-safe "physics" code interoperating with boost::chrono::duration
+ types and taking advantage of the boost::ratio infrastructure and design
+ philosophy.
+ </p>
+<p>
+ length - mimics boost::chrono::duration except restricts representation
+ to double. Uses boost::ratio facilities for length units conversions.
+ </p>
+<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Ratio</span><span class="special">></span>
+<span class="keyword">class</span> <span class="identifier">length</span> <span class="special">{</span>
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">double</span> <span class="identifier">len_</span><span class="special">;</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">typedef</span> <span class="identifier">Ratio</span> <span class="identifier">ratio</span><span class="special">;</span>
+ <span class="identifier">length</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">len_</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">{}</span>
+ <span class="identifier">length</span><span class="special">(</span><span class="keyword">const</span> <span class="keyword">double</span><span class="special">&</span> <span class="identifier">len</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">len_</span><span class="special">(</span><span class="identifier">len</span><span class="special">)</span> <span class="special">{}</span>
+
+ <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">></span>
+ <span class="identifier">length</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">length</span><span class="special"><</span><span class="identifier">R</span><span class="special">>&</span> <span class="identifier">d</span><span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">len_</span><span class="special">(</span><span class="identifier">d</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special">*</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_divide</span><span class="special"><</span><span class="identifier">Ratio</span><span class="special">,</span> <span class="identifier">R</span><span class="special">>::</span><span class="identifier">type</span><span class="special">::</span><span class="identifier">den</span> <span class="special">/</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_divide</span><span class="special"><</span><span class="identifier">Ratio</span><span class="special">,</span> <span class="identifier">R</span><span class="special">>::</span><span class="identifier">type</span><span class="special">::</span><span class="identifier">num</span><span class="special">)</span> <span class="special">{}</span>
+
+ <span class="keyword">double</span> <span class="identifier">count</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">len_</span><span class="special">;}</span>
+
+ <span class="identifier">length</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">+=(</span><span class="keyword">const</span> <span class="identifier">length</span><span class="special">&</span> <span class="identifier">d</span><span class="special">)</span> <span class="special">{</span><span class="identifier">len_</span> <span class="special">+=</span> <span class="identifier">d</span><span class="special">.</span><span class="identifier">count</span><span class="special">();</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">length</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">-=(</span><span class="keyword">const</span> <span class="identifier">length</span><span class="special">&</span> <span class="identifier">d</span><span class="special">)</span> <span class="special">{</span><span class="identifier">len_</span> <span class="special">-=</span> <span class="identifier">d</span><span class="special">.</span><span class="identifier">count</span><span class="special">();</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+
+ <span class="identifier">length</span> <span class="keyword">operator</span><span class="special">+()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">length</span> <span class="keyword">operator</span><span class="special">-()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">length</span><span class="special">(-</span><span class="identifier">len_</span><span class="special">);}</span>
+
+ <span class="identifier">length</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">*=(</span><span class="keyword">double</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="special">{</span><span class="identifier">len_</span> <span class="special">*=</span> <span class="identifier">rhs</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">length</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">/=(</span><span class="keyword">double</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="special">{</span><span class="identifier">len_</span> <span class="special">/=</span> <span class="identifier">rhs</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+<span class="special">};</span>
+</pre>
+<p>
+ Sparse sampling of length units
+ </p>
+<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">length</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">1</span><span class="special">></span> <span class="special">></span> <span class="identifier">meter</span><span class="special">;</span> <span class="comment">// set meter as "unity"
+</span><span class="keyword">typedef</span> <span class="identifier">length</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">centi</span><span class="special">></span> <span class="identifier">centimeter</span><span class="special">;</span> <span class="comment">// 1/100 meter
+</span><span class="keyword">typedef</span> <span class="identifier">length</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">kilo</span><span class="special">></span> <span class="identifier">kilometer</span><span class="special">;</span> <span class="comment">// 1000 meters
+</span><span class="keyword">typedef</span> <span class="identifier">length</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">254</span><span class="special">,</span> <span class="number">10000</span><span class="special">></span> <span class="special">></span> <span class="identifier">inch</span><span class="special">;</span> <span class="comment">// 254/10000 meters
+</span></pre>
+<p>
+ length takes ratio instead of two integral types so that definitions
+ can be made like so:
+ </p>
+<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">length</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_multiply</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">12</span><span class="special">>,</span> <span class="identifier">inch</span><span class="special">::</span><span class="identifier">ratio</span><span class="special">>::</span><span class="identifier">type</span><span class="special">></span> <span class="identifier">foot</span><span class="special">;</span> <span class="comment">// 12 inchs
+</span><span class="keyword">typedef</span> <span class="identifier">length</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_multiply</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">5280</span><span class="special">>,</span> <span class="identifier">foot</span><span class="special">::</span><span class="identifier">ratio</span><span class="special">>::</span><span class="identifier">type</span><span class="special">></span> <span class="identifier">mile</span><span class="special">;</span> <span class="comment">// 5280 feet
+</span></pre>
+<p>
+ Need a floating point definition of seconds
+ </p>
+<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">seconds</span><span class="special">;</span> <span class="comment">// unity
+</span></pre>
+<p>
+ Demo of (scientific) support for sub-nanosecond resolutions
+ </p>
+<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="keyword">double</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">pico</span><span class="special">></span> <span class="identifier">picosecond</span><span class="special">;</span> <span class="comment">// 10^-12 seconds
+</span><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="keyword">double</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">femto</span><span class="special">></span> <span class="identifier">femtosecond</span><span class="special">;</span> <span class="comment">// 10^-15 seconds
+</span><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="keyword">double</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">atto</span><span class="special">></span> <span class="identifier">attosecond</span><span class="special">;</span> <span class="comment">// 10^-18 seconds
+</span></pre>
+<p>
+ A very brief proof-of-concept for SIUnits-like library. Hard-wired to
+ floating point seconds and meters, but accepts other units.
+ </p>
+<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">R1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">R2</span><span class="special">></span>
+<span class="keyword">class</span> <span class="identifier">quantity</span>
+<span class="special">{</span>
+ <span class="keyword">double</span> <span class="identifier">q_</span><span class="special">;</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">typedef</span> <span class="identifier">R1</span> <span class="identifier">time_dim</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">R2</span> <span class="identifier">distance_dim</span><span class="special">;</span>
+ <span class="identifier">quantity</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">q_</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">{}</span>
+
+ <span class="keyword">double</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">q_</span><span class="special">;}</span>
+ <span class="keyword">void</span> <span class="identifier">set</span><span class="special">(</span><span class="keyword">double</span> <span class="identifier">q</span><span class="special">)</span> <span class="special">{</span><span class="identifier">q_</span> <span class="special">=</span> <span class="identifier">q</span><span class="special">;}</span>
+<span class="special">};</span>
+
+<span class="keyword">template</span> <span class="special"><></span>
+<span class="keyword">class</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">1</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">0</span><span class="special">></span> <span class="special">></span>
+<span class="special">{</span>
+ <span class="keyword">double</span> <span class="identifier">q_</span><span class="special">;</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">quantity</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">q_</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">{}</span>
+ <span class="identifier">quantity</span><span class="special">(</span><span class="identifier">seconds</span> <span class="identifier">d</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">q_</span><span class="special">(</span><span class="identifier">d</span><span class="special">.</span><span class="identifier">count</span><span class="special">())</span> <span class="special">{}</span> <span class="comment">// note: only User1::seconds needed here
+</span>
+ <span class="keyword">double</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">q_</span><span class="special">;}</span>
+ <span class="keyword">void</span> <span class="identifier">set</span><span class="special">(</span><span class="keyword">double</span> <span class="identifier">q</span><span class="special">)</span> <span class="special">{</span><span class="identifier">q_</span> <span class="special">=</span> <span class="identifier">q</span><span class="special">;}</span>
+<span class="special">};</span>
+
+<span class="keyword">template</span> <span class="special"><></span>
+<span class="keyword">class</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">0</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">1</span><span class="special">></span> <span class="special">></span>
+<span class="special">{</span>
+ <span class="keyword">double</span> <span class="identifier">q_</span><span class="special">;</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">quantity</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">q_</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">{}</span>
+ <span class="identifier">quantity</span><span class="special">(</span><span class="identifier">meter</span> <span class="identifier">d</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">q_</span><span class="special">(</span><span class="identifier">d</span><span class="special">.</span><span class="identifier">count</span><span class="special">())</span> <span class="special">{}</span> <span class="comment">// note: only User1::meter needed here
+</span>
+ <span class="keyword">double</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">q_</span><span class="special">;}</span>
+ <span class="keyword">void</span> <span class="identifier">set</span><span class="special">(</span><span class="keyword">double</span> <span class="identifier">q</span><span class="special">)</span> <span class="special">{</span><span class="identifier">q_</span> <span class="special">=</span> <span class="identifier">q</span><span class="special">;}</span>
+<span class="special">};</span>
+
+<span class="keyword">template</span> <span class="special"><></span>
+<span class="keyword">class</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">0</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">0</span><span class="special">></span> <span class="special">></span>
+<span class="special">{</span>
+ <span class="keyword">double</span> <span class="identifier">q_</span><span class="special">;</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">quantity</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">q_</span><span class="special">(</span><span class="number">1</span><span class="special">)</span> <span class="special">{}</span>
+ <span class="identifier">quantity</span><span class="special">(</span><span class="keyword">double</span> <span class="identifier">d</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">q_</span><span class="special">(</span><span class="identifier">d</span><span class="special">)</span> <span class="special">{}</span>
+
+ <span class="keyword">double</span> <span class="identifier">get</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">q_</span><span class="special">;}</span>
+ <span class="keyword">void</span> <span class="identifier">set</span><span class="special">(</span><span class="keyword">double</span> <span class="identifier">q</span><span class="special">)</span> <span class="special">{</span><span class="identifier">q_</span> <span class="special">=</span> <span class="identifier">q</span><span class="special">;}</span>
+<span class="special">};</span>
+</pre>
+<p>
+ Example of SI-Units
+ </p>
+<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">0</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">0</span><span class="special">></span> <span class="special">></span> <span class="identifier">Scalar</span><span class="special">;</span>
+<span class="keyword">typedef</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">1</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">0</span><span class="special">></span> <span class="special">></span> <span class="identifier">Time</span><span class="special">;</span> <span class="comment">// second
+</span><span class="keyword">typedef</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">0</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">1</span><span class="special">></span> <span class="special">></span> <span class="identifier">Distance</span><span class="special">;</span> <span class="comment">// meter
+</span><span class="keyword">typedef</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><-</span><span class="number">1</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">1</span><span class="special">></span> <span class="special">></span> <span class="identifier">Speed</span><span class="special">;</span> <span class="comment">// meter/second
+</span><span class="keyword">typedef</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><-</span><span class="number">2</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">1</span><span class="special">></span> <span class="special">></span> <span class="identifier">Acceleration</span><span class="special">;</span> <span class="comment">// meter/second^2
+</span></pre>
+<p>
+ Quantity arithmetics
+ </p>
+<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">R1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">R2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">R3</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">R4</span><span class="special">></span>
+<span class="identifier">quantity</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_subtract</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R3</span><span class="special">>::</span><span class="identifier">type</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_subtract</span><span class="special"><</span><span class="identifier">R2</span><span class="special">,</span> <span class="identifier">R4</span><span class="special">>::</span><span class="identifier">type</span><span class="special">></span>
+<span class="keyword">operator</span><span class="special">/(</span><span class="keyword">const</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R2</span><span class="special">>&</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">R3</span><span class="special">,</span> <span class="identifier">R4</span><span class="special">>&</span> <span class="identifier">y</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="identifier">quantity</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_subtract</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R3</span><span class="special">>::</span><span class="identifier">type</span><span class="special">,</span>
+ <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_subtract</span><span class="special"><</span><span class="identifier">R2</span><span class="special">,</span> <span class="identifier">R4</span><span class="special">>::</span><span class="identifier">type</span><span class="special">></span> <span class="identifier">R</span><span class="special">;</span>
+ <span class="identifier">R</span> <span class="identifier">r</span><span class="special">;</span>
+ <span class="identifier">r</span><span class="special">.</span><span class="identifier">set</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">/</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">get</span><span class="special">());</span>
+ <span class="keyword">return</span> <span class="identifier">r</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">R1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">R2</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">R3</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">R4</span><span class="special">></span>
+<span class="identifier">quantity</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_add</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R3</span><span class="special">>::</span><span class="identifier">type</span><span class="special">,</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_add</span><span class="special"><</span><span class="identifier">R2</span><span class="special">,</span> <span class="identifier">R4</span><span class="special">>::</span><span class="identifier">type</span><span class="special">></span>
+<span class="keyword">operator</span><span class="special">*(</span><span class="keyword">const</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R2</span><span class="special">>&</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">R3</span><span class="special">,</span> <span class="identifier">R4</span><span class="special">>&</span> <span class="identifier">y</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="identifier">quantity</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_add</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R3</span><span class="special">>::</span><span class="identifier">type</span><span class="special">,</span>
+ <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_add</span><span class="special"><</span><span class="identifier">R2</span><span class="special">,</span> <span class="identifier">R4</span><span class="special">>::</span><span class="identifier">type</span><span class="special">></span> <span class="identifier">R</span><span class="special">;</span>
+ <span class="identifier">R</span> <span class="identifier">r</span><span class="special">;</span>
+ <span class="identifier">r</span><span class="special">.</span><span class="identifier">set</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">*</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">get</span><span class="special">());</span>
+ <span class="keyword">return</span> <span class="identifier">r</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">R1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">R2</span><span class="special">></span>
+<span class="identifier">quantity</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R2</span><span class="special">></span>
+<span class="keyword">operator</span><span class="special">+(</span><span class="keyword">const</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R2</span><span class="special">>&</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R2</span><span class="special">>&</span> <span class="identifier">y</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R2</span><span class="special">></span> <span class="identifier">R</span><span class="special">;</span>
+ <span class="identifier">R</span> <span class="identifier">r</span><span class="special">;</span>
+ <span class="identifier">r</span><span class="special">.</span><span class="identifier">set</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">get</span><span class="special">());</span>
+ <span class="keyword">return</span> <span class="identifier">r</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">R1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">R2</span><span class="special">></span>
+<span class="identifier">quantity</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R2</span><span class="special">></span>
+<span class="keyword">operator</span><span class="special">-(</span><span class="keyword">const</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R2</span><span class="special">>&</span> <span class="identifier">x</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R2</span><span class="special">>&</span> <span class="identifier">y</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="identifier">quantity</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R2</span><span class="special">></span> <span class="identifier">R</span><span class="special">;</span>
+ <span class="identifier">R</span> <span class="identifier">r</span><span class="special">;</span>
+ <span class="identifier">r</span><span class="special">.</span><span class="identifier">set</span><span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special">-</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">get</span><span class="special">());</span>
+ <span class="keyword">return</span> <span class="identifier">r</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ Example type-safe physics function
+ </p>
+<pre class="programlisting"><span class="identifier">Distance</span>
+<span class="identifier">compute_distance</span><span class="special">(</span><span class="identifier">Speed</span> <span class="identifier">v0</span><span class="special">,</span> <span class="identifier">Time</span> <span class="identifier">t</span><span class="special">,</span> <span class="identifier">Acceleration</span> <span class="identifier">a</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">v0</span> <span class="special">*</span> <span class="identifier">t</span> <span class="special">+</span> <span class="identifier">Scalar</span><span class="special">(.</span><span class="number">5</span><span class="special">)</span> <span class="special">*</span> <span class="identifier">a</span> <span class="special">*</span> <span class="identifier">t</span> <span class="special">*</span> <span class="identifier">t</span><span class="special">;</span> <span class="comment">// if a units mistake is made here it won't compile
+</span><span class="special">}</span>
+</pre>
+<p>
+ Exercise example type-safe physics function and show interoperation of
+ custom time durations (User1::seconds) and standard time durations (boost::hours).
+ Though input can be arbitrary (but type-safe) units, output is always
+ in SI-units (a limitation of the simplified Units lib demoed here).
+ </p>
+<pre class="programlisting"><span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">8</span><span class="special">,</span> <span class="identifier">BOOST_INTMAX_C</span><span class="special">(</span><span class="number">0</span><span class="identifier">x7FFFFFFFD</span><span class="special">)></span> <span class="identifier">R1</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">3</span><span class="special">,</span> <span class="identifier">BOOST_INTMAX_C</span><span class="special">(</span><span class="number">0</span><span class="identifier">x7FFFFFFFD</span><span class="special">)></span> <span class="identifier">R2</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">User1</span><span class="special">::</span><span class="identifier">quantity</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_subtract</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">0</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">1</span><span class="special">></span> <span class="special">>::</span><span class="identifier">type</span><span class="special">,</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_subtract</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">1</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">0</span><span class="special">></span> <span class="special">>::</span><span class="identifier">type</span> <span class="special">></span> <span class="identifier">RR</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_subtract</span><span class="special"><</span><span class="identifier">R1</span><span class="special">,</span> <span class="identifier">R2</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">RS</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">RS</span><span class="special">::</span><span class="identifier">num</span> <span class="special"><<</span> <span class="char">'/'</span> <span class="special"><<</span> <span class="identifier">RS</span><span class="special">::</span><span class="identifier">den</span> <span class="special"><<</span> <span class="char">'\n'</span><span class="special">;</span>
+
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"*************\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"* testUser1 *\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"*************\n"</span><span class="special">;</span>
+ <span class="identifier">User1</span><span class="special">::</span><span class="identifier">Distance</span> <span class="identifier">d</span><span class="special">(</span> <span class="identifier">User1</span><span class="special">::</span><span class="identifier">mile</span><span class="special">(</span><span class="number">110</span><span class="special">)</span> <span class="special">);</span>
+ <span class="identifier">User1</span><span class="special">::</span><span class="identifier">Time</span> <span class="identifier">t</span><span class="special">(</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">hours</span><span class="special">(</span><span class="number">2</span><span class="special">)</span> <span class="special">);</span>
+
+ <span class="identifier">RR</span> <span class="identifier">r</span><span class="special">=</span><span class="identifier">d</span> <span class="special">/</span> <span class="identifier">t</span><span class="special">;</span>
+ <span class="comment">//r.set(d.get() / t.get());
+</span>
+ <span class="identifier">User1</span><span class="special">::</span><span class="identifier">Speed</span> <span class="identifier">rc</span><span class="special">=</span> <span class="identifier">r</span><span class="special">;</span>
+
+ <span class="identifier">User1</span><span class="special">::</span><span class="identifier">Speed</span> <span class="identifier">s</span> <span class="special">=</span> <span class="identifier">d</span> <span class="special">/</span> <span class="identifier">t</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Speed = "</span> <span class="special"><<</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" meters/sec\n"</span><span class="special">;</span>
+ <span class="identifier">User1</span><span class="special">::</span><span class="identifier">Acceleration</span> <span class="identifier">a</span> <span class="special">=</span> <span class="identifier">User1</span><span class="special">::</span><span class="identifier">Distance</span><span class="special">(</span> <span class="identifier">User1</span><span class="special">::</span><span class="identifier">foot</span><span class="special">(</span><span class="number">32.2</span><span class="special">)</span> <span class="special">)</span> <span class="special">/</span> <span class="identifier">User1</span><span class="special">::</span><span class="identifier">Time</span><span class="special">()</span> <span class="special">/</span> <span class="identifier">User1</span><span class="special">::</span><span class="identifier">Time</span><span class="special">();</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Acceleration = "</span> <span class="special"><<</span> <span class="identifier">a</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" meters/sec^2\n"</span><span class="special">;</span>
+ <span class="identifier">User1</span><span class="special">::</span><span class="identifier">Distance</span> <span class="identifier">df</span> <span class="special">=</span> <span class="identifier">compute_distance</span><span class="special">(</span><span class="identifier">s</span><span class="special">,</span> <span class="identifier">User1</span><span class="special">::</span><span class="identifier">Time</span><span class="special">(</span> <span class="identifier">User1</span><span class="special">::</span><span class="identifier">seconds</span><span class="special">(</span><span class="number">0.5</span><span class="special">)</span> <span class="special">),</span> <span class="identifier">a</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Distance = "</span> <span class="special"><<</span> <span class="identifier">df</span><span class="special">.</span><span class="identifier">get</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" meters\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"There are "</span> <span class="special"><<</span> <span class="identifier">User1</span><span class="special">::</span><span class="identifier">mile</span><span class="special">::</span><span class="identifier">ratio</span><span class="special">::</span><span class="identifier">den</span> <span class="special"><<</span> <span class="char">'/'</span> <span class="special"><<</span> <span class="identifier">User1</span><span class="special">::</span><span class="identifier">mile</span><span class="special">::</span><span class="identifier">ratio</span><span class="special">::</span><span class="identifier">num</span> <span class="special"><<</span> <span class="string">" miles/meter"</span><span class="special">;</span>
+ <span class="identifier">User1</span><span class="special">::</span><span class="identifier">meter</span> <span class="identifier">mt</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
+ <span class="identifier">User1</span><span class="special">::</span><span class="identifier">mile</span> <span class="identifier">mi</span> <span class="special">=</span> <span class="identifier">mt</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">" which is approximately "</span> <span class="special"><<</span> <span class="identifier">mi</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="char">'\n'</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"There are "</span> <span class="special"><<</span> <span class="identifier">User1</span><span class="special">::</span><span class="identifier">mile</span><span class="special">::</span><span class="identifier">ratio</span><span class="special">::</span><span class="identifier">num</span> <span class="special"><<</span> <span class="char">'/'</span> <span class="special"><<</span> <span class="identifier">User1</span><span class="special">::</span><span class="identifier">mile</span><span class="special">::</span><span class="identifier">ratio</span><span class="special">::</span><span class="identifier">den</span> <span class="special"><<</span> <span class="string">" meters/mile"</span><span class="special">;</span>
+ <span class="identifier">mi</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span>
+ <span class="identifier">mt</span> <span class="special">=</span> <span class="identifier">mi</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">" which is approximately "</span> <span class="special"><<</span> <span class="identifier">mt</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="char">'\n'</span><span class="special">;</span>
+ <span class="identifier">User1</span><span class="special">::</span><span class="identifier">attosecond</span> <span class="identifier">as</span><span class="special">(</span><span class="number">1</span><span class="special">);</span>
+ <span class="identifier">User1</span><span class="special">::</span><span class="identifier">seconds</span> <span class="identifier">sec</span> <span class="special">=</span> <span class="identifier">as</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"1 attosecond is "</span> <span class="special"><<</span> <span class="identifier">sec</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" seconds\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"sec = as; // compiles\n"</span><span class="special">;</span>
+ <span class="identifier">sec</span> <span class="special">=</span> <span class="identifier">User1</span><span class="special">::</span><span class="identifier">seconds</span><span class="special">(</span><span class="number">1</span><span class="special">);</span>
+ <span class="identifier">as</span> <span class="special">=</span> <span class="identifier">sec</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"1 second is "</span> <span class="special"><<</span> <span class="identifier">as</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" attoseconds\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"as = sec; // compiles\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"\n"</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ <span class="emphasis"><em>See the source file test/ratio_test.cpp</em></span>
+ </p>
+</div>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.how_you_override_the_duration_s_default_constructor"></a><a href="examples.html#boost_chrono.users_guide.examples.how_you_override_the_duration_s_default_constructor" title="How
+ you override the duration's default constructor">How
+ you override the duration's default constructor</a>
+</h4></div></div></div>
+<p>
+ Next follows how you override the duration's default constructor to do
+ anything you want (in this case zero). All we need to do is to change the
+ representation
+ </p>
+<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">I_dont_like_the_default_duration_behavior</span> <span class="special">{</span>
+
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">R</span><span class="special">></span>
+<span class="keyword">class</span> <span class="identifier">zero_default</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">typedef</span> <span class="identifier">R</span> <span class="identifier">rep</span><span class="special">;</span>
+
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">rep</span> <span class="identifier">rep_</span><span class="special">;</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="identifier">zero_default</span><span class="special">(</span><span class="identifier">rep</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">rep_</span><span class="special">(</span><span class="identifier">i</span><span class="special">)</span> <span class="special">{}</span>
+ <span class="keyword">operator</span> <span class="identifier">rep</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">rep_</span><span class="special">;}</span>
+
+ <span class="identifier">zero_default</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">+=(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span><span class="identifier">rep_</span> <span class="special">+=</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">rep_</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">zero_default</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">-=(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span><span class="identifier">rep_</span> <span class="special">-=</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">rep_</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">zero_default</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">*=(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span><span class="identifier">rep_</span> <span class="special">*=</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">rep_</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">zero_default</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">/=(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">{</span><span class="identifier">rep_</span> <span class="special">/=</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">rep_</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+
+ <span class="identifier">zero_default</span> <span class="keyword">operator</span><span class="special">+</span> <span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">zero_default</span> <span class="keyword">operator</span><span class="special">-</span> <span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">zero_default</span><span class="special">(-</span><span class="identifier">rep_</span><span class="special">);}</span>
+ <span class="identifier">zero_default</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">++()</span> <span class="special">{++</span><span class="identifier">rep_</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">zero_default</span> <span class="keyword">operator</span><span class="special">++(</span><span class="keyword">int</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">zero_default</span><span class="special">(</span><span class="identifier">rep_</span><span class="special">++);}</span>
+ <span class="identifier">zero_default</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">--()</span> <span class="special">{--</span><span class="identifier">rep_</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">zero_default</span> <span class="keyword">operator</span><span class="special">--(</span><span class="keyword">int</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">zero_default</span><span class="special">(</span><span class="identifier">rep_</span><span class="special">--);}</span>
+
+ <span class="keyword">friend</span> <span class="identifier">zero_default</span> <span class="keyword">operator</span><span class="special">+(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">zero_default</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span> <span class="special">+=</span> <span class="identifier">y</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="identifier">zero_default</span> <span class="keyword">operator</span><span class="special">-(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">zero_default</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span> <span class="special">-=</span> <span class="identifier">y</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="identifier">zero_default</span> <span class="keyword">operator</span><span class="special">*(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">zero_default</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span> <span class="special">*=</span> <span class="identifier">y</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="identifier">zero_default</span> <span class="keyword">operator</span><span class="special">/(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">zero_default</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span> <span class="special">/=</span> <span class="identifier">y</span><span class="special">;}</span>
+
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">zero_default</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">rep_</span> <span class="special">==</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">rep_</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">zero_default</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="special">!(</span><span class="identifier">x</span> <span class="special">==</span> <span class="identifier">y</span><span class="special">);}</span>
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><</span> <span class="special">(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">zero_default</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">rep_</span> <span class="special"><</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">rep_</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><=(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">zero_default</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="special">!(</span><span class="identifier">y</span> <span class="special"><</span> <span class="identifier">x</span><span class="special">);}</span>
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">></span> <span class="special">(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">zero_default</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">y</span> <span class="special"><</span> <span class="identifier">x</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">>=(</span><span class="identifier">zero_default</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">zero_default</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="special">!(</span><span class="identifier">x</span> <span class="special"><</span> <span class="identifier">y</span><span class="special">);}</span>
+<span class="special">};</span>
+
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">zero_default</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">nano</span> <span class="special">></span> <span class="identifier">nanoseconds</span><span class="special">;</span>
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">zero_default</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">micro</span> <span class="special">></span> <span class="identifier">microseconds</span><span class="special">;</span>
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">zero_default</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">milli</span> <span class="special">></span> <span class="identifier">milliseconds</span><span class="special">;</span>
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">zero_default</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span><span class="special">></span> <span class="special">></span> <span class="identifier">seconds</span><span class="special">;</span>
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">zero_default</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">60</span><span class="special">></span> <span class="special">></span> <span class="identifier">minutes</span><span class="special">;</span>
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">zero_default</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">3600</span><span class="special">></span> <span class="special">></span> <span class="identifier">hours</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ Usage
+ </p>
+<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">I_dont_like_the_default_duration_behavior</span><span class="special">;</span>
+
+<span class="identifier">milliseconds</span> <span class="identifier">ms</span><span class="special">;</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">ms</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="char">'\n'</span><span class="special">;</span>
+</pre>
+<p>
+ <span class="emphasis"><em>See the source file example/i_dont_like_the_default_duration_behavior.cpp</em></span>
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.min_utility"></a><a href="examples.html#boost_chrono.users_guide.examples.min_utility" title="min
+ utility">min
+ utility</a>
+</h4></div></div></div>
+<p>
+ Returns the earliest time_point.
+ </p>
+<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Duration1</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Duration2</span><span class="special">></span>
+<span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">common_type</span><span class="special"><</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration1</span><span class="special">>,</span>
+ <span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration2</span><span class="special">></span> <span class="special">>::</span><span class="identifier">type</span>
+<span class="identifier">min</span><span class="special">(</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration1</span><span class="special">></span> <span class="identifier">t1</span><span class="special">,</span> <span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration2</span><span class="special">></span> <span class="identifier">t2</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">t2</span> <span class="special"><</span> <span class="identifier">t1</span> <span class="special">?</span> <span class="identifier">t2</span> <span class="special">:</span> <span class="identifier">t1</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ Being able to <span class="bold"><strong>easily</strong></span> write this function
+ is a major feature!
+ </p>
+<pre class="programlisting"><span class="identifier">BOOST_AUTO</span><span class="special">(</span><span class="identifier">t1</span><span class="special">,</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">seconds</span><span class="special">(</span><span class="number">3</span><span class="special">));</span>
+<span class="identifier">BOOST_AUTO</span><span class="special">(</span><span class="identifier">t2</span><span class="special">,</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">nanoseconds</span><span class="special">(</span><span class="number">3</span><span class="special">));</span>
+<span class="identifier">BOOST_AUTO</span><span class="special">(</span><span class="identifier">t3</span><span class="special">,</span> <span class="special">(</span><span class="identifier">min</span><span class="special">)(</span><span class="identifier">t1</span><span class="special">,</span> <span class="identifier">t2</span><span class="special">));</span>
+</pre>
+<p>
+ <span class="emphasis"><em>See the source file example/min_time_point.cpp</em></span>
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.cycle_count"></a><a href="examples.html#boost_chrono.users_guide.examples.cycle_count" title="Cycle
+ count">Cycle
+ count</a>
+</h4></div></div></div>
+<p>
+ Users can easily create their own clocks, with both points in time and
+ time durations which have a representation and precision of their own choosing.
+ For example if there is a hardware counter which simply increments a count
+ with each cycle of the cpu, one can very easily build clocks, time points
+ and durations on top of that, using only a few tens of lines of code. Such
+ systems can be used to call the time-sensitive threading API's such as
+ sleep, wait on a condition variable, or wait for a mutex lock. The API
+ proposed herein is not sensitive as to whether this is a 300MHz clock (with
+ a 3 1/3 nanosecond tick period) or a 3GHz clock (with a tick period of
+ 1/3 of a nanosecond). And the resulting code will be just as efficient
+ as if the user wrote a special purpose clock cycle counter.
+ </p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
+
+<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">;</span>
+
+
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">speed</span><span class="special">></span>
+<span class="keyword">struct</span> <span class="identifier">cycle_count</span>
+<span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_multiply</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="identifier">speed</span><span class="special">>,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">mega</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">frequency</span><span class="special">;</span> <span class="comment">// Mhz
+</span> <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio_divide</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">ratio</span><span class="special"><</span><span class="number">1</span><span class="special">>,</span> <span class="identifier">frequency</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">period</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">rep</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">rep</span><span class="special">,</span> <span class="identifier">period</span><span class="special">></span> <span class="identifier">duration</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">cycle_count</span><span class="special">></span> <span class="identifier">time_point</span><span class="special">;</span>
+
+ <span class="keyword">static</span> <span class="identifier">time_point</span> <span class="identifier">now</span><span class="special">()</span>
+ <span class="special">{</span>
+ <span class="keyword">static</span> <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">tick</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="comment">// return exact cycle count
+</span> <span class="keyword">return</span> <span class="identifier">time_point</span><span class="special">(</span><span class="identifier">duration</span><span class="special">(++</span><span class="identifier">tick</span><span class="special">));</span> <span class="comment">// fake access to clock cycle count
+</span> <span class="special">}</span>
+<span class="special">};</span>
+
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">speed</span><span class="special">></span>
+<span class="keyword">struct</span> <span class="identifier">approx_cycle_count</span>
+<span class="special">{</span>
+ <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">frequency</span> <span class="special">=</span> <span class="identifier">speed</span> <span class="special">*</span> <span class="number">1000000</span><span class="special">;</span> <span class="comment">// MHz
+</span> <span class="keyword">typedef</span> <span class="identifier">nanoseconds</span> <span class="identifier">duration</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">duration</span><span class="special">::</span><span class="identifier">rep</span> <span class="identifier">rep</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">duration</span><span class="special">::</span><span class="identifier">period</span> <span class="identifier">period</span><span class="special">;</span>
+ <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">nanosec_per_sec</span> <span class="special">=</span> <span class="identifier">period</span><span class="special">::</span><span class="identifier">den</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">approx_cycle_count</span><span class="special">></span> <span class="identifier">time_point</span><span class="special">;</span>
+
+ <span class="keyword">static</span> <span class="identifier">time_point</span> <span class="identifier">now</span><span class="special">()</span>
+ <span class="special">{</span>
+ <span class="keyword">static</span> <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">tick</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span>
+ <span class="comment">// return cycle count as an approximate number of nanoseconds
+</span> <span class="comment">// compute as if nanoseconds is only duration in the std::lib
+</span> <span class="keyword">return</span> <span class="identifier">time_point</span><span class="special">(</span><span class="identifier">duration</span><span class="special">(++</span><span class="identifier">tick</span> <span class="special">*</span> <span class="identifier">nanosec_per_sec</span> <span class="special">/</span> <span class="identifier">frequency</span><span class="special">));</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+</pre>
+<p>
+ <span class="emphasis"><em>See the source file here</em></span>
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.xtime_conversions"></a><a href="examples.html#boost_chrono.users_guide.examples.xtime_conversions" title="xtime
+ conversions">xtime
+ conversions</a>
+</h4></div></div></div>
+<p>
+ Example round_up utility: converts d to To, rounding up for inexact conversions
+ Being able to <span class="bold"><strong>easily</strong></span> write this function
+ is a major feature!
+ </p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">type_traits</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+
+<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
+
+<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">;</span>
+
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">To</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span><span class="special">></span>
+<span class="identifier">To</span>
+<span class="identifier">round_up</span><span class="special">(</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">></span> <span class="identifier">d</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">To</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">duration_cast</span><span class="special"><</span><span class="identifier">To</span><span class="special">>(</span><span class="identifier">d</span><span class="special">);</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">result</span> <span class="special"><</span> <span class="identifier">d</span><span class="special">)</span>
+ <span class="special">++</span><span class="identifier">result</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ Demonstrate interaction with xtime-like facility:
+ </p>
+<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">xtime</span>
+<span class="special">{</span>
+ <span class="keyword">long</span> <span class="identifier">sec</span><span class="special">;</span>
+ <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="identifier">usec</span><span class="special">;</span>
+<span class="special">};</span>
+
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span><span class="special">></span>
+<span class="identifier">xtime</span>
+<span class="identifier">to_xtime_truncate</span><span class="special">(</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">></span> <span class="identifier">d</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">xtime</span> <span class="identifier">xt</span><span class="special">;</span>
+ <span class="identifier">xt</span><span class="special">.</span><span class="identifier">sec</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="keyword">long</span><span class="special">>(</span><span class="identifier">duration_cast</span><span class="special"><</span><span class="identifier">seconds</span><span class="special">>(</span><span class="identifier">d</span><span class="special">).</span><span class="identifier">count</span><span class="special">());</span>
+ <span class="identifier">xt</span><span class="special">.</span><span class="identifier">usec</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="keyword">long</span><span class="special">>(</span><span class="identifier">duration_cast</span><span class="special"><</span><span class="identifier">microseconds</span><span class="special">>(</span><span class="identifier">d</span> <span class="special">-</span> <span class="identifier">seconds</span><span class="special">(</span><span class="identifier">xt</span><span class="special">.</span><span class="identifier">sec</span><span class="special">)).</span><span class="identifier">count</span><span class="special">());</span>
+ <span class="keyword">return</span> <span class="identifier">xt</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span><span class="special">></span>
+<span class="identifier">xtime</span>
+<span class="identifier">to_xtime_round_up</span><span class="special">(</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">></span> <span class="identifier">d</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">xtime</span> <span class="identifier">xt</span><span class="special">;</span>
+ <span class="identifier">xt</span><span class="special">.</span><span class="identifier">sec</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="keyword">long</span><span class="special">>(</span><span class="identifier">duration_cast</span><span class="special"><</span><span class="identifier">seconds</span><span class="special">>(</span><span class="identifier">d</span><span class="special">).</span><span class="identifier">count</span><span class="special">());</span>
+ <span class="identifier">xt</span><span class="special">.</span><span class="identifier">usec</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="keyword">unsigned</span> <span class="keyword">long</span><span class="special">>(</span><span class="identifier">round_up</span><span class="special"><</span><span class="identifier">microseconds</span><span class="special">>(</span><span class="identifier">d</span> <span class="special">-</span> <span class="identifier">seconds</span><span class="special">(</span><span class="identifier">xt</span><span class="special">.</span><span class="identifier">sec</span><span class="special">)).</span><span class="identifier">count</span><span class="special">());</span>
+ <span class="keyword">return</span> <span class="identifier">xt</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="identifier">microseconds</span>
+<span class="identifier">from_xtime</span><span class="special">(</span><span class="identifier">xtime</span> <span class="identifier">xt</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">seconds</span><span class="special">(</span><span class="identifier">xt</span><span class="special">.</span><span class="identifier">sec</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">microseconds</span><span class="special">(</span><span class="identifier">xt</span><span class="special">.</span><span class="identifier">usec</span><span class="special">);</span>
+<span class="special">}</span>
+
+<span class="keyword">void</span> <span class="identifier">print</span><span class="special">(</span><span class="identifier">xtime</span> <span class="identifier">xt</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="char">'{'</span> <span class="special"><<</span> <span class="identifier">xt</span><span class="special">.</span><span class="identifier">sec</span> <span class="special"><<</span> <span class="char">','</span> <span class="special"><<</span> <span class="identifier">xt</span><span class="special">.</span><span class="identifier">usec</span> <span class="special"><<</span> <span class="string">"}\n"</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ Usage
+ </p>
+<pre class="programlisting"><span class="identifier">xtime</span> <span class="identifier">xt</span> <span class="special">=</span> <span class="identifier">to_xtime_truncate</span><span class="special">(</span><span class="identifier">seconds</span><span class="special">(</span><span class="number">3</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">milliseconds</span><span class="special">(</span><span class="number">251</span><span class="special">));</span>
+<span class="identifier">print</span><span class="special">(</span><span class="identifier">xt</span><span class="special">);</span>
+<span class="identifier">milliseconds</span> <span class="identifier">ms</span> <span class="special">=</span> <span class="identifier">duration_cast</span><span class="special"><</span><span class="identifier">milliseconds</span><span class="special">>(</span><span class="identifier">from_xtime</span><span class="special">(</span><span class="identifier">xt</span><span class="special">));</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">ms</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" milliseconds\n"</span><span class="special">;</span>
+<span class="identifier">xt</span> <span class="special">=</span> <span class="identifier">to_xtime_round_up</span><span class="special">(</span><span class="identifier">ms</span><span class="special">);</span>
+<span class="identifier">print</span><span class="special">(</span><span class="identifier">xt</span><span class="special">);</span>
+<span class="identifier">xt</span> <span class="special">=</span> <span class="identifier">to_xtime_truncate</span><span class="special">(</span><span class="identifier">seconds</span><span class="special">(</span><span class="number">3</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">nanoseconds</span><span class="special">(</span><span class="number">999</span><span class="special">));</span>
+<span class="identifier">print</span><span class="special">(</span><span class="identifier">xt</span><span class="special">);</span>
+<span class="identifier">xt</span> <span class="special">=</span> <span class="identifier">to_xtime_round_up</span><span class="special">(</span><span class="identifier">seconds</span><span class="special">(</span><span class="number">3</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">nanoseconds</span><span class="special">(</span><span class="number">999</span><span class="special">));</span>
+<span class="identifier">print</span><span class="special">(</span><span class="identifier">xt</span><span class="special">);</span>
+</pre>
+<p>
+ <span class="emphasis"><em>See the source file here</em></span>
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.xtime_clock"></a>xtime_clock
+</h4></div></div></div>
+<p>
+ This example demonstrates the use of a timeval-like struct to be used as
+ the representation type for both duraiton and time_point.
+ </p>
+<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">xtime</span> <span class="special">{</span>
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="keyword">long</span> <span class="identifier">tv_sec</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="identifier">tv_usec</span><span class="special">;</span>
+
+ <span class="keyword">void</span> <span class="identifier">fixup</span><span class="special">()</span> <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">tv_usec</span> <span class="special"><</span> <span class="number">0</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">tv_usec</span> <span class="special">+=</span> <span class="number">1000000</span><span class="special">;</span>
+ <span class="special">--</span><span class="identifier">tv_sec</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">explicit</span> <span class="identifier">xtime</span><span class="special">(</span><span class="keyword">long</span> <span class="identifier">sec</span><span class="special">,</span> <span class="keyword">long</span> <span class="identifier">usec</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">tv_sec</span> <span class="special">=</span> <span class="identifier">sec</span><span class="special">;</span>
+ <span class="identifier">tv_usec</span> <span class="special">=</span> <span class="identifier">usec</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">tv_usec</span> <span class="special"><</span> <span class="number">0</span> <span class="special">||</span> <span class="identifier">tv_usec</span> <span class="special">>=</span> <span class="number">1000000</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">tv_sec</span> <span class="special">+=</span> <span class="identifier">tv_usec</span> <span class="special">/</span> <span class="number">1000000</span><span class="special">;</span>
+ <span class="identifier">tv_usec</span> <span class="special">%=</span> <span class="number">1000000</span><span class="special">;</span>
+ <span class="identifier">fixup</span><span class="special">();</span>
+ <span class="special">}</span>
+ <span class="special">}</span>
+
+ <span class="keyword">explicit</span> <span class="identifier">xtime</span><span class="special">(</span><span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">usec</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">tv_usec</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="keyword">long</span><span class="special">>(</span><span class="identifier">usec</span> <span class="special">%</span> <span class="number">1000000</span><span class="special">);</span>
+ <span class="identifier">tv_sec</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="keyword">long</span><span class="special">>(</span><span class="identifier">usec</span> <span class="special">/</span> <span class="number">1000000</span><span class="special">);</span>
+ <span class="identifier">fixup</span><span class="special">();</span>
+ <span class="special">}</span>
+
+ <span class="comment">// explicit
+</span> <span class="keyword">operator</span> <span class="keyword">long</span> <span class="keyword">long</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="keyword">long</span> <span class="keyword">long</span><span class="special">>(</span><span class="identifier">tv_sec</span><span class="special">)</span> <span class="special">*</span> <span class="number">1000000</span> <span class="special">+</span> <span class="identifier">tv_usec</span><span class="special">;}</span>
+
+ <span class="identifier">xtime</span><span class="special">&</span> <span class="keyword">operator</span> <span class="special">+=</span> <span class="special">(</span><span class="identifier">xtime</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">tv_sec</span> <span class="special">+=</span> <span class="identifier">rhs</span><span class="special">.</span><span class="identifier">tv_sec</span><span class="special">;</span>
+ <span class="identifier">tv_usec</span> <span class="special">+=</span> <span class="identifier">rhs</span><span class="special">.</span><span class="identifier">tv_usec</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">tv_usec</span> <span class="special">>=</span> <span class="number">1000000</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">tv_usec</span> <span class="special">-=</span> <span class="number">1000000</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">tv_sec</span><span class="special">;</span>
+ <span class="special">}</span>
+ <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">xtime</span><span class="special">&</span> <span class="keyword">operator</span> <span class="special">-=</span> <span class="special">(</span><span class="identifier">xtime</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">tv_sec</span> <span class="special">-=</span> <span class="identifier">rhs</span><span class="special">.</span><span class="identifier">tv_sec</span><span class="special">;</span>
+ <span class="identifier">tv_usec</span> <span class="special">-=</span> <span class="identifier">rhs</span><span class="special">.</span><span class="identifier">tv_usec</span><span class="special">;</span>
+ <span class="identifier">fixup</span><span class="special">();</span>
+ <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">xtime</span><span class="special">&</span> <span class="keyword">operator</span> <span class="special">%=</span> <span class="special">(</span><span class="identifier">xtime</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">t</span> <span class="special">=</span> <span class="identifier">tv_sec</span> <span class="special">*</span> <span class="number">1000000</span> <span class="special">+</span> <span class="identifier">tv_usec</span><span class="special">;</span>
+ <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">r</span> <span class="special">=</span> <span class="identifier">rhs</span><span class="special">.</span><span class="identifier">tv_sec</span> <span class="special">*</span> <span class="number">1000000</span> <span class="special">+</span> <span class="identifier">rhs</span><span class="special">.</span><span class="identifier">tv_usec</span><span class="special">;</span>
+ <span class="identifier">t</span> <span class="special">%=</span> <span class="identifier">r</span><span class="special">;</span>
+ <span class="identifier">tv_sec</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="keyword">long</span><span class="special">>(</span><span class="identifier">t</span> <span class="special">/</span> <span class="number">1000000</span><span class="special">);</span>
+ <span class="identifier">tv_usec</span> <span class="special">=</span> <span class="keyword">static_cast</span><span class="special"><</span><span class="keyword">long</span><span class="special">>(</span><span class="identifier">t</span> <span class="special">%</span> <span class="number">1000000</span><span class="special">);</span>
+ <span class="identifier">fixup</span><span class="special">();</span>
+ <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="keyword">friend</span> <span class="identifier">xtime</span> <span class="keyword">operator</span><span class="special">+(</span><span class="identifier">xtime</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">xtime</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span> <span class="special">+=</span> <span class="identifier">y</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="identifier">xtime</span> <span class="keyword">operator</span><span class="special">-(</span><span class="identifier">xtime</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">xtime</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span> <span class="special">-=</span> <span class="identifier">y</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="identifier">xtime</span> <span class="keyword">operator</span><span class="special">%(</span><span class="identifier">xtime</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">xtime</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span> <span class="special">%=</span> <span class="identifier">y</span><span class="special">;}</span>
+
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="identifier">xtime</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">xtime</span> <span class="identifier">y</span><span class="special">)</span>
+ <span class="special">{</span> <span class="keyword">return</span> <span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">tv_sec</span> <span class="special">==</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">tv_sec</span> <span class="special">&&</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">tv_usec</span> <span class="special">==</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">tv_usec</span><span class="special">);</span> <span class="special">}</span>
+
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><(</span><span class="identifier">xtime</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">xtime</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">tv_sec</span> <span class="special">==</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">tv_sec</span><span class="special">)</span>
+ <span class="keyword">return</span> <span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">tv_usec</span> <span class="special"><</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">tv_usec</span><span class="special">);</span>
+ <span class="keyword">return</span> <span class="special">(</span><span class="identifier">x</span><span class="special">.</span><span class="identifier">tv_sec</span> <span class="special"><</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">tv_sec</span><span class="special">);</span>
+ <span class="special">}</span>
+
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span><span class="identifier">xtime</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">xtime</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="special">!(</span><span class="identifier">x</span> <span class="special">==</span> <span class="identifier">y</span><span class="special">);</span> <span class="special">}</span>
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">></span> <span class="special">(</span><span class="identifier">xtime</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">xtime</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="identifier">y</span> <span class="special"><</span> <span class="identifier">x</span><span class="special">;</span> <span class="special">}</span>
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><=(</span><span class="identifier">xtime</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">xtime</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="special">!(</span><span class="identifier">y</span> <span class="special"><</span> <span class="identifier">x</span><span class="special">);</span> <span class="special">}</span>
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">>=(</span><span class="identifier">xtime</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">xtime</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span> <span class="keyword">return</span> <span class="special">!(</span><span class="identifier">x</span> <span class="special"><</span> <span class="identifier">y</span><span class="special">);</span> <span class="special">}</span>
+
+ <span class="keyword">friend</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span><span class="special">&</span> <span class="keyword">operator</span><span class="special"><<(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ostream</span><span class="special">&</span> <span class="identifier">os</span><span class="special">,</span> <span class="identifier">xtime</span> <span class="identifier">x</span><span class="special">)</span>
+ <span class="special">{</span><span class="keyword">return</span> <span class="identifier">os</span> <span class="special"><<</span> <span class="char">'{'</span> <span class="special"><<</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">tv_sec</span> <span class="special"><<</span> <span class="char">','</span> <span class="special"><<</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">tv_usec</span> <span class="special"><<</span> <span class="char">'}'</span><span class="special">;}</span>
+<span class="special">};</span>
+</pre>
+<p>
+ Clock based on timeval-like struct.
+ </p>
+<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">xtime_clock</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">typedef</span> <span class="identifier">xtime</span> <span class="identifier">rep</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">micro</span> <span class="identifier">period</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">rep</span><span class="special">,</span> <span class="identifier">period</span><span class="special">></span> <span class="identifier">duration</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">xtime_clock</span><span class="special">></span> <span class="identifier">time_point</span><span class="special">;</span>
+
+ <span class="keyword">static</span> <span class="identifier">time_point</span> <span class="identifier">now</span><span class="special">()</span>
+ <span class="special">{</span>
+ <span class="preprocessor">#if</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_CHRONO_WINDOWS_API</span><span class="special">)</span>
+ <span class="identifier">time_point</span> <span class="identifier">t</span><span class="special">(</span><span class="identifier">duration</span><span class="special">(</span><span class="identifier">xtime</span><span class="special">(</span><span class="number">0</span><span class="special">)));</span>
+ <span class="identifier">gettimeofday</span><span class="special">((</span><span class="identifier">timeval</span><span class="special">*)&</span><span class="identifier">t</span><span class="special">,</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">t</span><span class="special">;</span>
+
+ <span class="preprocessor">#elif</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_CHRONO_MAC_API</span><span class="special">)</span>
+
+ <span class="identifier">time_point</span> <span class="identifier">t</span><span class="special">(</span><span class="identifier">duration</span><span class="special">(</span><span class="identifier">xtime</span><span class="special">(</span><span class="number">0</span><span class="special">)));</span>
+ <span class="identifier">gettimeofday</span><span class="special">((</span><span class="identifier">timeval</span><span class="special">*)&</span><span class="identifier">t</span><span class="special">,</span> <span class="number">0</span><span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">t</span><span class="special">;</span>
+
+ <span class="preprocessor">#elif</span> <span class="identifier">defined</span><span class="special">(</span><span class="identifier">BOOST_CHRONO_POSIX_API</span><span class="special">)</span>
+ <span class="comment">//time_point t(0,0);
+</span>
+ <span class="identifier">timespec</span> <span class="identifier">ts</span><span class="special">;</span>
+ <span class="special">::</span><span class="identifier">clock_gettime</span><span class="special">(</span> <span class="identifier">CLOCK_REALTIME</span><span class="special">,</span> <span class="special">&</span><span class="identifier">ts</span> <span class="special">);</span>
+
+ <span class="identifier">xtime</span> <span class="identifier">xt</span><span class="special">(</span> <span class="identifier">ts</span><span class="special">.</span><span class="identifier">tv_sec</span><span class="special">,</span> <span class="identifier">ts</span><span class="special">.</span><span class="identifier">tv_nsec</span><span class="special">/</span><span class="number">1000</span><span class="special">);</span>
+ <span class="keyword">return</span> <span class="identifier">time_point</span><span class="special">(</span><span class="identifier">duration</span><span class="special">(</span><span class="identifier">xt</span><span class="special">));</span>
+
+ <span class="preprocessor">#endif</span> <span class="comment">// POSIX
+</span> <span class="special">}</span>
+<span class="special">};</span>
+</pre>
+<p>
+ Usage of xtime_clock
+ </p>
+<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">;</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"sizeof xtime_clock::time_point = "</span> <span class="special"><<</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">xtime_clock</span><span class="special">::</span><span class="identifier">time_point</span><span class="special">)</span> <span class="special"><<</span> <span class="char">'\n'</span><span class="special">;</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"sizeof xtime_clock::duration = "</span> <span class="special"><<</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">xtime_clock</span><span class="special">::</span><span class="identifier">duration</span><span class="special">)</span> <span class="special"><<</span> <span class="char">'\n'</span><span class="special">;</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"sizeof xtime_clock::rep = "</span> <span class="special"><<</span> <span class="keyword">sizeof</span><span class="special">(</span><span class="identifier">xtime_clock</span><span class="special">::</span><span class="identifier">rep</span><span class="special">)</span> <span class="special"><<</span> <span class="char">'\n'</span><span class="special">;</span>
+<span class="identifier">xtime_clock</span><span class="special">::</span><span class="identifier">duration</span> <span class="identifier">delay</span><span class="special">(</span><span class="identifier">milliseconds</span><span class="special">(</span><span class="number">5</span><span class="special">));</span>
+<span class="identifier">xtime_clock</span><span class="special">::</span><span class="identifier">time_point</span> <span class="identifier">start</span> <span class="special">=</span> <span class="identifier">xtime_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">();</span>
+<span class="keyword">while</span> <span class="special">(</span><span class="identifier">xtime_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()</span> <span class="special">-</span> <span class="identifier">start</span> <span class="special"><=</span> <span class="identifier">delay</span><span class="special">)</span> <span class="special">{}</span>
+<span class="identifier">xtime_clock</span><span class="special">::</span><span class="identifier">time_point</span> <span class="identifier">stop</span> <span class="special">=</span> <span class="identifier">xtime_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">();</span>
+<span class="identifier">xtime_clock</span><span class="special">::</span><span class="identifier">duration</span> <span class="identifier">elapsed</span> <span class="special">=</span> <span class="identifier">stop</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">;</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"paused "</span> <span class="special"><<</span> <span class="identifier">nanoseconds</span><span class="special">(</span><span class="identifier">elapsed</span><span class="special">).</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" nanoseconds\n"</span><span class="special">;</span>
+</pre>
+<p>
+ <span class="emphasis"><em>See the source file example/timeval_demo.cpp</em></span>
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.runtime_resolution"></a>runtime_resolution
+</h4></div></div></div>
+<p>
+ Handle duration with resolution not known until run time
+ </p>
+<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">duration</span>
+<span class="special">{</span>
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> <span class="identifier">rep</span><span class="special">;</span>
+<span class="keyword">private</span><span class="special">:</span>
+ <span class="identifier">rep</span> <span class="identifier">rep_</span><span class="special">;</span>
+
+ <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">double</span> <span class="identifier">ticks_per_nanosecond</span><span class="special">;</span>
+
+<span class="keyword">public</span><span class="special">:</span>
+ <span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="keyword">double</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">nano</span><span class="special">></span> <span class="identifier">tonanosec</span><span class="special">;</span>
+
+ <span class="identifier">duration</span><span class="special">()</span> <span class="special">{}</span> <span class="comment">// = default;
+</span> <span class="keyword">explicit</span> <span class="identifier">duration</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">rep</span><span class="special">&</span> <span class="identifier">r</span><span class="special">)</span> <span class="special">:</span> <span class="identifier">rep_</span><span class="special">(</span><span class="identifier">r</span><span class="special">)</span> <span class="special">{}</span>
+
+ <span class="comment">// conversions
+</span> <span class="keyword">explicit</span> <span class="identifier">duration</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">tonanosec</span><span class="special">&</span> <span class="identifier">d</span><span class="special">)</span>
+ <span class="special">:</span> <span class="identifier">rep_</span><span class="special">(</span><span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">rep</span><span class="special">>(</span><span class="identifier">d</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special">*</span> <span class="identifier">ticks_per_nanosecond</span><span class="special">))</span> <span class="special">{}</span>
+
+ <span class="comment">// explicit
+</span> <span class="keyword">operator</span> <span class="identifier">tonanosec</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">tonanosec</span><span class="special">(</span><span class="identifier">rep_</span><span class="special">/</span><span class="identifier">ticks_per_nanosecond</span><span class="special">);}</span>
+
+ <span class="comment">// observer
+</span>
+ <span class="identifier">rep</span> <span class="identifier">count</span><span class="special">()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">rep_</span><span class="special">;}</span>
+
+ <span class="comment">// arithmetic
+</span>
+ <span class="identifier">duration</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">+=(</span><span class="keyword">const</span> <span class="identifier">duration</span><span class="special">&</span> <span class="identifier">d</span><span class="special">)</span> <span class="special">{</span><span class="identifier">rep_</span> <span class="special">+=</span> <span class="identifier">d</span><span class="special">.</span><span class="identifier">rep_</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">duration</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">-=(</span><span class="keyword">const</span> <span class="identifier">duration</span><span class="special">&</span> <span class="identifier">d</span><span class="special">)</span> <span class="special">{</span><span class="identifier">rep_</span> <span class="special">+=</span> <span class="identifier">d</span><span class="special">.</span><span class="identifier">rep_</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">duration</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">*=(</span><span class="identifier">rep</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="special">{</span><span class="identifier">rep_</span> <span class="special">*=</span> <span class="identifier">rhs</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">duration</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">/=(</span><span class="identifier">rep</span> <span class="identifier">rhs</span><span class="special">)</span> <span class="special">{</span><span class="identifier">rep_</span> <span class="special">/=</span> <span class="identifier">rhs</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+
+ <span class="identifier">duration</span> <span class="keyword">operator</span><span class="special">+()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">duration</span> <span class="keyword">operator</span><span class="special">-()</span> <span class="keyword">const</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">duration</span><span class="special">(-</span><span class="identifier">rep_</span><span class="special">);}</span>
+ <span class="identifier">duration</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">++()</span> <span class="special">{++</span><span class="identifier">rep_</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">duration</span> <span class="keyword">operator</span><span class="special">++(</span><span class="keyword">int</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">duration</span><span class="special">(</span><span class="identifier">rep_</span><span class="special">++);}</span>
+ <span class="identifier">duration</span><span class="special">&</span> <span class="keyword">operator</span><span class="special">--()</span> <span class="special">{--</span><span class="identifier">rep_</span><span class="special">;</span> <span class="keyword">return</span> <span class="special">*</span><span class="keyword">this</span><span class="special">;}</span>
+ <span class="identifier">duration</span> <span class="keyword">operator</span><span class="special">--(</span><span class="keyword">int</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">duration</span><span class="special">(</span><span class="identifier">rep_</span><span class="special">--);}</span>
+
+ <span class="keyword">friend</span> <span class="identifier">duration</span> <span class="keyword">operator</span><span class="special">+(</span><span class="identifier">duration</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">duration</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span> <span class="special">+=</span> <span class="identifier">y</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="identifier">duration</span> <span class="keyword">operator</span><span class="special">-(</span><span class="identifier">duration</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">duration</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span> <span class="special">-=</span> <span class="identifier">y</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="identifier">duration</span> <span class="keyword">operator</span><span class="special">*(</span><span class="identifier">duration</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">rep</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span> <span class="special">*=</span> <span class="identifier">y</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="identifier">duration</span> <span class="keyword">operator</span><span class="special">*(</span><span class="identifier">rep</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">duration</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">y</span> <span class="special">*=</span> <span class="identifier">x</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="identifier">duration</span> <span class="keyword">operator</span><span class="special">/(</span><span class="identifier">duration</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">rep</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span> <span class="special">/=</span> <span class="identifier">y</span><span class="special">;}</span>
+
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">==(</span><span class="identifier">duration</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">duration</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">rep_</span> <span class="special">==</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">rep_</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">!=(</span><span class="identifier">duration</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">duration</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="special">!(</span><span class="identifier">x</span> <span class="special">==</span> <span class="identifier">y</span><span class="special">);}</span>
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><</span> <span class="special">(</span><span class="identifier">duration</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">duration</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">x</span><span class="special">.</span><span class="identifier">rep_</span> <span class="special"><</span> <span class="identifier">y</span><span class="special">.</span><span class="identifier">rep_</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special"><=(</span><span class="identifier">duration</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">duration</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="special">!(</span><span class="identifier">y</span> <span class="special"><</span> <span class="identifier">x</span><span class="special">);}</span>
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">></span> <span class="special">(</span><span class="identifier">duration</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">duration</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="identifier">y</span> <span class="special"><</span> <span class="identifier">x</span><span class="special">;}</span>
+ <span class="keyword">friend</span> <span class="keyword">bool</span> <span class="keyword">operator</span><span class="special">>=(</span><span class="identifier">duration</span> <span class="identifier">x</span><span class="special">,</span> <span class="identifier">duration</span> <span class="identifier">y</span><span class="special">)</span> <span class="special">{</span><span class="keyword">return</span> <span class="special">!(</span><span class="identifier">x</span> <span class="special"><</span> <span class="identifier">y</span><span class="special">);}</span>
+<span class="special">};</span>
+</pre>
+<p>
+ <span class="emphasis"><em>See the source file here</em></span>
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.simulated_thread_interface_demonstration_program"></a><a href="examples.html#boost_chrono.users_guide.examples.simulated_thread_interface_demonstration_program" title="Simulated
+ thread interface demonstration program">Simulated
+ thread interface demonstration program</a>
+</h4></div></div></div>
+<p>
+ Free sleep functions
+ </p>
+<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span> <span class="keyword">namespace</span> <span class="identifier">this_thread</span> <span class="special">{</span>
+
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span><span class="special">></span>
+<span class="keyword">void</span> <span class="identifier">sleep_for</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">>&</span> <span class="identifier">d</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">microseconds</span> <span class="identifier">t</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration_cast</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">microseconds</span><span class="special">>(</span><span class="identifier">d</span><span class="special">);</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">t</span> <span class="special"><</span> <span class="identifier">d</span><span class="special">)</span>
+ <span class="special">++</span><span class="identifier">t</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">t</span> <span class="special">></span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">microseconds</span><span class="special">(</span><span class="number">0</span><span class="special">))</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"sleep_for "</span> <span class="special"><<</span> <span class="identifier">t</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" microseconds\n"</span><span class="special">;</span>
+<span class="special">}</span>
+
+<span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Duration</span><span class="special">></span>
+<span class="keyword">void</span> <span class="identifier">sleep_until</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span><span class="special">>&</span> <span class="identifier">t</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span><span class="special">></span> <span class="identifier">Time</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">time_point</span> <span class="identifier">SysTime</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">t</span> <span class="special">></span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">())</span> <span class="special">{</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">common_type</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Time</span><span class="special">::</span><span class="identifier">duration</span><span class="special">,</span>
+ <span class="keyword">typename</span> <span class="identifier">SysTime</span><span class="special">::</span><span class="identifier">duration</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">D</span><span class="special">;</span>
+ <span class="comment">/* auto */</span> <span class="identifier">D</span> <span class="identifier">d</span> <span class="special">=</span> <span class="identifier">t</span> <span class="special">-</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">();</span>
+ <span class="identifier">microseconds</span> <span class="identifier">us</span> <span class="special">=</span> <span class="identifier">duration_cast</span><span class="special"><</span><span class="identifier">microseconds</span><span class="special">>(</span><span class="identifier">d</span><span class="special">);</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">us</span> <span class="special"><</span> <span class="identifier">d</span><span class="special">)</span>
+ <span class="special">++</span><span class="identifier">us</span><span class="special">;</span>
+ <span class="identifier">SysTime</span> <span class="identifier">st</span> <span class="special">=</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">us</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"sleep_until "</span><span class="special">;</span>
+ <span class="identifier">detail</span><span class="special">::</span><span class="identifier">print_time</span><span class="special">(</span><span class="identifier">st</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">" which is "</span> <span class="special"><<</span> <span class="special">(</span><span class="identifier">st</span> <span class="special">-</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()).</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" microseconds away\n"</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="special">}</span>
+
+<span class="special">}}</span>
+</pre>
+<p>
+ timed_mutex modified fuctions
+ </p>
+<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
+<span class="keyword">struct</span> <span class="identifier">timed_mutex</span> <span class="special">{</span>
+ <span class="comment">// ...
+</span>
+ <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span><span class="special">></span>
+ <span class="keyword">bool</span> <span class="identifier">try_lock_for</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">>&</span> <span class="identifier">d</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">microseconds</span> <span class="identifier">t</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration_cast</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">microseconds</span><span class="special">>(</span><span class="identifier">d</span><span class="special">);</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">t</span> <span class="special"><=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">microseconds</span><span class="special">(</span><span class="number">0</span><span class="special">))</span>
+ <span class="keyword">return</span> <span class="identifier">try_lock</span><span class="special">();</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"try_lock_for "</span> <span class="special"><<</span> <span class="identifier">t</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" microseconds\n"</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Duration</span><span class="special">></span>
+ <span class="keyword">bool</span> <span class="identifier">try_lock_until</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span><span class="special">>&</span> <span class="identifier">t</span><span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span><span class="special">></span> <span class="identifier">Time</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">time_point</span> <span class="identifier">SysTime</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">t</span> <span class="special"><=</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">())</span>
+ <span class="keyword">return</span> <span class="identifier">try_lock</span><span class="special">();</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">common_type</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Time</span><span class="special">::</span><span class="identifier">duration</span><span class="special">,</span>
+ <span class="keyword">typename</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">duration</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">D</span><span class="special">;</span>
+ <span class="comment">/* auto */</span> <span class="identifier">D</span> <span class="identifier">d</span> <span class="special">=</span> <span class="identifier">t</span> <span class="special">-</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">();</span>
+ <span class="identifier">microseconds</span> <span class="identifier">us</span> <span class="special">=</span> <span class="identifier">duration_cast</span><span class="special"><</span><span class="identifier">microseconds</span><span class="special">>(</span><span class="identifier">d</span><span class="special">);</span>
+ <span class="identifier">SysTime</span> <span class="identifier">st</span> <span class="special">=</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">us</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"try_lock_until "</span><span class="special">;</span>
+ <span class="identifier">detail</span><span class="special">::</span><span class="identifier">print_time</span><span class="special">(</span><span class="identifier">st</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">" which is "</span> <span class="special"><<</span> <span class="special">(</span><span class="identifier">st</span> <span class="special">-</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()).</span><span class="identifier">count</span><span class="special">()</span>
+ <span class="special"><<</span> <span class="string">" microseconds away\n"</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+<span class="special">}</span>
+</pre>
+<p>
+ condition_variable modified fuctions
+ </p>
+<pre class="programlisting"><span class="keyword">namespace</span> <span class="identifier">boost</span> <span class="special">{</span>
+<span class="keyword">struct</span> <span class="identifier">condition_variable</span>
+<span class="special">{</span>
+ <span class="comment">// ...
+</span>
+ <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Period</span><span class="special">></span>
+ <span class="keyword">bool</span> <span class="identifier">wait_for</span><span class="special">(</span><span class="identifier">mutex</span><span class="special">&,</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">>&</span> <span class="identifier">d</span><span class="special">)</span> <span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">microseconds</span> <span class="identifier">t</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration_cast</span><span class="special"><</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">microseconds</span><span class="special">>(</span><span class="identifier">d</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"wait_for "</span> <span class="special"><<</span> <span class="identifier">t</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" microseconds\n"</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">Clock</span><span class="special">,</span> <span class="keyword">class</span> <span class="identifier">Duration</span><span class="special">></span>
+ <span class="keyword">bool</span> <span class="identifier">wait_until</span><span class="special">(</span><span class="identifier">mutex</span><span class="special">&,</span> <span class="keyword">const</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span><span class="special">>&</span> <span class="identifier">t</span><span class="special">)</span> <span class="special">{</span>
+ <span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">time_point</span><span class="special"><</span><span class="identifier">Clock</span><span class="special">,</span> <span class="identifier">Duration</span><span class="special">></span> <span class="identifier">Time</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">time_point</span> <span class="identifier">SysTime</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">t</span> <span class="special"><=</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">())</span>
+ <span class="keyword">return</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="keyword">typedef</span> <span class="keyword">typename</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">common_type</span><span class="special"><</span><span class="keyword">typename</span> <span class="identifier">Time</span><span class="special">::</span><span class="identifier">duration</span><span class="special">,</span>
+ <span class="keyword">typename</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">duration</span><span class="special">>::</span><span class="identifier">type</span> <span class="identifier">D</span><span class="special">;</span>
+ <span class="comment">/* auto */</span> <span class="identifier">D</span> <span class="identifier">d</span> <span class="special">=</span> <span class="identifier">t</span> <span class="special">-</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">();</span>
+ <span class="identifier">microseconds</span> <span class="identifier">us</span> <span class="special">=</span> <span class="identifier">duration_cast</span><span class="special"><</span><span class="identifier">microseconds</span><span class="special">>(</span><span class="identifier">d</span><span class="special">);</span>
+ <span class="identifier">SysTime</span> <span class="identifier">st</span> <span class="special">=</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">us</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"wait_until "</span><span class="special">;</span>
+ <span class="identifier">detail</span><span class="special">::</span><span class="identifier">print_time</span><span class="special">(</span><span class="identifier">st</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">" which is "</span> <span class="special"><<</span> <span class="special">(</span><span class="identifier">st</span> <span class="special">-</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()).</span><span class="identifier">count</span><span class="special">()</span>
+ <span class="special"><<</span> <span class="string">" microseconds away\n"</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="keyword">true</span><span class="special">;</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+<span class="special">}</span>
+</pre>
+<p>
+ Usage
+ </p>
+<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">mutex</span> <span class="identifier">m</span><span class="special">;</span>
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">timed_mutex</span> <span class="identifier">mut</span><span class="special">;</span>
+<span class="identifier">boost</span><span class="special">::</span><span class="identifier">condition_variable</span> <span class="identifier">cv</span><span class="special">;</span>
+
+<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">;</span>
+<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">;</span>
+
+<span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">sleep_for</span><span class="special">(</span><span class="identifier">seconds</span><span class="special">(</span><span class="number">3</span><span class="special">));</span>
+<span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">sleep_for</span><span class="special">(</span><span class="identifier">nanoseconds</span><span class="special">(</span><span class="number">300</span><span class="special">));</span>
+<span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">time_point</span> <span class="identifier">time_limit</span> <span class="special">=</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">seconds</span><span class="special">(</span><span class="number">4</span><span class="special">)</span> <span class="special">+</span> <span class="identifier">milliseconds</span><span class="special">(</span><span class="number">500</span><span class="special">);</span>
+<span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">sleep_until</span><span class="special">(</span><span class="identifier">time_limit</span><span class="special">);</span>
+
+<span class="identifier">mut</span><span class="special">.</span><span class="identifier">try_lock_for</span><span class="special">(</span><span class="identifier">milliseconds</span><span class="special">(</span><span class="number">30</span><span class="special">));</span>
+<span class="identifier">mut</span><span class="special">.</span><span class="identifier">try_lock_until</span><span class="special">(</span><span class="identifier">time_limit</span><span class="special">);</span>
+
+<span class="identifier">cv</span><span class="special">.</span><span class="identifier">wait_for</span><span class="special">(</span><span class="identifier">m</span><span class="special">,</span> <span class="identifier">minutes</span><span class="special">(</span><span class="number">1</span><span class="special">));</span> <span class="comment">// real code would put this in a loop
+</span><span class="identifier">cv</span><span class="special">.</span><span class="identifier">wait_until</span><span class="special">(</span><span class="identifier">m</span><span class="special">,</span> <span class="identifier">time_limit</span><span class="special">);</span> <span class="comment">// real code would put this in a loop
+</span>
+<span class="comment">// For those who prefer floating point
+</span><span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">sleep_for</span><span class="special">(</span><span class="identifier">duration</span><span class="special"><</span><span class="keyword">double</span><span class="special">>(</span><span class="number">0.25</span><span class="special">));</span>
+<span class="identifier">this_thread</span><span class="special">::</span><span class="identifier">sleep_until</span><span class="special">(</span><span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()</span> <span class="special">+</span> <span class="identifier">duration</span><span class="special"><</span><span class="keyword">double</span><span class="special">>(</span><span class="number">1.5</span><span class="special">));</span>
+</pre>
+<p>
+ <span class="emphasis"><em>See the source file example/simulated_thread_interface_demo.cpp</em></span>
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.saturating"></a>Saturating
+</h4></div></div></div>
+<p>
+ A "saturating" signed integral type is developed. This type has
+ +/- infinity and a nan (like IEEE floating point) but otherwise obeys signed
+ integral arithmetic. This class is subsequently used as the rep in boost::chrono::duration
+ to demonstrate a duration class that does not silently ignore overflow.
+ </p>
+<p>
+ <span class="emphasis"><em>See the source file example/satutating.cpp</em></span>
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.howard_hinnant_s_original_demonstration_program"></a><a href="examples.html#boost_chrono.users_guide.examples.howard_hinnant_s_original_demonstration_program" title="Howard
+ Hinnant's original demonstration program">Howard
+ Hinnant's original demonstration program</a>
+</h4></div></div></div>
+<p>
+ <span class="emphasis"><em>See the source file example/time2_demo.cpp</em></span>
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.a_tiny_program_that_times_how_long_until_a_key_is_struck"></a><a href="examples.html#boost_chrono.users_guide.examples.a_tiny_program_that_times_how_long_until_a_key_is_struck" title="A
+ tiny program that times how long until a key is struck">A
+ tiny program that times how long until a key is struck</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
+<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iomanip</span><span class="special">></span>
+
+<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">;</span>
+
+<span class="keyword">template</span><span class="special"><</span> <span class="keyword">class</span> <span class="identifier">Clock</span> <span class="special">></span>
+<span class="keyword">class</span> <span class="identifier">timer</span>
+<span class="special">{</span>
+ <span class="keyword">typename</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">time_point</span> <span class="identifier">start</span><span class="special">;</span>
+<span class="keyword">public</span><span class="special">:</span>
+
+ <span class="identifier">timer</span><span class="special">()</span> <span class="special">:</span> <span class="identifier">start</span><span class="special">(</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()</span> <span class="special">)</span> <span class="special">{}</span>
+
+ <span class="keyword">typename</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">duration</span> <span class="identifier">elapsed</span><span class="special">()</span> <span class="keyword">const</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">Clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">()</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="keyword">double</span> <span class="identifier">seconds</span><span class="special">()</span> <span class="keyword">const</span>
+ <span class="special">{</span>
+ <span class="keyword">return</span> <span class="identifier">elapsed</span><span class="special">().</span><span class="identifier">count</span><span class="special">()</span> <span class="special">*</span> <span class="special">((</span><span class="keyword">double</span><span class="special">)</span><span class="identifier">Clock</span><span class="special">::</span><span class="identifier">period</span><span class="special">::</span><span class="identifier">num</span><span class="special">/</span><span class="identifier">Clock</span><span class="special">::</span><span class="identifier">period</span><span class="special">::</span><span class="identifier">den</span><span class="special">);</span>
+ <span class="special">}</span>
+<span class="special">};</span>
+
+<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">timer</span><span class="special"><</span><span class="identifier">system_clock</span><span class="special">></span> <span class="identifier">t1</span><span class="special">;</span>
+ <span class="identifier">timer</span><span class="special"><</span><span class="identifier">monotonic_clock</span><span class="special">></span> <span class="identifier">t2</span><span class="special">;</span>
+ <span class="identifier">timer</span><span class="special"><</span><span class="identifier">high_resolution_clock</span><span class="special">></span> <span class="identifier">t3</span><span class="special">;</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"Strike any key: "</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cin</span><span class="special">.</span><span class="identifier">get</span><span class="special">();</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">fixed</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">setprecision</span><span class="special">(</span><span class="number">9</span><span class="special">);</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"system_clock-----------: "</span>
+ <span class="special"><<</span> <span class="identifier">t1</span><span class="special">.</span><span class="identifier">seconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" seconds\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"monotonic_clock--------: "</span>
+ <span class="special"><<</span> <span class="identifier">t2</span><span class="special">.</span><span class="identifier">seconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" seconds\n"</span><span class="special">;</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"high_resolution_clock--: "</span>
+ <span class="special"><<</span> <span class="identifier">t3</span><span class="special">.</span><span class="identifier">seconds</span><span class="special">()</span> <span class="special"><<</span> <span class="string">" seconds\n"</span><span class="special">;</span>
+
+ <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">time_point</span> <span class="identifier">d4</span> <span class="special">=</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">();</span>
+ <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">time_point</span> <span class="identifier">d5</span> <span class="special">=</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">();</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"\nsystem_clock latency-----------: "</span> <span class="special"><<</span> <span class="special">(</span><span class="identifier">d5</span> <span class="special">-</span> <span class="identifier">d4</span><span class="special">).</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">monotonic_clock</span><span class="special">::</span><span class="identifier">time_point</span> <span class="identifier">d6</span> <span class="special">=</span> <span class="identifier">monotonic_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">();</span>
+ <span class="identifier">monotonic_clock</span><span class="special">::</span><span class="identifier">time_point</span> <span class="identifier">d7</span> <span class="special">=</span> <span class="identifier">monotonic_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">();</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"monotonic_clock latency--------: "</span> <span class="special"><<</span> <span class="special">(</span><span class="identifier">d7</span> <span class="special">-</span> <span class="identifier">d6</span><span class="special">).</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">high_resolution_clock</span><span class="special">::</span><span class="identifier">time_point</span> <span class="identifier">d8</span> <span class="special">=</span> <span class="identifier">high_resolution_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">();</span>
+ <span class="identifier">high_resolution_clock</span><span class="special">::</span><span class="identifier">time_point</span> <span class="identifier">d9</span> <span class="special">=</span> <span class="identifier">high_resolution_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">();</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"high_resolution_clock latency--: "</span> <span class="special"><<</span> <span class="special">(</span><span class="identifier">d9</span> <span class="special">-</span> <span class="identifier">d8</span><span class="special">).</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">time_t</span> <span class="identifier">now</span> <span class="special">=</span> <span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">to_time_t</span><span class="special">(</span><span class="identifier">system_clock</span><span class="special">::</span><span class="identifier">now</span><span class="special">());</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"\nsystem_clock::now() reports UTC is "</span>
+ <span class="special"><<</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">asctime</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">gmtime</span><span class="special">(&</span><span class="identifier">now</span><span class="special">))</span> <span class="special"><<</span> <span class="string">"\n"</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ <span class="emphasis"><em>See the source file example/await_keystroke.cpp</em></span>
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.stopclock_example_cpp"></a>stopclock_example.cpp
+</h4></div></div></div>
+<p>
+ Here is the stopclock_example.cpp program supplied with the Boost Chrono
+ library:
+ </p>
+<p>
+ When the <code class="computeroutput"><span class="identifier">stopclock</span><span class="special"><></span>
+ <span class="identifier">t</span></code> object is created, it starts
+ timing. When it is destroyed at the end of the program, its destructor
+ stops the time counting and displays timing information on cout.
+ </p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">stopclock</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">cmath</span><span class="special">></span>
+
+<span class="keyword">int</span> <span class="identifier">main</span><span class="special">()</span>
+<span class="special">{</span>
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">stopclock</span><span class="special"><></span> <span class="identifier">t</span><span class="special">;</span>
+
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">long</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">10000000</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span> <span class="special">)</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">sqrt</span><span class="special">(</span> <span class="number">123.456L</span> <span class="special">);</span> <span class="comment">// burn some time
+</span>
+ <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ The output of this program run looks like this:
+ </p>
+<pre class="programlisting"><span class="identifier">wall</span> <span class="number">0.42</span> <span class="identifier">s</span><span class="special">,</span> <span class="identifier">user</span> <span class="number">0.41</span> <span class="identifier">s</span> <span class="special">+</span> <span class="identifier">system</span> <span class="number">0.00</span> <span class="identifier">s</span> <span class="special">=</span> <span class="identifier">total</span> <span class="identifier">cpu</span> <span class="number">0.41</span> <span class="identifier">s</span><span class="special">,</span> <span class="special">(</span><span class="number">96.3</span><span class="special">%)</span>
+</pre>
+<p>
+ In other words, this program ran in 0.42 seconds as would be measured by
+ a clock on the wall, the operating system charged it for 0.41 seconds of
+ user CPU time and 0 seconds of system CPU time, the total of these two
+ was 0.41, and that represented 96.3 percent of the wall clock time.
+ </p>
+<p>
+ <span class="emphasis"><em>See the source file example/stopclock_example.cpp</em></span>
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.stopclock_example2_cpp"></a>stopclock_example2.cpp
+</h4></div></div></div>
+<p>
+ The stopclock_example2.cpp program is the same, except that it supplies
+ additional constructor arguments from the command line:
+ </p>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">stopclock</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">cmath</span><span class="special">></span>
+
+<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">*</span> <span class="identifier">argv</span><span class="special">[]</span> <span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">const</span> <span class="keyword">char</span> <span class="special">*</span> <span class="identifier">format</span> <span class="special">=</span> <span class="identifier">argc</span> <span class="special">></span> <span class="number">1</span> <span class="special">?</span> <span class="identifier">argv</span><span class="special">[</span><span class="number">1</span><span class="special">]</span> <span class="special">:</span> <span class="string">"%t cpu seconds\n"</span><span class="special">;</span>
+ <span class="keyword">int</span> <span class="identifier">places</span> <span class="special">=</span> <span class="identifier">argc</span> <span class="special">></span> <span class="number">2</span> <span class="special">?</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">atoi</span><span class="special">(</span> <span class="identifier">argv</span><span class="special">[</span><span class="number">2</span><span class="special">]</span> <span class="special">)</span> <span class="special">:</span> <span class="number">2</span><span class="special">;</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">stopclock</span><span class="special"><></span> <span class="identifier">t</span><span class="special">(</span> <span class="identifier">format</span><span class="special">,</span> <span class="identifier">places</span> <span class="special">);</span>
+
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">long</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">0</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="number">10000000</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span> <span class="special">)</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">sqrt</span><span class="special">(</span> <span class="number">123.456L</span> <span class="special">);</span> <span class="comment">// burn some time
+</span>
+ <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
+<span class="special">}</span>
+</pre>
+<p>
+ Here is the output for this program for several sets of command line arguments:
+ </p>
+<pre class="programlisting"><span class="identifier">stopclock_example2</span>
+<span class="number">0.42</span> <span class="identifier">cpu</span> <span class="identifier">seconds</span>
+
+<span class="identifier">stopclock_example2</span> <span class="string">"%w wall clock seconds\n"</span>
+<span class="number">0.41</span> <span class="identifier">wall</span> <span class="identifier">clock</span> <span class="identifier">seconds</span>
+
+<span class="identifier">stopclock_example2</span> <span class="string">"%w wall clock seconds\n"</span> <span class="number">6</span>
+<span class="number">0.421875</span> <span class="identifier">wall</span> <span class="identifier">clock</span> <span class="identifier">seconds</span>
+
+<span class="identifier">stopclock_example2</span> <span class="string">"%t total CPU seconds\n"</span> <span class="number">3</span>
+<span class="number">0.422</span> <span class="identifier">total</span> <span class="identifier">CPU</span> <span class="identifier">seconds</span>
+</pre>
+<p>
+ <span class="emphasis"><em>See the source file example/stopclock_example2.cpp</em></span>
+ </p>
+</div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.examples.time_command"></a><a href="examples.html#boost_chrono.users_guide.examples.time_command" title="time
+ command">time
+ command</a>
+</h4></div></div></div>
+<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">stopclock</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
+<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">cstdlib</span><span class="special">></span>
+<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">string</span><span class="special">></span>
+<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">iostream</span><span class="special">></span>
+
+<span class="keyword">int</span> <span class="identifier">main</span><span class="special">(</span> <span class="keyword">int</span> <span class="identifier">argc</span><span class="special">,</span> <span class="keyword">char</span> <span class="special">*</span> <span class="identifier">argv</span><span class="special">[]</span> <span class="special">)</span>
+<span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">argc</span> <span class="special">==</span> <span class="number">1</span> <span class="special">)</span>
+ <span class="special">{</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"invoke: timex [-v] command [args...]\n"</span>
+ <span class="string">" command will be executed and timings displayed\n"</span>
+ <span class="string">" -v option causes command and args to be displayed\n"</span><span class="special">;</span>
+ <span class="keyword">return</span> <span class="number">1</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">s</span><span class="special">;</span>
+
+ <span class="keyword">bool</span> <span class="identifier">verbose</span> <span class="special">=</span> <span class="keyword">false</span><span class="special">;</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">argc</span> <span class="special">></span> <span class="number">1</span> <span class="special">&&</span> <span class="special">*</span><span class="identifier">argv</span><span class="special">[</span><span class="number">1</span><span class="special">]</span> <span class="special">==</span> <span class="char">'-'</span> <span class="special">&&</span> <span class="special">*(</span><span class="identifier">argv</span><span class="special">[</span><span class="number">1</span><span class="special">]+</span><span class="number">1</span><span class="special">)</span> <span class="special">==</span> <span class="char">'v'</span> <span class="special">)</span>
+ <span class="special">{</span>
+ <span class="identifier">verbose</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">;</span>
+ <span class="special">++</span><span class="identifier">argv</span><span class="special">;</span>
+ <span class="special">--</span><span class="identifier">argc</span><span class="special">;</span>
+ <span class="special">}</span>
+
+ <span class="keyword">for</span> <span class="special">(</span> <span class="keyword">int</span> <span class="identifier">i</span> <span class="special">=</span> <span class="number">1</span><span class="special">;</span> <span class="identifier">i</span> <span class="special"><</span> <span class="identifier">argc</span><span class="special">;</span> <span class="special">++</span><span class="identifier">i</span> <span class="special">)</span>
+ <span class="special">{</span>
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">i</span> <span class="special">></span> <span class="number">1</span> <span class="special">)</span> <span class="identifier">s</span> <span class="special">+=</span> <span class="char">' '</span><span class="special">;</span>
+ <span class="identifier">s</span> <span class="special">+=</span> <span class="identifier">argv</span><span class="special">[</span><span class="identifier">i</span><span class="special">];</span>
+ <span class="special">}</span>
+
+ <span class="keyword">if</span> <span class="special">(</span> <span class="identifier">verbose</span> <span class="special">)</span>
+ <span class="special">{</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="string">"command: \""</span> <span class="special"><<</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">c_str</span><span class="special">()</span> <span class="special"><<</span> <span class="string">"\"\n"</span><span class="special">;</span> <span class="special">}</span>
+
+ <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">stopclock</span><span class="special"><></span> <span class="identifier">t</span><span class="special">;</span>
+
+ <span class="keyword">return</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">system</span><span class="special">(</span> <span class="identifier">s</span><span class="special">.</span><span class="identifier">c_str</span><span class="special">()</span> <span class="special">);</span>
+<span class="special">}</span>
+</pre>
+<p>
+ <span class="emphasis"><em>See the source file example/timex.cpp</em></span>
+ </p>
+</div>
+</div>
+<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
+<td align="left"></td>
+<td align="right"><div class="copyright-footer">Copyright © 2008 Howard Hinnant<br>Copyright © 2006 , 2008 Beman Dawes<br>Copyright © 2009 -2010 Vicente J. Botet Escriba<p>
+ 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)
+ </p>
+</div></td>
+</tr></table>
+<hr>
+<div class="spirit-nav">
+<a accesskey="p" href="tutorial.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../users_guide.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="ext_references.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
+</div>
+</body>
+</html>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/ext_references.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/ext_references.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/ext_references.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -1,12 +1,12 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
-<title> References</title>
+<title> External Resources</title>
<link rel="stylesheet" href="../../../../../../doc/html/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
<link rel="start" href="../../index.html" title="Boost.Chrono">
<link rel="up" href="../users_guide.html" title=" Users'Guide">
-<link rel="prev" href="tutorial.html" title="Tutorial">
+<link rel="prev" href="examples.html" title="Examples">
<link rel="next" href="../reference.html" title=" Reference ">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
@@ -20,11 +20,11 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="tutorial.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../users_guide.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../reference.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="examples.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../users_guide.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../reference.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
-<a name="boost_chrono.users_guide.ext_references"></a> References
+<a name="boost_chrono.users_guide.ext_references"></a> External Resources
</h3></div></div></div>
<div class="variablelist">
<p class="title"><b></b></p>
@@ -65,7 +65,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="tutorial.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../users_guide.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../reference.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="examples.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../users_guide.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="../reference.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
</body>
</html>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/getting_started.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/getting_started.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/getting_started.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -39,7 +39,7 @@
Installing Chrono</a>
</h4></div></div></div>
<a name="boost_chrono.users_guide.getting_started.install.getting__emphasis_role__bold__boost_chrono__emphasis__"></a><h5>
-<a name="id4817887"></a>
+<a name="id4818252"></a>
<a href="getting_started.html#boost_chrono.users_guide.getting_started.install.getting__emphasis_role__bold__boost_chrono__emphasis__">Getting
<span class="bold"><strong>Boost.Chrono</strong></span> </a>
</h5>
@@ -50,10 +50,11 @@
</p>
<p>
You can also access the latest (unstable?) state from the <a href="https://svn.boost.org/svn/boost/sandbox/chrono" target="_top">Boost
- Sandbox</a>.
+ Sandbox</a>. Just go to here
+ and follow the instructions there for anonymous SVN access.
</p>
<a name="boost_chrono.users_guide.getting_started.install.where_to_install__emphasis_role__bold__boost_chrono__emphasis___"></a><h5>
-<a name="id4817948"></a>
+<a name="id4818321"></a>
<a href="getting_started.html#boost_chrono.users_guide.getting_started.install.where_to_install__emphasis_role__bold__boost_chrono__emphasis___">Where
to install <span class="bold"><strong>Boost.Chrono</strong></span>? </a>
</h5>
@@ -69,7 +70,7 @@
variable. Any help is welcome.
</p>
<a name="boost_chrono.users_guide.getting_started.install.building__emphasis_role__bold__boost_chrono__emphasis__"></a><h5>
-<a name="id4817990"></a>
+<a name="id4818363"></a>
<a href="getting_started.html#boost_chrono.users_guide.getting_started.install.building__emphasis_role__bold__boost_chrono__emphasis__">Building
<span class="bold"><strong>Boost.Chrono</strong></span> </a>
</h5>
@@ -80,13 +81,13 @@
<pre class="programlisting"><span class="identifier">bjam</span> <span class="identifier">libs</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">build</span>
</pre>
<a name="boost_chrono.users_guide.getting_started.install.requirements"></a><h5>
-<a name="id4818058"></a>
+<a name="id4818431"></a>
<a href="getting_started.html#boost_chrono.users_guide.getting_started.install.requirements">Requirements</a>
</h5>
<p>
- <span class="bold"><strong>Boost.Bitfield</strong></span> depends on some Boost libraries.
+ <span class="bold"><strong>Boost.Chrono</strong></span> depends on some Boost libraries.
For these specific parts you must use either Boost version 1.39.0 or the
- version in SVN trunk (even if older version should works also).
+ version in SVN trunk (even if older versions should works also).
</p>
<p>
In particular, <span class="bold"><strong>Boost.Chrono</strong></span> depends on:
@@ -94,10 +95,6 @@
<div class="variablelist">
<p class="title"><b></b></p>
<dl>
-<dt><span class="term">Boost.Accumulator</span></dt>
-<dd><p>
- for accumulator_set, and statistics features
- </p></dd>
<dt><span class="term">Boost.Config</span></dt>
<dd><p>
for configuration purposes, ...
@@ -118,18 +115,36 @@
<dd><p>
for is_base, ...
</p></dd>
-<dt><span class="term">Boost.Typeof</span></dt>
-<dd><p>
- for typeof, ...
- </p></dd>
<dt><span class="term">Boost.UtiliTy/EnableIf</span></dt>
<dd><p>
for enable_if, ...
</p></dd>
</dl>
</div>
+<p>
+ <span class="bold"><strong>Boost.Chrono</strong></span> depends optionaly on:
+ </p>
+<div class="variablelist">
+<p class="title"><b></b></p>
+<dl>
+<dt><span class="term">Boost.Accumulator</span></dt>
+<dd><p>
+ for accumulator_set, and statistics features when stopwatch_accumulator.hpp
+ is included
+ </p></dd>
+<dt><span class="term">Boost.Thread</span></dt>
+<dd><p>
+ for thread_specific_ptr when suspendible_clock.hpp is included
+ </p></dd>
+<dt><span class="term">Boost.Typeof</span></dt>
+<dd><p>
+ for duration and time_point registration when typeof/boost/chrono/chrono.hpp
+ is include
+ </p></dd>
+</dl>
+</div>
<a name="boost_chrono.users_guide.getting_started.install.building_an_executable_that_uses__emphasis_role__bold__boost_chrono__emphasis__"></a><h5>
-<a name="id4818268"></a>
+<a name="id4818679"></a>
<a href="getting_started.html#boost_chrono.users_guide.getting_started.install.building_an_executable_that_uses__emphasis_role__bold__boost_chrono__emphasis__">Building
an executable that uses <span class="bold"><strong>Boost.Chrono</strong></span>
</a>
@@ -139,7 +154,7 @@
with the Boost System library.
</p>
<a name="boost_chrono.users_guide.getting_started.install.exceptions_safety_"></a><h5>
-<a name="id4818304"></a>
+<a name="id4818715"></a>
<a href="getting_started.html#boost_chrono.users_guide.getting_started.install.exceptions_safety_">Exceptions
safety </a>
</h5>
@@ -148,7 +163,7 @@
of exception safety as long as the underlying parameters provide it.
</p>
<a name="boost_chrono.users_guide.getting_started.install.thread_safety_"></a><h5>
-<a name="id4818331"></a>
+<a name="id4818742"></a>
<a href="getting_started.html#boost_chrono.users_guide.getting_started.install.thread_safety_">Thread
safety </a>
</h5>
@@ -156,7 +171,7 @@
All functions in the library are thread-unsafe except when noted explicitly.
</p>
<a name="boost_chrono.users_guide.getting_started.install.tested_compilers_"></a><h5>
-<a name="id4818355"></a>
+<a name="id4818766"></a>
<a href="getting_started.html#boost_chrono.users_guide.getting_started.install.tested_compilers_">Tested
compilers </a>
</h5>
Modified: sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/tutorial.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/tutorial.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/boost_chrono/users_guide/tutorial.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -7,7 +7,7 @@
<link rel="start" href="../../index.html" title="Boost.Chrono">
<link rel="up" href="../users_guide.html" title=" Users'Guide">
<link rel="prev" href="getting_started.html" title=" Getting Started">
-<link rel="next" href="ext_references.html" title=" References">
+<link rel="next" href="examples.html" title="Examples">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
@@ -20,113 +20,208 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="getting_started.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../users_guide.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="ext_references.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="getting_started.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../users_guide.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="examples.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h3 class="title">
<a name="boost_chrono.users_guide.tutorial"></a>Tutorial
</h3></div></div></div>
<div class="toc"><dl>
-<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.how_to_define_a_thread_clock">How
- to define a thread clock</a></span></dt>
-<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.how_can_i_prefix_each_report_with__boost_current_function__function_signature_">How
- can I prefix each report with <code class="computeroutput"><span class="identifier">BOOST_CURRENT_FUNCTION</span></code>
- function signature?</a></span></dt>
-<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.how_can_i_prefix_each_report_with____file_____line_____pattern_">How
- can I prefix each report with <code class="computeroutput"><span class="identifier">__FILE__</span><span class="special">[</span><span class="identifier">__LINE__</span><span class="special">]</span></code> pattern?</a></span></dt>
-<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.can_i_use_an_stopclock_accumulator_which_is_not_static_">Can
- I use an stopclock accumulator which is not static?</a></span></dt>
-<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.how_can_i_suspend_a_stopwatch_">How
- can I suspend a stopwatch?</a></span></dt>
-<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.how_to_get_specific_statistics_from_stopwatches_accumulator_">How
- to get specific statistics from stopwatches accumulator?</a></span></dt>
-<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.how_can_i_make_a_specific_formatter_when_the_default_do_not_satisfy_my_expectations">How
- can I make a specific formatter when the default do not satisfy my expectations</a></span></dt>
+<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.common_type">Common
+ Type</a></span></dt>
+<dd><dl><dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.common_type.how_to_get_the_common_type_of_inter_type_with_explicit_conversions_">How
+ to get the common type of inter-type with explicit conversions?</a></span></dt></dl></dd>
+<dt><span class="section">Ratio</span></dt>
+<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.clocks__time_point_and_duration">Clocks,
+ time_point and duration</a></span></dt>
+<dd><dl><dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.clocks__time_point_and_duration.how_to_get_the_actual_cpu_milliseconds__or_other_units___used_by_the_current_thread_between_end_and_start_">How
+ to get the actual CPU milliseconds (or other units?) used by the current
+ thread between end and start?</a></span></dt></dl></dd>
+<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks">Stopwatches
+ and Stopclocks</a></span></dt>
+<dd><dl>
+<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_can_i_prefix_each_report_with__boost_current_function__function_signature_">How
+ can I prefix each report with <code class="computeroutput"><span class="identifier">BOOST_CURRENT_FUNCTION</span></code>
+ function signature?</a></span></dt>
+<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_can_i_prefix_each_report_with____file_____line_____pattern_">How
+ can I prefix each report with <code class="computeroutput"><span class="identifier">__FILE__</span><span class="special">[</span><span class="identifier">__LINE__</span><span class="special">]</span></code> pattern?</a></span></dt>
+<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.can_i_use_an_stopclock_accumulator_which_is_not_static_">Can
+ I use an stopclock accumulator which is not static?</a></span></dt>
+<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_can_i_suspend_a_stopwatch_">How
+ can I suspend a stopwatch?</a></span></dt>
+<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_to_get_specific_statistics_from_stopwatches_accumulator_">How
+ to get specific statistics from stopwatches accumulator?</a></span></dt>
+</dl></dd>
+<dt><span class="section">Formatters</span></dt>
+<dd><dl><dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.formatters.how_can_i_make_a_specific_formatter_when_the_default_do_not_satisfy_my_expectations">How
+ can I make a specific formatter when the default do not satisfy my expectations</a></span></dt></dl></dd>
</dl></div>
+<div class="note"><table border="0" summary="Note">
+<tr>
+<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/html/images/note.png"></td>
+<th align="left">Note</th>
+</tr>
+<tr><td align="left" valign="top"><p>
+ If you have not read yet the <a href="../overview/motivation.html" target="_top">motivation
+ section</a>, please read it now.
+ </p></td></tr>
+</table></div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
-<a name="boost_chrono.users_guide.tutorial.how_to_define_a_thread_clock"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.how_to_define_a_thread_clock" title="How
- to define a thread clock">How
- to define a thread clock</a>
+<a name="boost_chrono.users_guide.tutorial.common_type"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.common_type" title="Common
+ Type">Common
+ Type</a>
</h4></div></div></div>
-<p>
- On posix systems for which the macro _POSIX_THREAD_CPUTIME is defined we
- can get the time associated to a specific thread.
- </p>
-<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">thread_clock</span> <span class="special">{</span>
-<span class="keyword">public</span><span class="special">:</span>
- <span class="keyword">typedef</span> <span class="identifier">nanoseconds</span> <span class="identifier">duration</span><span class="special">;</span>
- <span class="keyword">typedef</span> <span class="identifier">duration</span><span class="special">::</span><span class="identifier">rep</span> <span class="identifier">rep</span><span class="special">;</span>
- <span class="keyword">typedef</span> <span class="identifier">duration</span><span class="special">::</span><span class="identifier">period</span> <span class="identifier">period</span><span class="special">;</span>
- <span class="keyword">typedef</span> <span class="identifier">chrono</span><span class="special">::</span><span class="identifier">time_point</span><span class="special"><</span><span class="identifier">process_real_cpu_clock</span><span class="special">></span> <span class="identifier">time_point</span><span class="special">;</span>
- <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">bool</span> <span class="identifier">is_monotonic</span> <span class="special">=</span> <span class="keyword">true</span><span class="special">;</span>
-
- <span class="keyword">static</span> <span class="identifier">time_point</span> <span class="identifier">now</span><span class="special">(</span> <span class="special">)</span> <span class="special">{</span>
- <span class="comment">// get the current thread
-</span> <span class="identifier">pthread_t</span> <span class="identifier">pth</span><span class="special">=</span><span class="identifier">pthread_self</span><span class="special">(</span><span class="keyword">void</span><span class="special">);</span>
- <span class="comment">// get the clock_id associated to the current thread
-</span> <span class="identifier">clockid_t</span> <span class="identifier">clock_id</span><span class="special">;</span>
- <span class="identifier">pthread_getcpuclockid</span><span class="special">(</span><span class="identifier">pth</span><span class="special">,</span> <span class="identifier">clock_id</span><span class="special">);</span>
- <span class="comment">// get the timespec associated to the thread clock
-</span> <span class="keyword">struct</span> <span class="identifier">timespec</span> <span class="identifier">ts</span><span class="special">;</span>
- <span class="keyword">if</span> <span class="special">(</span> <span class="special">::</span><span class="identifier">clock_gettime</span><span class="special">(</span> <span class="identifier">clock_id</span><span class="special">,</span> <span class="special">&</span><span class="identifier">ts</span> <span class="special">)</span> <span class="special">)</span>
- <span class="special">{</span>
- <span class="identifier">boost</span><span class="special">::</span><span class="identifier">throw_exception</span><span class="special">(</span>
- <span class="identifier">system</span><span class="special">::</span><span class="identifier">system_error</span><span class="special">(</span> <span class="identifier">errno</span><span class="special">,</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">system_category</span><span class="special">,</span> <span class="string">"chrono::thread_clock"</span> <span class="special">));</span>
- <span class="special">}</span>
+<div class="toc"><dl><dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.common_type.how_to_get_the_common_type_of_inter_type_with_explicit_conversions_">How
+ to get the common type of inter-type with explicit conversions?</a></span></dt></dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.users_guide.tutorial.common_type.how_to_get_the_common_type_of_inter_type_with_explicit_conversions_"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.common_type.how_to_get_the_common_type_of_inter_type_with_explicit_conversions_" title="How
+ to get the common type of inter-type with explicit conversions?">How
+ to get the common type of inter-type with explicit conversions?</a>
+</h5></div></div></div>
+<p>
+ The default definition of <code class="computeroutput"><span class="identifier">common_type</span></code>
+ demands the conversion be implicit. However the trait can be specialized
+ for user-defined types which want to limit their inter-type conversions
+ to explicit, and yet still want to interoperate with the <code class="computeroutput"><span class="identifier">common_type</span></code> facility.
+ </p>
+</div>
+</div>
+<div class="section" lang="en"><div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.tutorial.ratio"></a>Ratio
+</h4></div></div></div></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h4 class="title">
+<a name="boost_chrono.users_guide.tutorial.clocks__time_point_and_duration"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.clocks__time_point_and_duration" title="Clocks,
+ time_point and duration">Clocks,
+ time_point and duration</a>
+</h4></div></div></div>
+<div class="toc"><dl><dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.clocks__time_point_and_duration.how_to_get_the_actual_cpu_milliseconds__or_other_units___used_by_the_current_thread_between_end_and_start_">How
+ to get the actual CPU milliseconds (or other units?) used by the current
+ thread between end and start?</a></span></dt></dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.users_guide.tutorial.clocks__time_point_and_duration.how_to_get_the_actual_cpu_milliseconds__or_other_units___used_by_the_current_thread_between_end_and_start_"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.clocks__time_point_and_duration.how_to_get_the_actual_cpu_milliseconds__or_other_units___used_by_the_current_thread_between_end_and_start_" title="How
+ to get the actual CPU milliseconds (or other units?) used by the current
+ thread between end and start?">How
+ to get the actual CPU milliseconds (or other units?) used by the current
+ thread between end and start?</a>
+</h5></div></div></div>
+<p>
+ You can use <code class="computeroutput"><span class="identifier">duration_cast</span><span class="special"><></span></code> to convert the <code class="computeroutput"><span class="identifier">thread_clock</span><span class="special">::</span><span class="identifier">duration</span></code> into whatever units you desire.
+ This facility will round down (truncate) if an exact conversion is not
+ possible. Ex:
+ </p>
+<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">milliseconds</span> <span class="identifier">ms</span><span class="special">;</span>
+<span class="identifier">ms</span> <span class="identifier">d</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration_cast</span><span class="special"><</span><span class="identifier">ms</span><span class="special">>(</span><span class="identifier">end</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">);</span>
- <span class="comment">// transform to nanoseconds
-</span> <span class="keyword">return</span> <span class="identifier">time_point</span><span class="special">(</span><span class="identifier">duration</span><span class="special">(</span>
- <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">thread_clock</span><span class="special">::</span><span class="identifier">rep</span><span class="special">>(</span> <span class="identifier">ts</span><span class="special">.</span><span class="identifier">tv_sec</span> <span class="special">)</span> <span class="special">*</span> <span class="number">1000000000</span> <span class="special">+</span> <span class="identifier">ts</span><span class="special">.</span><span class="identifier">tv_nsec</span><span class="special">));</span>
+<span class="comment">// d now holds the number of milliseconds from start to end.
+</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">ms</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="string">"ms\n"</span><span class="special">;</span>
+</pre>
+<p>
+ As <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">thread_clock</span><span class="special">::</span><span class="identifier">duration</span></code> is nanoseconds, we can convert
+ to <code class="computeroutput"><span class="identifier">nanoseconds</span></code>, or some
+ integral-based duration which <code class="computeroutput"><span class="identifier">nanoseconds</span></code>
+ will always exactly convert to, then <code class="computeroutput"><span class="identifier">duration_cast</span><span class="special"><></span></code> is unnecessary:
+ </p>
+<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">nanoseconds</span> <span class="identifier">ns</span><span class="special">;</span>
+<span class="identifier">ns</span> <span class="identifier">d</span> <span class="special">=</span> <span class="identifier">end</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">;</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">ns</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="string">"ns\n"</span><span class="special">;</span>
+</pre>
+<p>
+ If you need seconds with a floating point representation you can also
+ eliminate the <code class="computeroutput"><span class="identifier">duration_cast</span><span class="special"><></span></code>:
+ </p>
+<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="keyword">double</span><span class="special">></span> <span class="identifier">sec</span><span class="special">;</span> <span class="comment">// seconds, stored with a double
+</span><span class="identifier">sec</span> <span class="identifier">d</span> <span class="special">=</span> <span class="identifier">end</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">;</span>
+<span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">sec</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="string">"s\n"</span><span class="special">;</span>
+</pre>
+<p>
+ If you're not sure if you need <code class="computeroutput"><span class="identifier">duration_cast</span><span class="special"><></span></code> or not, feel free to try it without.
+ If the conversion is exact, or if the destination has a floating point
+ representation, it will compile. Else it will not compile.
+ </p>
+<p>
+ If you would like to programmatically inspect <code class="computeroutput"><span class="identifier">thread_clock</span><span class="special">::</span><span class="identifier">duration</span></code>,
+ you can get the representation type with <code class="computeroutput"><span class="identifier">thread_clock</span><span class="special">::</span><span class="identifier">rep</span></code>,
+ and the tick period with <code class="computeroutput"><span class="identifier">thread_clock</span><span class="special">::</span><span class="identifier">period</span></code>
+ (which should be a type <code class="computeroutput"><span class="identifier">ratio</span></code>
+ which has nested values <code class="computeroutput"><span class="identifier">ratio</span><span class="special">::</span><span class="identifier">num</span></code>
+ and <code class="computeroutput"><span class="identifier">ratio</span><span class="special">::</span><span class="identifier">den</span></code>). The tick period of <code class="computeroutput"><span class="identifier">thread_clock</span></code> is <code class="computeroutput"><span class="identifier">thread_clock</span><span class="special">::</span><span class="identifier">period</span><span class="special">::</span><span class="identifier">num</span> <span class="special">/</span> <span class="identifier">thread_clock</span><span class="special">::</span><span class="identifier">period</span><span class="special">::</span><span class="identifier">den</span></code>
+ seconds: 1/1000000000 in this case (1 billionth of a second), stored
+ in a long long.
+ </p>
+<p>
+ If you need to use <code class="computeroutput"><span class="identifier">duration_cast</span><span class="special"><></span></code>, but want to round up, instead
+ of down when the conversion is inexact, here is a handy little helper
+ function to do so. Writing it is actually a good starter project for
+ understanding chrono:
+ </p>
+<pre class="programlisting"><span class="keyword">template</span> <span class="special"><</span><span class="keyword">class</span> <span class="identifier">ToDuration</span><span class="special">,</span> <span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">></span>
+<span class="identifier">ToDuration</span>
+<span class="identifier">round_up</span><span class="special">(</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration</span><span class="special"><</span><span class="identifier">Rep</span><span class="special">,</span> <span class="identifier">Period</span><span class="special">></span> <span class="identifier">d</span><span class="special">)</span>
+<span class="special">{</span>
+ <span class="comment">// first round down
+</span> <span class="identifier">ToDuration</span> <span class="identifier">result</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">duration_cast</span><span class="special"><</span><span class="identifier">ToDuration</span><span class="special">>(</span><span class="identifier">d</span><span class="special">);</span>
+ <span class="keyword">if</span> <span class="special">(</span><span class="identifier">result</span> <span class="special"><</span> <span class="identifier">d</span><span class="special">)</span> <span class="comment">// comparisons are *always* exact
+</span> <span class="special">++</span><span class="identifier">result</span><span class="special">;</span> <span class="comment">// increment by one tick period
+</span> <span class="keyword">return</span> <span class="identifier">result</span><span class="special">;</span>
+<span class="special">}</span>
- <span class="special">}</span>
- <span class="keyword">static</span> <span class="identifier">time_point</span> <span class="identifier">now</span><span class="special">(</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">error_code</span> <span class="special">&</span> <span class="identifier">ec</span> <span class="special">)</span> <span class="special">{</span>
- <span class="comment">// get the current thread
-</span> <span class="identifier">pthread_t</span> <span class="identifier">pth</span><span class="special">=</span><span class="identifier">pthread_self</span><span class="special">(</span><span class="keyword">void</span><span class="special">);</span>
- <span class="comment">// get the clock_id associated to the current thread
-</span> <span class="identifier">clockid_t</span> <span class="identifier">clock_id</span><span class="special">;</span>
- <span class="identifier">pthread_getcpuclockid</span><span class="special">(</span><span class="identifier">pth</span><span class="special">,</span> <span class="identifier">clock_id</span><span class="special">);</span>
- <span class="comment">// get the timespec associated to the thread clock
-</span> <span class="keyword">struct</span> <span class="identifier">timespec</span> <span class="identifier">ts</span><span class="special">;</span>
- <span class="keyword">if</span> <span class="special">(</span> <span class="special">::</span><span class="identifier">clock_gettime</span><span class="special">(</span> <span class="identifier">clock_id</span><span class="special">,</span> <span class="special">&</span><span class="identifier">ts</span> <span class="special">)</span> <span class="special">)</span>
- <span class="special">{</span>
- <span class="identifier">ec</span><span class="special">.</span><span class="identifier">assign</span><span class="special">(</span> <span class="identifier">errno</span><span class="special">,</span> <span class="identifier">system</span><span class="special">::</span><span class="identifier">system_category</span> <span class="special">);</span>
- <span class="keyword">return</span> <span class="identifier">time_point</span><span class="special">();</span>
- <span class="special">}</span>
- <span class="identifier">ec</span><span class="special">.</span><span class="identifier">clear</span><span class="special">();</span>
- <span class="comment">// transform to nanoseconds
-</span> <span class="keyword">return</span> <span class="identifier">time_point</span><span class="special">(</span><span class="identifier">duration</span><span class="special">(</span>
- <span class="keyword">static_cast</span><span class="special"><</span><span class="identifier">thread_clock</span><span class="special">::</span><span class="identifier">rep</span><span class="special">>(</span> <span class="identifier">ts</span><span class="special">.</span><span class="identifier">tv_sec</span> <span class="special">)</span> <span class="special">*</span> <span class="number">1000000000</span> <span class="special">+</span> <span class="identifier">ts</span><span class="special">.</span><span class="identifier">tv_nsec</span><span class="special">));</span>
- <span class="special">}</span>
-<span class="special">};</span>
+<span class="keyword">typedef</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">milliseconds</span> <span class="identifier">ms</span><span class="special">;</span>
+<span class="identifier">ms</span> <span class="identifier">d</span> <span class="special">=</span> <span class="identifier">round_up</span><span class="special"><</span><span class="identifier">ms</span><span class="special">>(</span><span class="identifier">end</span> <span class="special">-</span> <span class="identifier">start</span><span class="special">);</span>
+<span class="comment">// d now holds the number of milliseconds from start to end, rounded up.
+</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special"><<</span> <span class="identifier">ms</span><span class="special">.</span><span class="identifier">count</span><span class="special">()</span> <span class="special"><<</span> <span class="string">"ms\n"</span><span class="special">;</span>
</pre>
</div>
+</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
-<a name="boost_chrono.users_guide.tutorial.how_can_i_prefix_each_report_with__boost_current_function__function_signature_"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.how_can_i_prefix_each_report_with__boost_current_function__function_signature_" title="How
- can I prefix each report with BOOST_CURRENT_FUNCTION
- function signature?">How
- can I prefix each report with <code class="computeroutput"><span class="identifier">BOOST_CURRENT_FUNCTION</span></code>
- function signature?</a>
+<a name="boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks" title="Stopwatches
+ and Stopclocks">Stopwatches
+ and Stopclocks</a>
</h4></div></div></div>
-<p>
- You will need to give a specific format to you stopclock. You just need
- to concatenate the your specific patter to the default_format of the formatter.
- </p>
-<p>
- For example, for a stopclock_accumulator the default formatter is stopwatch_accumulator_formatter,
- this you will need to do something like:
- </p>
+<div class="toc"><dl>
+<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_can_i_prefix_each_report_with__boost_current_function__function_signature_">How
+ can I prefix each report with <code class="computeroutput"><span class="identifier">BOOST_CURRENT_FUNCTION</span></code>
+ function signature?</a></span></dt>
+<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_can_i_prefix_each_report_with____file_____line_____pattern_">How
+ can I prefix each report with <code class="computeroutput"><span class="identifier">__FILE__</span><span class="special">[</span><span class="identifier">__LINE__</span><span class="special">]</span></code> pattern?</a></span></dt>
+<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.can_i_use_an_stopclock_accumulator_which_is_not_static_">Can
+ I use an stopclock accumulator which is not static?</a></span></dt>
+<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_can_i_suspend_a_stopwatch_">How
+ can I suspend a stopwatch?</a></span></dt>
+<dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_to_get_specific_statistics_from_stopwatches_accumulator_">How
+ to get specific statistics from stopwatches accumulator?</a></span></dt>
+</dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_can_i_prefix_each_report_with__boost_current_function__function_signature_"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_can_i_prefix_each_report_with__boost_current_function__function_signature_" title="How
+ can I prefix each report with BOOST_CURRENT_FUNCTION
+ function signature?">How
+ can I prefix each report with <code class="computeroutput"><span class="identifier">BOOST_CURRENT_FUNCTION</span></code>
+ function signature?</a>
+</h5></div></div></div>
+<p>
+ You will need to give a specific format to your stopclock. You just need
+ to concatenate your specific pattern to the default_format of the formatter.
+ </p>
+<p>
+ For example, for a stopclock_accumulator the default formatter is stopwatch_accumulator_formatter,
+ you will need to do something like:
+ </p>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">stopclock_accumulator</span><span class="special"><></span> <span class="identifier">acc</span><span class="special">(</span>
- <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">(</span><span class="identifier">BOOST_CURRENT_FUNCTION</span><span class="special">)</span> <span class="special">+</span> <span class="string">": "</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">(</span><span class="identifier">BOOST_CURRENT_FUNCTION</span><span class="special">)</span> <span class="special">+</span> <span class="string">": "</span>
<span class="special">+</span> <span class="identifier">stopwatch_accumulator_formatter</span><span class="special">::</span><span class="identifier">default_format</span><span class="special">()</span>
<span class="special">);</span>
<span class="identifier">stopclock_accumulator</span><span class="special"><>::</span><span class="identifier">scoped_run</span> <span class="identifier">_</span><span class="special">(</span><span class="identifier">acc</span><span class="special">);</span>
</pre>
<p>
- Some of you will say that this is too long to type just to get the a report.
- You can of course define your own macro as
- </p>
+ Some of you will say that this is too long to type just to get the a
+ report. You can of course define your own macro as
+ </p>
<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">REPORT_FUNCTION_ACCUMULATED_LIFETIME</span><span class="special">\</span>
<span class="keyword">static</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">chrono</span><span class="special">::</span><span class="identifier">stopclock_accumulator</span><span class="special"><></span> <span class="special">\</span>
<span class="identifier">BOOST_JOIN</span><span class="special">(</span><span class="identifier">_accumulator_</span><span class="special">,</span> <span class="identifier">__LINE__</span><span class="special">)</span><span class="identifier">_</span>
@@ -138,8 +233,8 @@
<span class="special">(</span><span class="identifier">BOOST_JOIN</span><span class="special">(</span><span class="identifier">_accumulator_</span><span class="special">,</span> <span class="identifier">__LINE__</span><span class="special">))</span>
</pre>
<p>
- With this macro you will just have
- </p>
+ With this macro you will just have to write
+ </p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">foo</span><span class="special">()</span>
<span class="special">{</span>
<span class="identifier">REPORT_FUNCTION_ACCUMULATED_LIFETIME</span><span class="special">()</span> <span class="special">;</span>
@@ -149,28 +244,28 @@
</pre>
</div>
<div class="section" lang="en">
-<div class="titlepage"><div><div><h4 class="title">
-<a name="boost_chrono.users_guide.tutorial.how_can_i_prefix_each_report_with____file_____line_____pattern_"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.how_can_i_prefix_each_report_with____file_____line_____pattern_" title="How
- can I prefix each report with __FILE__[__LINE__] pattern?">How
- can I prefix each report with <code class="computeroutput"><span class="identifier">__FILE__</span><span class="special">[</span><span class="identifier">__LINE__</span><span class="special">]</span></code> pattern?</a>
-</h4></div></div></div>
-<p>
- When you want to prefix with the <code class="computeroutput"><span class="identifier">__FILE__</span><span class="special">[</span><span class="identifier">__LINE__</span><span class="special">]</span></code> pattern you can follow the same technique
- as described below:
- </p>
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_can_i_prefix_each_report_with____file_____line_____pattern_"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_can_i_prefix_each_report_with____file_____line_____pattern_" title="How
+ can I prefix each report with __FILE__[__LINE__] pattern?">How
+ can I prefix each report with <code class="computeroutput"><span class="identifier">__FILE__</span><span class="special">[</span><span class="identifier">__LINE__</span><span class="special">]</span></code> pattern?</a>
+</h5></div></div></div>
+<p>
+ When you want to prefix with the <code class="computeroutput"><span class="identifier">__FILE__</span><span class="special">[</span><span class="identifier">__LINE__</span><span class="special">]</span></code> pattern you can follow the same technique
+ as described below:
+ </p>
<pre class="programlisting"><span class="preprocessor">#define</span> <span class="identifier">REPORT_LINE_ACCUMULATED_LIFETIME</span> <span class="special">\</span>
- <span class="keyword">static</span> <span class="identifier">stopclock_accumulator</span><span class="special"><></span>
+ <span class="keyword">static</span> <span class="identifier">stopclock_accumulator</span><span class="special"><></span>
<span class="identifier">BOOST_JOIN</span><span class="special">(</span><span class="identifier">_accumulator_</span><span class="special">,</span> <span class="identifier">__LINE__</span><span class="special">)</span> <span class="special">\</span>
- <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">(</span><span class="identifier">__FILE__</span><span class="special">)</span> <span class="special">+</span> <span class="string">"["</span> <span class="special">+</span> <span class="identifier">BOOST_STRINGIZE</span><span class="special">(</span><span class="identifier">__LINE__</span><span class="special">)</span> <span class="special">+</span> <span class="string">"] "</span>
+ <span class="special">(</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">(</span><span class="identifier">__FILE__</span><span class="special">)</span> <span class="special">+</span> <span class="string">"["</span> <span class="special">+</span> <span class="identifier">BOOST_STRINGIZE</span><span class="special">(</span><span class="identifier">__LINE__</span><span class="special">)</span> <span class="special">+</span> <span class="string">"] "</span>
<span class="special">+</span> <span class="identifier">stopwatch_accumulator_formatter</span><span class="special">::</span><span class="identifier">default_format</span><span class="special">()</span> <span class="special">\</span>
<span class="special">);</span> <span class="special">\</span>
<span class="identifier">stopclock_accumulator</span><span class="special"><>::</span><span class="identifier">scoped_run</span> <span class="special">\</span>
- <span class="identifier">BOOST_JOIN</span><span class="special">(</span><span class="identifier">_accumulator_run_</span><span class="special">,</span> <span class="identifier">__LINE__</span><span class="special">)</span>
+ <span class="identifier">BOOST_JOIN</span><span class="special">(</span><span class="identifier">_accumulator_run_</span><span class="special">,</span> <span class="identifier">__LINE__</span><span class="special">)</span>
<span class="special">(</span><span class="identifier">BOOST_JOIN</span><span class="special">(</span><span class="identifier">_accumulator_</span><span class="special">,</span> <span class="identifier">__LINE__</span><span class="special">))</span>
</pre>
<p>
- Now you can mix fcntion and line reports as follows
- </p>
+ Now you can mix fcntion and line reports as follows
+ </p>
<pre class="programlisting"><span class="keyword">void</span> <span class="identifier">foo</span><span class="special">()</span>
<span class="special">{</span>
<span class="identifier">REPORT_FUNCTION_ACCUMULATED_LIFETIME</span><span class="special">;</span>
@@ -184,19 +279,19 @@
</pre>
</div>
<div class="section" lang="en">
-<div class="titlepage"><div><div><h4 class="title">
-<a name="boost_chrono.users_guide.tutorial.can_i_use_an_stopclock_accumulator_which_is_not_static_"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.can_i_use_an_stopclock_accumulator_which_is_not_static_" title="Can
- I use an stopclock accumulator which is not static?">Can
- I use an stopclock accumulator which is not static?</a>
-</h4></div></div></div>
-<p>
- The typical example of stopclock_accumulator is to get statistical measures
- of the time a function takes for each one of its calls. You an also use
- stopclock_accumulator to get statistical measures of the time a given loop
- takes for each one of its laps.
- </p>
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.can_i_use_an_stopclock_accumulator_which_is_not_static_"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.can_i_use_an_stopclock_accumulator_which_is_not_static_" title="Can
+ I use an stopclock accumulator which is not static?">Can
+ I use an stopclock accumulator which is not static?</a>
+</h5></div></div></div>
+<p>
+ The typical example of stopclock_accumulator is to get statistical measures
+ of the time a function takes for each one of its calls. You an also use
+ stopclock_accumulator to get statistical measures of the time a given
+ loop takes for each one of its laps.
+ </p>
<pre class="programlisting"><span class="identifier">stopclock_accumulator</span><span class="special"><></span> <span class="identifier">acc</span><span class="special">(</span>
- <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">(</span><span class="identifier">__FILE__</span><span class="special">)</span> <span class="special">+</span> <span class="string">"["</span> <span class="special">+</span> <span class="identifier">BOOST_STRINGIZE</span><span class="special">(</span><span class="identifier">__LINE__</span><span class="special">)</span> <span class="special">+</span> <span class="string">"] "</span>
+ <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span><span class="special">(</span><span class="identifier">__FILE__</span><span class="special">)</span> <span class="special">+</span> <span class="string">"["</span> <span class="special">+</span> <span class="identifier">BOOST_STRINGIZE</span><span class="special">(</span><span class="identifier">__LINE__</span><span class="special">)</span> <span class="special">+</span> <span class="string">"] "</span>
<span class="special">+</span> <span class="identifier">stopwatch_accumulator_formatter</span><span class="special">::</span><span class="identifier">default_format</span><span class="special">()</span>
<span class="special">);</span>
<span class="keyword">for</span> <span class="special">(</span><span class="keyword">int</span> <span class="identifier">i</span><span class="special">=</span><span class="number">0</span><span class="special">;</span> <span class="identifier">i</span><span class="special"><</span><span class="identifier">N</span><span class="special">;</span> <span class="identifier">i</span><span class="special">++)</span> <span class="special">{</span>
@@ -206,11 +301,11 @@
</pre>
</div>
<div class="section" lang="en">
-<div class="titlepage"><div><div><h4 class="title">
-<a name="boost_chrono.users_guide.tutorial.how_can_i_suspend_a_stopwatch_"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.how_can_i_suspend_a_stopwatch_" title="How
- can I suspend a stopwatch?">How
- can I suspend a stopwatch?</a>
-</h4></div></div></div>
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_can_i_suspend_a_stopwatch_"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_can_i_suspend_a_stopwatch_" title="How
+ can I suspend a stopwatch?">How
+ can I suspend a stopwatch?</a>
+</h5></div></div></div>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">chrono</span><span class="special">/</span><span class="identifier">stopwatch</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">cmath</span><span class="special">></span>
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">thread</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
@@ -229,29 +324,29 @@
</pre>
</div>
<div class="section" lang="en">
-<div class="titlepage"><div><div><h4 class="title">
-<a name="boost_chrono.users_guide.tutorial.how_to_get_specific_statistics_from_stopwatches_accumulator_"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.how_to_get_specific_statistics_from_stopwatches_accumulator_" title="How
- to get specific statistics from stopwatches accumulator?">How
- to get specific statistics from stopwatches accumulator?</a>
-</h4></div></div></div>
-<p>
- There are two use cases that coul need to change the statistics associated
- to a stopwatches accumulator:
- </p>
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_to_get_specific_statistics_from_stopwatches_accumulator_"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.stopwatches_and_stopclocks.how_to_get_specific_statistics_from_stopwatches_accumulator_" title="How
+ to get specific statistics from stopwatches accumulator?">How
+ to get specific statistics from stopwatches accumulator?</a>
+</h5></div></div></div>
+<p>
+ There are two use cases that coul need to change the statistics associated
+ to a stopwatches accumulator:
+ </p>
<div class="orderedlist"><ol type="1">
<li>
- We want to reduce the default reporting and we preffer to adapt the statistics
- to the reporting
- </li>
+ We want to reduce the default reporting and we preffer to adapt the
+ statistics to the reporting
+ </li>
<li>
- We want to report other statistics of the samples
- </li>
+ We want to report other statistics of the samples
+ </li>
</ol></div>
<p>
- For the first case we just need to change the accumulator_set and the format
- we want to get. Imagin we want to get only the count, sam and mean statistics,
- no need to calculate the min neither the max.
- </p>
+ For the first case we just need to change the accumulator_set and the
+ format we want to get. Imagin we want to get only the count, sam and
+ mean statistics, no need to calculate the min neither the max.
+ </p>
<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">accumulators</span><span class="special">;</span>
<span class="keyword">typedef</span> <span class="identifier">stopwatch_accumulator</span><span class="special"><</span><span class="identifier">process_real_cpu_clock</span><span class="special">,</span>
@@ -276,26 +371,33 @@
<span class="special">}</span>
</pre>
<p>
- But wat would hapend if we haven't forced the format:
- </p>
+ But what would hapend if we haven't forced the format:
+ </p>
<pre class="programlisting"><span class="keyword">static</span> <span class="identifier">my_stopwatch_accumulator_reporter</span> <span class="identifier">acc</span><span class="special">;</span>
<span class="identifier">my_stopwatch_accumulator_reporter</span><span class="special">::</span><span class="identifier">scoped_run</span> <span class="identifier">_</span><span class="special">(</span><span class="identifier">acc</span><span class="special">);</span>
</pre>
<p>
- Unfortunately there is no error at compile time. Fortunately, the run-time
- execution is not undefined and will return 0 for the missing statistics.
- </p>
+ Unfortunately there is no error at compile time. Fortunately, the run-time
+ execution is not undefined and will return 0 for the missing statistics.
+ </p>
+</div>
</div>
<div class="section" lang="en">
<div class="titlepage"><div><div><h4 class="title">
-<a name="boost_chrono.users_guide.tutorial.how_can_i_make_a_specific_formatter_when_the_default_do_not_satisfy_my_expectations"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.how_can_i_make_a_specific_formatter_when_the_default_do_not_satisfy_my_expectations" title="How
- can I make a specific formatter when the default do not satisfy my expectations">How
- can I make a specific formatter when the default do not satisfy my expectations</a>
+<a name="boost_chrono.users_guide.tutorial.formatters"></a>Formatters
</h4></div></div></div>
-<p>
- Imagine then that we want to report the tag::variance(lazy). We will need
- to include the specific accumulator file
- </p>
+<div class="toc"><dl><dt><span class="section"><a href="tutorial.html#boost_chrono.users_guide.tutorial.formatters.how_can_i_make_a_specific_formatter_when_the_default_do_not_satisfy_my_expectations">How
+ can I make a specific formatter when the default do not satisfy my expectations</a></span></dt></dl></div>
+<div class="section" lang="en">
+<div class="titlepage"><div><div><h5 class="title">
+<a name="boost_chrono.users_guide.tutorial.formatters.how_can_i_make_a_specific_formatter_when_the_default_do_not_satisfy_my_expectations"></a><a href="tutorial.html#boost_chrono.users_guide.tutorial.formatters.how_can_i_make_a_specific_formatter_when_the_default_do_not_satisfy_my_expectations" title="How
+ can I make a specific formatter when the default do not satisfy my expectations">How
+ can I make a specific formatter when the default do not satisfy my expectations</a>
+</h5></div></div></div>
+<p>
+ Imagine then that we want to report the <code class="computeroutput"><span class="identifier">tag</span><span class="special">::</span><span class="identifier">variance</span><span class="special">(</span><span class="identifier">lazy</span><span class="special">)</span></code>. We will need to include the specific
+ accumulator file
+ </p>
<pre class="programlisting"><span class="special">...</span>
<span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">accumulators</span><span class="special">/</span><span class="identifier">statistics</span><span class="special">/</span><span class="identifier">variance</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span>
<span class="special">...</span>
@@ -311,10 +413,10 @@
<span class="special">>::</span><span class="identifier">reporter</span> <span class="identifier">my_stopwatch_accumulator_reporter</span><span class="special">;</span>
</pre>
<p>
- But what happens if we add new statistics to the accumulator_set that are
- not taken in account by the default formatter? These statistics will simply
- be ignored. So we will need to define own own accumulator formatter.
- </p>
+ But what happens if we add new statistics to the accumulator_set that
+ are not taken in account by the default formatter? These statistics will
+ simply be ignored. So we will need to define own own accumulator formatter.
+ </p>
<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">stopwatch_accumulator</span><span class="special"><</span><span class="identifier">process_real_cpu_clock</span><span class="special">,</span>
<span class="identifier">accumulator_set</span><span class="special"><</span><span class="identifier">process_real_cpu_clock</span><span class="special">::</span><span class="identifier">rep</span><span class="special">,</span>
<span class="identifier">features</span><span class="special"><</span>
@@ -328,9 +430,9 @@
<span class="special">>::</span><span class="identifier">reporter</span> <span class="identifier">my_stopwatch_accumulator_reporter</span><span class="special">;</span>
</pre>
<p>
- Next follow the definition of a formatter taking care of count, sum, mean
- and variance
- </p>
+ Next follow the definition of a formatter taking care of count, sum,
+ mean and variance
+ </p>
<pre class="programlisting"><span class="keyword">class</span> <span class="identifier">my_stopwatch_accumulator_formatter</span> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
<span class="keyword">typedef</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">string</span> <span class="identifier">string_type</span><span class="special">;</span>
@@ -390,6 +492,7 @@
</pre>
</div>
</div>
+</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2008 Howard Hinnant<br>Copyright © 2006 , 2008 Beman Dawes<br>Copyright © 2009 -2010 Vicente J. Botet Escriba<p>
@@ -400,7 +503,7 @@
</tr></table>
<hr>
<div class="spirit-nav">
-<a accesskey="p" href="getting_started.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../users_guide.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="ext_references.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
+<a accesskey="p" href="getting_started.html"><img src="../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../users_guide.html"><img src="../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="examples.html"><img src="../../../../../../doc/html/images/next.png" alt="Next"></a>
</div>
</body>
</html>
Modified: sandbox/chrono/libs/chrono/doc/html/index.html
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/index.html (original)
+++ sandbox/chrono/libs/chrono/doc/html/index.html 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -38,7 +38,7 @@
<div><p class="copyright">Copyright © 2006 , 2008 Beman Dawes</p></div>
<div><p class="copyright">Copyright © 2009 -2010 Vicente J. Botet Escriba</p></div>
<div><div class="legalnotice">
-<a name="id4803373"></a><p>
+<a name="id4762408"></a><p>
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)
</p>
@@ -52,13 +52,14 @@
<dt><span class="section">Overview</span></dt>
<dd><dl>
<dt><span class="section">Motivation</span></dt>
-<dt><span class="section">Caveat emptor</span></dt>
+<dt><span class="section"> Caveat emptor</span></dt>
</dl></dd>
<dt><span class="section"> Users'Guide</span></dt>
<dd><dl>
<dt><span class="section"> Getting Started</span></dt>
<dt><span class="section">Tutorial</span></dt>
-<dt><span class="section"> References</span></dt>
+<dt><span class="section">Examples</span></dt>
+<dt><span class="section"> External Resources</span></dt>
</dl></dd>
<dt><span class="section"> Reference </span></dt>
<dd><dl>
@@ -73,27 +74,6 @@
<dt><span class="section"><a href="boost_chrono/reference/deprecated_headers.html">Deprecated
Headers</a></span></dt>
</dl></dd>
-<dt><span class="section">Examples</span></dt>
-<dd><dl>
-<dt><span class="section">SI-units</span></dt>
-<dt><span class="section"><a href="boost_chrono/examples/how_you_override_the_duration_s_default_constructor.html">How
- you override the duration's default constructor</a></span></dt>
-<dt><span class="section">min utility</span></dt>
-<dt><span class="section">Cycle count</span></dt>
-<dt><span class="section">xtime conversions</span></dt>
-<dt><span class="section">xtime_clock</span></dt>
-<dt><span class="section">runtime_resolution</span></dt>
-<dt><span class="section"><a href="boost_chrono/examples/simulated_thread_interface_demonstration_program.html">Simulated
- thread interface demonstration program</a></span></dt>
-<dt><span class="section">Saturating</span></dt>
-<dt><span class="section"><a href="boost_chrono/examples/howard_hinnant_s_original_demonstration_program.html">Howard
- Hinnant's original demonstration program</a></span></dt>
-<dt><span class="section"><a href="boost_chrono/examples/a_tiny_program_that_times_how_long_until_a_key_is_struck.html">A
- tiny program that times how long until a key is struck</a></span></dt>
-<dt><span class="section">stopclock_example.cpp</span></dt>
-<dt><span class="section">stopclock_example2.cpp</span></dt>
-<dt><span class="section">time command</span></dt>
-</dl></dd>
<dt><span class="section">Appendices</span></dt>
<dd><dl>
<dt><span class="section"> Appendix A: History</span></dt>
@@ -121,7 +101,7 @@
</table></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
-<td align="left"><p><small>Last revised: May 28, 2010 at 23:01:29 GMT</small></p></td>
+<td align="left"><p><small>Last revised: June 26, 2010 at 02:41:06 GMT</small></p></td>
<td align="right"><div class="copyright-footer"></div></td>
</tr></table>
<hr>
Modified: sandbox/chrono/libs/chrono/doc/html/standalone_HTML.manifest
==============================================================================
--- sandbox/chrono/libs/chrono/doc/html/standalone_HTML.manifest (original)
+++ sandbox/chrono/libs/chrono/doc/html/standalone_HTML.manifest 2010-06-25 22:51:35 EDT (Fri, 25 Jun 2010)
@@ -1,10 +1,11 @@
index.html
boost_chrono/overview.html
boost_chrono/overview/motivation.html
-boost_chrono/overview/caveat_emptor.html
+boost_chrono/overview/caveat.html
boost_chrono/users_guide.html
boost_chrono/users_guide/getting_started.html
boost_chrono/users_guide/tutorial.html
+boost_chrono/users_guide/examples.html
boost_chrono/users_guide/ext_references.html
boost_chrono/reference.html
boost_chrono/reference/cpp0x.html
@@ -13,21 +14,6 @@
boost_chrono/reference/stopwatch_reporters.html
boost_chrono/reference/stopwatch_formatters.html
boost_chrono/reference/deprecated_headers.html
-boost_chrono/examples.html
-boost_chrono/examples/si_units.html
-boost_chrono/examples/how_you_override_the_duration_s_default_constructor.html
-boost_chrono/examples/min_utility.html
-boost_chrono/examples/cycle_count.html
-boost_chrono/examples/xtime_conversions.html
-boost_chrono/examples/xtime_clock.html
-boost_chrono/examples/runtime_resolution.html
-boost_chrono/examples/simulated_thread_interface_demonstration_program.html
-boost_chrono/examples/saturating.html
-boost_chrono/examples/howard_hinnant_s_original_demonstration_program.html
-boost_chrono/examples/a_tiny_program_that_times_how_long_until_a_key_is_struck.html
-boost_chrono/examples/stopclock_example_cpp.html
-boost_chrono/examples/stopclock_example2_cpp.html
-boost_chrono/examples/time_command.html
boost_chrono/appendices.html
boost_chrono/appendices/history.html
boost_chrono/appendices/rationale.html
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