]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/chrono/doc/chrono.qbk
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / chrono / doc / chrono.qbk
1 [/
2 / Copyright (c) 2008 Howard Hinnant
3 / Copyright (c) 2006, 2008 Beman Dawes
4 / Copyright (c) 2009-2015 Vicente J. Botet Escriba
5 /
6 / Distributed under the Boost Software License, Version 1.0. (See accompanying
7 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 /]
9
10 [library Boost.Chrono
11 [quickbook 1.5]
12 [version 2.0.5]
13 [authors [Hinnant, Howard]]
14 [authors [Dawes, Beman]]
15 [authors [Botet Escriba, Vicente J.]]
16 [copyright 2008 Howard Hinnant]
17 [copyright 2006, 2008 Beman Dawes]
18 [copyright 2009-2013 Vicente J. Botet Escriba]
19 [category utilities system]
20 [id chrono]
21 [dirname chrono]
22 [purpose
23 Useful time utilities.
24 ]
25 [license
26 Distributed under the Boost Software License, Version 1.0.
27 (See accompanying file LICENSE_1_0.txt or copy at
28 [@http://www.boost.org/LICENSE_1_0.txt])
29 ]
30 ]
31
32 [/==================]
33 [def __Boost_Chrono__ [*Boost.Chrono]]
34 [def __Boost_Chrono [*Boost.Chrono]]
35
36 [def __see_bellow__ ['see bellow]]
37
38 [/===============================================]
39 [def __inherit [*Inherits:]]
40 [def __std_ref [*C++ Standard Reference:]]
41 [def __header [*Header:]]
42 [def __compat [*Compiler Compatibility:]]
43 [def __examples [*Examples:]]
44 [def __example [*Example:]]
45 [def __type [*type:]]
46 [def __returns [*Returns:]]
47 [def __return_type [*Return Type:]]
48 [def __throws [*Throws:]]
49 [def __remarks [*Remarks:]]
50 [def __effects [*Effects:]]
51 [def __post_conditions [*Post Conditions:]]
52 [def __post_condition [*Post Conditions:]]
53 [def __postcondition [*Post Conditions:]]
54 [def __pre_conditions [*Pre Conditions:]]
55 [def __precondition [*Pre Conditions:]]
56 [def __requires [*Requires:]]
57 [def __params [*Parameters:]]
58 [template param [p] [*[p]:]]
59
60 [template mu[]'''μ'''] [/ Greek small letter mu]
61 [template plusminus[]'''±'''] [/ ? plus or minus sign]
62
63 [def __mus [mu]s]
64
65 [/===============================================]
66 [def __common_type `common_type`]
67
68
69 [/===============================================]
70 [def __ratio `ratio`]
71
72 [def __ratio_add `ratio_add`]
73 [def __ratio_subtract `ratio_subtract`]
74 [def __ratio_multiply `ratio_multiply`]
75 [def __ratio_divide `ratio_divide`]
76
77
78 [def __ratio_equal `ratio_equal`]
79 [def __ratio_not_equal `ratio_not_equal`]
80 [def __ratio_less `ratio_less`]
81 [def __ratio_less_equal `ratio_less_equal`]
82 [def __ratio_greater `ratio_greater`]
83 [def __ratio_greater_equal `ratio_greater_equal`]
84
85 [def __failbit `failbit`]
86
87
88 [def __atto `atto`]
89 [def __femto `femto`]
90 [def __pico `pico`]
91 [def __nano `nano`]
92 [def __micro `micro`]
93 [def __milli `milli`]
94 [def __centi `centi`]
95 [def __deci `deci`]
96 [def __deca `deca`]
97 [def __hecto `hecto`]
98 [def __kilo `kilo`]
99 [def __mega `mega`]
100 [def __giga `giga`]
101 [def __tera `tera`]
102 [def __peta `peta`]
103 [def __exa `exa`]
104
105
106 [/==================]
107
108
109 [template chrono_conf[link_text] [link chrono.reference.cpp0x.chrono_chrono_hpp.conf [link_text]]]
110
111 [def __BOOST_CHRONO_HEADER_ONLY [link chrono.reference.cpp0x.chrono_chrono_hpp.conf.header_only `BOOST_CHRONO_HEADER_ONLY`]]
112 [def __BOOST_SYSTEM_INLINED `BOOST_SYSTEM_INLINED`]
113
114 [def __BOOST_CHRONO_USES_STATIC_ASSERT [chrono_conf `BOOST_CHRONO_USES_STATIC_ASSERT`]]
115 [def __BOOST_CHRONO_USES_MPL_ASSERT [chrono_conf `BOOST_CHRONO_USES_MPL_ASSERT`]]
116 [def __BOOST_CHRONO_USES_ARRAY_ASSERT [chrono_conf `BOOST_CHRONO_USES_ARRAY_ASSERT`]]
117
118 [def __BOOST_CHRONO_HAS_CLOCK_STEADY [link chrono.reference.cpp0x.system_clocks_hpp.BOOST_CHRONO_HAS_CLOCK_STEADY `BOOST_CHRONO_HAS_CLOCK_STEADY`]]
119
120 [def __BOOST_CHRONO_HAS_THREAD_CLOCK [link chrono.reference.other_clocks.thread_clock_hpp.BOOST_CHRONO_HAS_THREAD_CLOCK `BOOST_CHRONO_HAS_THREAD_CLOCK`]]
121
122
123
124 [def __clock_req [link chrono.reference.cpp0x.clock `Clock`] requirements]
125 [def __Clock [link chrono.reference.cpp0x.clock `Clock`]]
126 [def __Clock [link chrono.reference.cpp0x.clock `Clock`'s]]
127 [def __TrivialClock [link chrono.reference.cpp0x.clock `TrivialClock`]]
128
129 [def __To [link chrono.reference.cpp0x.duration_hpp.duration `To`]]
130 [def __ToDuration [link chrono.reference.cpp0x.duration_hpp.duration `ToDuration`]]
131 [def __Duration [link chrono.reference.cpp0x.duration_hpp.duration `Duration`]]
132 [def __Duration1 [link chrono.reference.cpp0x.duration_hpp.duration `Duration1`]]
133 [def __Duration2 [link chrono.reference.cpp0x.duration_hpp.duration `Duration2`]]
134 [def __duration [link chrono.reference.cpp0x.duration_hpp.duration `duration`]]
135 [def __durations [link chrono.reference.cpp0x.duration_hpp.duration `duration`]s]
136 [def __duration_s [link chrono.reference.cpp0x.duration_hpp.duration `duration`]'s]
137
138 [def __duration__c_0 [link chrono.reference.cpp0x.duration_hpp.duration.duration_c_0 `duration`]]
139 [def __duration__c_1 [link chrono.reference.cpp0x.duration_hpp.duration.duration_c_1 `duration`]]
140 [def __duration__c_2 [link chrono.reference.cpp0x.duration_hpp.duration.duration_c_2 `duration`]]
141 [def __duration__count [link chrono.reference.cpp0x.duration_hpp.duration.count `count`]]
142 [def __duration__op_unary_plus [link chrono.reference.cpp0x.duration_hpp.duration.op_plus `operator+`]]
143 [def __duration__op_unary_minus [link chrono.reference.cpp0x.duration_hpp.duration.op_minus `operator-`]]
144 [def __duration__op_pre_inc [link chrono.reference.cpp0x.duration_hpp.duration.op_pre_inc `operator++`]]
145 [def __duration__op_post_inc [link chrono.reference.cpp0x.duration_hpp.duration.op_post_inc `operator++`]]
146 [def __duration__op_pre_dec [link chrono.reference.cpp0x.duration_hpp.duration.op_pre_dec `operator--`]]
147 [def __duration__op_post_dec [link chrono.reference.cpp0x.duration_hpp.duration.op_post_dec `operator--`]]
148 [def __duration__op_plus_eq [link chrono.reference.cpp0x.duration_hpp.duration.op_plus_eq `operator+=`]]
149 [def __duration__op_minus_eq [link chrono.reference.cpp0x.duration_hpp.duration.op_minus_eq `operator-=`]]
150 [def __duration__op_mult_eq [link chrono.reference.cpp0x.duration_hpp.duration.op_mult_eq `operator*=`]]
151 [def __duration__op_div_eq [link chrono.reference.cpp0x.duration_hpp.duration.op_div_eq `operator/=`]]
152 [def __duration__op_mod_eq [link chrono.reference.cpp0x.duration_hpp.duration.op_mod_eq `operator%=`]]
153 [def __duration__op_mod_eq2 [link chrono.reference.cpp0x.duration_hpp.duration.op_mod_eq2 `operator%=`]]
154 [def __duration__zero [link chrono.reference.cpp0x.duration_hpp.duration.zero `zero`]]
155 [def __duration__min [link chrono.reference.cpp0x.duration_hpp.duration.min `min`]]
156 [def __duration__max [link chrono.reference.cpp0x.duration_hpp.duration.max `max`]]
157 [def __duration__op_plus_1 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_plus_1 `operator+`]]
158 [def __duration__op_minus_1 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_minus_1 `operator-`]]
159 [def __duration__op_mult_1 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_mult_1 `operator*`]]
160 [def __duration__op_mult_2 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_mult_2 `operator*`]]
161 [def __duration__op_div_1 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_div_1 `operator/`]]
162 [def __duration__op_div_2 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_div_2 `operator/`]]
163 [def __duration__op_div_3 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_div_3 `operator/`]]
164 [def __duration__op_mod_1 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_mod_1 `operator%`]]
165 [def __duration__op_mod_2 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_mod_2 `operator%`]]
166 [def __duration__op_eq_1 [link chrono.reference.cpp0x.duration_hpp.cmp.duration__op_eq_1 `operator==`]]
167 [def __duration__op_neq_1 [link chrono.reference.cpp0x.duration_hpp.cmp.duration__op_neq_1 `operator!=`]]
168 [def __duration__op_lt_1 [link chrono.reference.cpp0x.duration_hpp.cmp.duration__op_lt_1 `operator<`]]
169 [def __duration__op_leq_1 [link chrono.reference.cpp0x.duration_hpp.cmp.duration__op_leq_1 `operator<=`]]
170 [def __duration__op_gt_1 [link chrono.reference.cpp0x.duration_hpp.cmp.duration__op_gt_1 `operator>`]]
171 [def __duration__op_geq_1 [link chrono.reference.cpp0x.duration_hpp.cmp.duration__op_geq_1 `operator>=`]]
172
173
174
175 [/==================]
176 [def __time_point [link chrono.reference.cpp0x.time_point_hpp.time_point `time_point`]]
177 [def __time_points [link chrono.reference.cpp0x.time_point_hpp.time_point `time_point`]s]
178 [def __time_point_s [link chrono.reference.cpp0x.time_point_hpp.time_point `time_point`]'s]
179
180
181 [def __time_point__c_1 [link chrono.reference.cpp0x.time_point_hpp.time_point.time_point_c_1 `time_point`]]
182 [def __time_point__c_2 [link chrono.reference.cpp0x.time_point_hpp.time_point.time_point_c_2 `time_point`]]
183 [def __time_point__c_3 [link chrono.reference.cpp0x.time_point_hpp.time_point.time_point_c_3 `time_point`]]
184 [def __time_point__time_since_epoch [link chrono.reference.cpp0x.time_point_hpp.time_point.time_since_epoch `time_since_epoch`]]
185 [def __time_point__op_unary_plus [link chrono.reference.cpp0x.time_point_hpp.time_point.op_unary_plus `operator+`]]
186 [def __time_point__op_unary_minus [link chrono.reference.cpp0x.time_point_hpp.time_point.op_unary_minus `operator-`]]
187 [def __time_point__op_pre_inc [link chrono.reference.cpp0x.time_point_hpp.time_point.op_pre_inc `operator++`]]
188 [def __time_point__op_post_inc [link chrono.reference.cpp0x.time_point_hpp.time_point.op_post_inc `operator++`]]
189 [def __time_point__op_pre_dec [link chrono.reference.cpp0x.time_point_hpp.time_point.op_pre_dec `operator--`]]
190 [def __time_point__op_post_dec [link chrono.reference.cpp0x.time_point_hpp.time_point.op_post_dec `operator--`]]
191 [def __time_point__op_plus_eq_1[link chrono.reference.cpp0x.time_point_hpp.time_point.op_plus_eq_1 `operator+=`]]
192 [def __time_point__op_plus_eq_2[link chrono.reference.cpp0x.time_point_hpp.time_point.op_plus_eq_2 `operator+=`]]
193 [def __time_point__op_minus_eq_1 [link chrono.reference.cpp0x.time_point_hpp.time_point.op_minus_eq_1 `operator-=`]]
194 [def __time_point__op_minus_eq_2 [link chrono.reference.cpp0x.time_point_hpp.time_point.op_minus_eq_2 `operator-=`]]
195 [def __time_point__min [link chrono.reference.cpp0x.time_point_hpp.time_point.min `min`]]
196 [def __time_point__max [link chrono.reference.cpp0x.time_point_hpp.time_point.max `max`]]
197 [def __time_point__op_plus_1 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_plus_1 `operator+`]]
198 [def __time_point__op_plus_2 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_plus_2 `operator+`]]
199 [def __time_point__op_minus_1 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_minus_1 `operator-`]]
200 [def __time_point__op_minus_2 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_minus_2 `operator-`]]
201 [def __time_point__op_mult_1 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_mult_1 `operator*`]]
202 [def __time_point__op_mult_2 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_mult_2 `operator*`]]
203 [def __time_point__op_div_1 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_div_1 `operator/`]]
204 [def __time_point__op_div_2 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_div_2 `operator/`]]
205 [def __time_point__op_div_3 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_div_3 `operator/`]]
206 [def __time_point__op_mod_1 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_mod_1 `operator%`]]
207 [def __time_point__op_mod_2 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_mod_2 `operator%`]]
208 [def __time_point__op_eq [link chrono.reference.cpp0x.time_point_hpp.cmp.time_point__op_eq `operator==`]]
209 [def __time_point__op_neq [link chrono.reference.cpp0x.time_point_hpp.cmp.time_point__op_neq `operator!=`]]
210 [def __time_point__op_lt [link chrono.reference.cpp0x.time_point_hpp.cmp.time_point__op_lt `operator<`]]
211 [def __time_point__op_leq [link chrono.reference.cpp0x.time_point_hpp.cmp.time_point__op_leq `operator<=`]]
212 [def __time_point__op_gt [link chrono.reference.cpp0x.time_point_hpp.cmp.time_point__op_gt `operator>`]]
213 [def __time_point__op_geq [link chrono.reference.cpp0x.time_point_hpp.cmp.time_point__op_geq `operator>=`]]
214
215 [def __time_point_units [link chrono.reference.io.time_point_units_hpp.time_point_units `time_point_units`]]
216
217
218
219
220
221
222 [/==================]
223 [def __system_clock [link chrono.reference.cpp0x.system_clocks_hpp.system_clock `system_clock`]]
224 [def __steady_clock [link chrono.reference.cpp0x.system_clocks_hpp.steady_clock `steady_clock`]]
225 [def __high_resolution_clock [link chrono.reference.cpp0x.system_clocks_hpp.high_resolution_clock `high_resolution_clock`]]
226
227 [/==================]
228
229 [def __process_real_cpu_clock [link chrono.reference.other_clocks.process_cpu_clocks_hpp.process_real_cpu_clock `process_real_cpu_clock`]]
230 [def __process_system_cpu_clock [link chrono.reference.other_clocks.process_cpu_clocks_hpp.process_system_cpu_clock `process_system_cpu_clock`]]
231 [def __process_user_cpu_clock [link chrono.reference.other_clocks.process_cpu_clocks_hpp.process_user_cpu_clock `process_user_cpu_clock`]]
232 [def __process_cpu_clock [link chrono.reference.other_clocks.process_cpu_clocks_hpp.process_cpu_clock `process_cpu_clock`]]
233 [def __thread_clock [link chrono.reference.other_clocks.thread_clock_hpp.thread_clock `thread_clock`]]
234
235 [/==================]
236 [def __duration_cast [link chrono.reference.cpp0x.duration_hpp.duration_cast `duration_cast`]]
237 [def __time_point_cast [link chrono.reference.cpp0x.time_point_hpp.time_point_cast `time_point_cast`]]
238
239
240 [def __nanoseconds [link chrono.reference.cpp0x.duration_hpp.duration_typedefs `nanoseconds`]]
241 [def __microseconds [link chrono.reference.cpp0x.duration_hpp.duration_typedefs `microseconds`]]
242 [def __milliseconds [link chrono.reference.cpp0x.duration_hpp.duration_typedefs `milliseconds`]]
243 [def __seconds [link chrono.reference.cpp0x.duration_hpp.duration_typedefs `seconds`]]
244 [def __minutes [link chrono.reference.cpp0x.duration_hpp.duration_typedefs `minutes`]]
245 [def __hours [link chrono.reference.cpp0x.duration_hpp.duration_typedefs `hours`]]
246
247 [def __common_type_spe [link chrono.reference.cpp0x.duration_hpp.common_type_spe `common_type`]]
248
249 [/==================]
250 [def __treat_as_floating_point [link chrono.reference.cpp0x.duration_hpp.traits.treat_as_floating_point `treat_as_floating_point`]]
251 [def __duration_values [link chrono.reference.cpp0x.duration_hpp.traits.duration_values `duration_values`]]
252 [def __zero [link chrono.reference.cpp0x.duration_hpp.traits.duration_values.zero `zero`]]
253 [def __max [link chrono.reference.cpp0x.duration_hpp.traits.duration_values.max `max`]]
254 [def __min [link chrono.reference.cpp0x.duration_hpp.traits.duration_values.min `min`]]
255
256
257
258 [/==================]
259
260 [def __duration_punct [link chrono.reference.io_v1.chrono_io_hpp.duration_punct `duration_punct`]]
261 [def __duration_punct__c1 [link chrono.reference.io_v1.chrono_io_hpp.duration_punct.c1 `duration_punct`]]
262 [def __duration_punct__c2 [link chrono.reference.io_v1.chrono_io_hpp.duration_punct.c2 `duration_punct`]]
263 [def __duration_punct__is_prefix_name [link chrono.reference.io_v1.chrono_io_hpp.duration_punct.is_prefix_name `is_prefix_name`]]
264 [def __duration_punct__is_symbol_name [link chrono.reference.io_v1.chrono_io_hpp.duration_punct.is_symbol_name `is_symbol_name`]]
265 [def __duration_punct__get_duration_style [link chrono.reference.io_v1.chrono_io_hpp.duration_punct.get_duration_style `get_duration_style`]]
266
267 [def __duration_short [link chrono.reference.io_v1.chrono_io_hpp.manipulators `duration_short`]]
268 [def __duration_long [link chrono.reference.io_v1.chrono_io_hpp.manipulators `duration_long`]]
269
270
271 [def __duration_style [link chrono.reference.io.duration_style_hpp.duration_style `duration_style`]]
272 [def __duration_style_type [link chrono.reference.io.duration_style_hpp.duration_style `duration_style`]]
273 [def __prefix [link chrono.reference.io.duration_style_hpp.duration_style `prefix`]]
274 [def __symbol [link chrono.reference.io.duration_style_hpp.duration_style `symbol`]]
275
276 [def __symbol_format [link chrono.reference.io.duration_io_hpp.manipulators.symbol_format `symbol_format`]]
277 [def __name_format [link chrono.reference.io.duration_io_hpp.manipulators.name_format `name_format`]]
278 [def __duration_fmt [link chrono.reference.io.duration_io_hpp.manipulators.duration_fmt `duration_fmt`]]
279 [def __duration_fmt__c1 [link chrono.reference.io.duration_io_hpp.manipulators.duration_fmt.c1 `duration_fmt`]]
280 [def __duration_fmt__op_duration_style [link chrono.reference.io.duration_io_hpp.manipulators.duration_fmt.op_duration_style `operator duration_style`]]
281 [def __duration_fmt__get_duration_style [link chrono.reference.io.duration_io_hpp.manipulators.duration_fmt.op_duration_style `get_duration_style`]]
282 [def __duration_fmt__op_in [link chrono.reference.io.duration_io_hpp.manipulators.duration_fmt.op_in `operator >>`]]
283 [def __duration_fmt__op_out [link chrono.reference.io.duration_io_hpp.manipulators.duration_fmt.op_out `operator <<`]]
284
285
286 [def __duration_style_io_saver [link chrono.reference.io.ios_state_hpp.ioss.duration_style_io_saver `duration_style_io_saver`]]
287 [def __duration_style_io_saver__c1 [link chrono.reference.io.ios_state_hpp.ioss.duration_style_io_saver.c1 `duration_style_io_saver`]]
288 [def __duration_style_io_saver__c2 [link chrono.reference.io.ios_state_hpp.ioss.duration_style_io_saver.c2 `duration_style_io_saver`]]
289 [def __duration_style_io_saver__d [link chrono.reference.io.ios_state_hpp.ioss.duration_style_io_saver.d `~duration_style_io_saver`]]
290 [def __duration_style_io_saver__restore [link chrono.reference.io.ios_state_hpp.ioss.duration_style_io_saver.restore `restore`]]
291
292 [def __get_duration_style [link chrono.reference.io.ios_state_hpp.sag.get_duration_style `get_duration_style`]]
293 [def __set_duration_style [link chrono.reference.io.ios_state_hpp.sag.set_duration_style `set_duration_style`]]
294 [def __get_timezone [link chrono.reference.io.ios_state_hpp.sag.get_timezone `get_timezone`]]
295 [def __set_timezone [link chrono.reference.io.ios_state_hpp.sag.set_timezone `set_timezone`]]
296 [def __get_time_fmt [link chrono.reference.io.ios_state_hpp.sag.get_time_fmt `get_time_fmt`]]
297 [def __set_time_fmt [link chrono.reference.io.ios_state_hpp.sag.set_time_fmt `set_time_fmt`]]
298
299 [def __duration__op_in [link chrono.reference.io.duration_io_hpp.streams.duration__op_in `operator >>`]]
300 [def __duration__op_out [link chrono.reference.io.duration_io_hpp.streams.duration__op_out `operator <<`]]
301
302 [def __duration_get [link chrono.reference.io.duration_get_hpp.duration_get `duration_get`]]
303 [def __duration_get_c [link chrono.reference.io.duration_get_hpp.duration_get.c `duration_get`]]
304 [def __duration_get_d [link chrono.reference.io.duration_get_hpp.duration_get.d `~duration_get`]]
305 [def __duration_get_get [link chrono.reference.io.duration_get_hpp.duration_get.get `get`]]
306 [def __duration_get_get2 [link chrono.reference.io.duration_get_hpp.duration_get.get2 `get`]]
307 [def __duration_get_get_unit [link chrono.reference.io.duration_get_hpp.duration_get.get_unit `get_unit`]]
308 [def __duration_get_get_value [link chrono.reference.io.duration_get_hpp.duration_get.get_value `get_value`]]
309
310 [def __duration_put [link chrono.reference.io.duration_put_hpp.duration_put `duration_put`]]
311 [def __duration_put_c [link chrono.reference.io.duration_put_hpp.duration_put.c `duration_put`]]
312 [def __duration_put_d [link chrono.reference.io.duration_put_hpp.duration_put.d `~duration_put`]]
313 [def __duration_put_put [link chrono.reference.io.duration_put_hpp.duration_put.put `put`]]
314 [def __duration_put_put2 [link chrono.reference.io.duration_put_hpp.duration_put.put2 `put`]]
315 [def __duration_put_put_unit [link chrono.reference.io.duration_put_hpp.duration_put.put_unit `put_unit`]]
316 [def __duration_put_put_value [link chrono.reference.io.duration_put_hpp.duration_put.put_value `put_value`]]
317
318 [def __duration_units [link chrono.reference.io.duration_units_hpp.duration_units `duration_units`]]
319 [def __duration_units_c [link chrono.reference.io.duration_units_hpp.duration_units.c `duration_units`]]
320 [def __duration_units_d [link chrono.reference.io.duration_units_hpp.duration_units.d `~duration_units`]]
321 [def __duration_units_get_n_d_valid_units_start [link chrono.reference.io.duration_units_hpp.duration_units.get_n_d_valid_units_start `get_n_d_valid_units_start`]]
322 [def __duration_units_get_n_d_valid_units_end [link chrono.reference.io.duration_units_hpp.duration_units.get_n_d_valid_units_end `get_n_d_valid_units_end`]]
323 [def __duration_units_get_n_d_unit [link chrono.reference.io.duration_units_hpp.duration_units.get_n_d_unit `get_n_d_unit`]]
324 [def __duration_units_do_get_n_d_unit [link chrono.reference.io.duration_units_hpp.duration_units.do_get_n_d_unit `do_get_n_d_unit`]]
325 [def __duration_units_match_n_d_valid_unit [link chrono.reference.io.duration_units_hpp.duration_units.match_n_d_valid_unit `match_n_d_valid_unit`]]
326 [def __duration_units_get_valid_units_start [link chrono.reference.io.duration_units_hpp.duration_units.get_valid_units_start `get_valid_units_start`]]
327 [def __duration_units_get_valid_units_end [link chrono.reference.io.duration_units_hpp.duration_units.get_valid_units_end `get_valid_units_end`]]
328 [def __duration_units_get_unit [link chrono.reference.io.duration_units_hpp.duration_units.get_unit `get_unit`]]
329 [def __duration_units_do_get_unit [link chrono.reference.io.duration_units_hpp.duration_units.do_get_unit `do_get_unit`]]
330 [def __duration_units_match_valid_unit [link chrono.reference.io.duration_units_hpp.duration_units.match_valid_unit `match_valid_unit`]]
331 [def __duration_units_get_pattern [link chrono.reference.io.duration_units_hpp.duration_units.get_pattern `get_pattern`]]
332 [def __duration_units_is_named_unit [link chrono.reference.io.duration_units_hpp.duration_units.is_named_unit `is_named_unit`]]
333 [def __duration_units_do_is_named_unit [link chrono.reference.io.duration_units_hpp.duration_units.do_is_named_unit `do_is_named_unit`]]
334
335
336 [/==================]
337
338 [def __timezone [link chrono.reference.io.timezone_hpp.timezone `timezone`]]
339 [def __utc [link chrono.reference.io.timezone_hpp.timezone `utc`]]
340 [def __local [link chrono.reference.io.timezone_hpp.timezone `local`]]
341
342
343 [def __time_fmt1 [link chrono.reference.io.time_point_io_hpp.manip.time_fmt1 `time_fmt`]]
344 [def __time_fmt2 [link chrono.reference.io.time_point_io_hpp.manip.time_fmt2 `time_fmt`]]
345
346 [def __timezone_io_saver [link chrono.reference.io.ios_state_hpp.ioss.timezone_io_saver `timezone_io_saver`]]
347 [def __timezone_io_saver__c1 [link chrono.reference.io.ios_state_hpp.ioss.timezone_io_saver.c1 `timezone_io_saver`]]
348 [def __timezone_io_saver__c2 [link chrono.reference.io.ios_state_hpp.ioss.timezone_io_saver.c2 `timezone_io_saver`]]
349 [def __timezone_io_saver__d [link chrono.reference.io.ios_state_hpp.ioss.timezone_io_saver.d `~timezone_io_saver`]]
350 [def __timezone_io_saver__restore [link chrono.reference.io.ios_state_hpp.ioss.timezone_io_saver.restore `restore`]]
351
352 [def __time_fmt_io_saver [link chrono.reference.io.ios_state_hpp.ioss.time_fmt_io_saver `time_fmt_io_saver`]]
353 [def __time_fmt_io_saver__c1 [link chrono.reference.io.ios_state_hpp.ioss.time_fmt_io_saver.c1 `time_fmt_io_saver`]]
354 [def __time_fmt_io_saver__c2 [link chrono.reference.io.ios_state_hpp.ioss.time_fmt_io_saver.c2 `time_fmt_io_saver`]]
355 [def __time_fmt_io_saver__d [link chrono.reference.io.ios_state_hpp.ioss.time_fmt_io_saver.d `~time_fmt_io_saver`]]
356 [def __time_fmt_io_saver__restore [link chrono.reference.io.ios_state_hpp.ioss.time_fmt_io_saver.restore `restore`]]
357
358 [/==================]
359
360 [def __round [link chrono.reference.round.round_hpp `round`]]
361 [def __ceil [link chrono.reference.round.ceil_hpp `ceil`]]
362 [def __floor [link chrono.reference.round.floor_hpp `floor`]]
363
364 [/==================]
365
366 [def __StrictStopwatch [link boost_chrono.reference.stopwatches.strict_stopwatch_req `StrictStopwatch`]]
367 [def __strict_stopwatch_concept [link boost_chrono.reference.stopwatches.strict_stopwatch_req `StrictStopwatch`]]
368 [def __strict_stopwatch [link boost_chrono.reference.stopwatches.strict_stopwatch_hpp.strict_stopwatch `strict_stopwatch`]]
369
370
371 [def __strict_stopclock [link boost_chrono.reference.stopclocks.strict_stopclock_hpp.strict_stopclock `strict_stopclock`]]
372
373 [def __Stopwatch [link boost_chrono.reference.stopwatches.stopwatch_req `Stopwatch`]]
374 [def __stopwatch_concept [link boost_chrono.reference.stopwatches.stopwatch_req `Stopwatch`]]
375 [def __stopwatch [link boost_chrono.reference.stopwatches.stopwatch_hpp.stopwatch `stopwatch`]]
376 [def __laps_stopwatch [link boost_chrono.reference.stopwatches.stopwatch_hpp.stopwatch `laps_stopwatch`]]
377 [def __laps_stopclock [link boost_chrono.reference.stopwatches.stopwatch_hpp.stopwatch `basic_stopclock`]]
378
379 [def __SuspendableStopwatch [link boost_chrono.reference.stopwatches.suspendable_stopwatch_req `SuspendableStopwatch`]]
380 [def __suspendable_stopwatch_concept [link boost_chrono.reference.stopwatches.suspendable_stopwatch_req `SuspendableStopwatch`]]
381 [def __suspendable_stopwatch [link boost_chrono.reference.stopwatches.suspendable_stopwatch_hpp.suspendable_stopwatch `suspendable_stopwatch`]]
382 [def __suspendable_stopclock [link boost_chrono.reference.stopwatches.suspendable_stopwatch_hpp.suspendable_stopwatch `suspendable_stopclock`]]
383
384 [def __stopwatch_reporter `stopwatch_reporter `]
385 [def __stopclock `stopclock `]
386 [def __Formatter `Formatter`]
387 [def __Formatters `Formatter`s]
388
389
390 [/===============]
391 [section Overview]
392 [/===============]
393
394 [:["What is time, then? If nobody asks me, I know; if I have to explain it to someone who has asked me, I do not know."]]
395 [:[*['-- Augustine ]]]
396
397
398 [/====================================]
399 [heading How to Use This Documentation]
400 [/====================================]
401
402 This documentation makes use of the following naming and formatting conventions.
403
404 * Code is in `fixed width font` and is syntax-highlighted.
405 * Replaceable text that you will need to supply is in [~italics].
406 * Free functions are rendered in the code font followed by `()`, as in `free_function()`.
407 * If a name refers to a class template, it is specified like this: `class_template<>`; that is, it is in code font and its name is followed by `<>` to indicate that it is a class template.
408 * If a name refers to a function-like macro, it is specified like this: `MACRO()`;
409 that is, it is uppercase in code font and its name is followed by `()` to indicate that it is a function-like macro. Object-like macros appear without the trailing `()`.
410 * Names that refer to /concepts/ in the generic programming sense are specified in CamelCase.
411
412 [note In addition, notes such as this one specify non-essential information that provides additional background or rationale.]
413
414 Finally, you can mentally add the following to any code fragments in this document:
415
416 // Include all of Chrono files
417 #include <boost/chrono.hpp>
418
419 [/=================]
420 [section Motivation]
421 [/=================]
422
423 [heading Time]
424
425 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, we do not need a terribly complicated solution to meet the bulk of our needs. However, overly simplistic solutions can be dangerous and inefficient, and won't adapt as the computer industry evolves.
426
427 __Boost_Chrono__ implements the new time facilities in C++11, as proposed in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]]. That document provides background and motivation for key design decisions and is the source of a good deal of information in this documentation.
428
429 [/
430 __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.
431 ]
432
433
434 In addition to the clocks provided by the standard proposal, __Boost_Chrono__ provides specific process and thread clocks.
435
436
437 [/
438 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.
439 ]
440
441 [heading Wall clock versus system and user time]
442
443 To make the timing facilities of Boost.Chrono more generally useful, the library provides a number of clocks that are thin wrappers around the operating system's process time API, thereby allowing the extraction of wall clock time, user CPU time, and system CPU time of the process. Wall clock time is the sum of CPU time and system CPU time. (On POSIX-like systems, this relies on `times()`. On Windows, it relies on `GetProcessTimes()`.)
444
445 [/
446 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.
447 ]
448
449 [/
450 3 concrete process clocks:
451
452 # __process_real_cpu_clock,
453 # __process_user_cpu_clock,
454 # __process_system_cpu_clock
455
456 providing a
457 ]
458
459 [/__Boost_Chrono__ provides
460 thin wrappers 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.
461 ]
462
463 [/These clocks capture the specific time unitarily. __Boost_Chrono__ provides also a clock __process_cpu_clock that captures the three times at once.
464 ]
465
466 [/include stopwatches/motivation.qbk]
467
468 [endsect]
469
470 [/==================]
471 [section Description]
472 [/==================]
473
474 The __Boost_Chrono__ library provides:
475
476 [heading Standard]
477
478 * A means to represent time durations: managed by the generic __duration class . Examples of time durations include days, __minutes, __seconds and __nanoseconds, which can be represented with a fixed number of clock ticks per unit. All of these units of time duration are united with a generic interface by the __duration facility.
479 * A type for representing points in time: __time_point. A __time_point represents an epoch plus or minus a __duration. The library leaves epochs unspecified. A __time_point is associated with a /clock/.
480 * Several clocks, some of which may not be available on a particular platform: __system_clock, __steady_clock and __high_resolution_clock. A clock is a pairing of a __time_point and __duration, and a function which returns a __time_point representing ['now].
481
482 [heading Other clocks]
483
484 To make the timing facilities more generally useful, __Boost_Chrono__ provides a number of clocks that are thin wrappers around the operating system's time APIs, thereby allowing the extraction of wall clock time, user CPU time, system CPU time spent by the process,
485
486 * __process_real_cpu_clock, captures wall clock CPU time spent by the current process.
487 * __process_user_cpu_clock, captures user-CPU time spent by the current process.
488 * __process_system_cpu_clock, captures system-CPU time spent by the current process.
489 * A tuple-like class __process_cpu_clock, that captures real, user-CPU, and system-CPU process times together.
490 * A __thread_clock thread steady clock giving the time spent by the current thread (when supported by a platform).
491
492
493 [/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.
494 ]
495
496 Lastly, __Boost_Chrono__ includes [@http://www.boost.org/libs/typeof typeof] registration for __duration and __time_point to permit using emulated auto with C++03 compilers.
497
498 [heading I/O]
499
500 It provides I/O for __duration and __time_point. This I/O makes use of these types much more convenient. In following the "you only pay for what you use" philosophy, this extra functionality is located in a header separate from <boost/chrono/chrono.hpp>, namely <boost/chrono/chrono_io.hpp>.
501
502 It builds on `<boost/ratio/ratio_io.hpp>` to provide readable and flexible formatting and parsing for types in `<boost/chrono.hpp>`.
503 This textural representation uses [@http://en.wikipedia.org/wiki/SI_prefix#List_of_SI_prefixes SI prefixes] whenever possible.
504 This makes it easy for `boost::milliseconds` to be represented by the text "milliseconds", or a hypothetical meter
505 class to print out "millimeter".
506 The __duration and the __time_point i/o can be customized through the new facets: __duration_units and __time_point_units.
507 The user can specialize these facets so that the chrono i/o could be localizable.
508 However Boost.Chrono doesn't provides a complete locale solution.
509
510 `system_clock::time_point` I/O is proposed in terms of UTC timepoints, strongly guided by
511 ISO 9899:1999, Programming languages - C, ISO 9945:2003, Information Technology - Portable Operating System Interface (POSIX) and
512 ISO 8601:2004, Data elements and interchange formats - Information interchange - Representation of dates and times.
513
514 [heading Rounding utilities]
515
516 A few simple rounding utility functions for working with durations.
517
518 [/include stopwatches/description.qbk]
519
520 [heading Caveat Emptor]
521
522 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.
523
524 [endsect]
525
526 [endsect]
527
528
529 [/==============================]
530 [section:users_guide User's Guide]
531 [/==============================]
532
533 [/======================================]
534 [section:getting_started Getting Started]
535 [/======================================]
536
537 [/======================================]
538 [section:install Installing Chrono]
539 [/======================================]
540
541 [/=================================]
542 [heading Getting __Boost_Chrono__ ]
543 [/=================================]
544
545 __Boost_Chrono__ is in the latest Boost release in the folder `/boost/chrono`. Documentation, tests and examples folder are at `boost/libs/chrono/`.
546
547 You can also access the latest (unstable?) state from the [@https://svn.boost.org/svn/boost-trunk Boost trunk] directories boost/chrono and libs/chrono. Just go to [@http://svn.boost.org/trac/boost/wiki/BoostSubversion here] and follow the instructions there for anonymous SVN access.
548
549
550 [/==========================================]
551 [heading Where to install Boost.Chrono? ]
552 [/==========================================]
553
554 The simple way is to decompress (or checkout from SVN) the files in your BOOST_ROOT directory.
555
556
557 [/=================================]
558 [heading Building Boost.Chrono ]
559 [/=================================]
560
561 __Boost_Chrono__ can be configured as a header-only library defining __BOOST_CHRONO_HEADER_ONLY.
562 However Boost.Chrono depends on the non header-only library Boost.System, so that you will need to link with boost_system.
563
564 Boost.System has an undocumented feature (use of macro BOOST_ERROR_CODE_HEADER_ONLY) to make it header only.
565
566 If __BOOST_CHRONO_HEADER_ONLY is not defined you need to compile it and build the library before use, for example using:
567
568 bjam libs/chrono/build
569
570 [/===================]
571 [heading Requirements]
572 [/===================]
573
574 In particular, __Boost_Chrono__ depends on:
575
576 [variablelist
577 [
578 [[@http://www.boost.org/libs/config [*Boost.Config]]] [for configuration purposes, ...]
579 ]
580 [
581 [[@http://www.boost.org/libs/exception [*Boost.Exception]]] [for throw_exception, ...]
582 ]
583 [
584 [[@http://www.boost.org/libs/integer [*Boost.Integer]]] [for cstdint conformance, ...]
585 ]
586 [
587 [[@http://www.boost.org/libs/mpl [*Boost.MPL]]] [for MPL Assert and bool, logical ...]
588 ]
589 [
590 [[@http://www.boost.org/libs/operators [*Boost.Operators]]] [for operators, ...]
591 ]
592 [
593 [[@http://www.boost.org/libs/ratio [*Boost.Ratio]]] [for ratio, milli, micro, ...]
594 ]
595 [
596 [[@http://www.boost.org/libs/system [*Boost.System]]] [for error_code, ...]
597 ]
598 [
599 [[@http://www.boost.org/libs/type_traits [*Boost.TypeTraits]]] [for is_base, is_convertible, common_type, ...]
600 ]
601 [
602 [[@http://www.boost.org/libs/utility [*Boost.Utility/EnableIf]]] [for enable_if, ...]
603 ]
604 ]
605
606
607 [/=========================================================]
608 [heading Building an Executable that Uses Boost.Chrono ]
609 [/=========================================================]
610
611 In addition to link with the __Boost_Chrono__ library you need also to link with the [*Boost.System] library.
612 If [*Boost.System] is configured defining BOOST_ERROR_CODE_HEADER_ONLY you will no need to link with it as the dependent part is header only then.
613
614
615 [/=========================]
616 [heading Exception safety ]
617 [/=========================]
618
619 All functions in the library are exception-neutral and provide strong guarantee of exception safety as long as the underlying parameters provide it.
620
621
622 [/=====================]
623 [heading Thread safety ]
624 [/=====================]
625
626 All functions in the library are thread-unsafe except when noted explicitly.
627
628 As Boost.Chrono doesn't use mutable global variables the thread-safety analysis is limited to the access to each instance variable. It is not thread safe to use a function that modifies the access to a user variable if another can be reading or writing it.
629
630
631 [/========================]
632 [heading Tested compilers ]
633 [/========================]
634
635 The implementation will eventually work with most C++03 conforming compilers.
636 Currently I use to test with on:
637
638 Windows with
639
640 * MSVC 10.0
641
642 MinGW with
643
644 * GCC 4.5.0
645 * GCC 4.5.0 -std=c++0x
646 * GCC 4.5.2
647 * GCC 4.5.2 -std=c++0x
648 * GCC 4.6.0
649 * GCC 4.6.0 -std=c++0x
650 * GCC 4.8.0
651 * GCC 4.8.0 -std=c++0x
652
653 Ubuntu with
654 * GCC 4.4.6
655 * GCC 4.4.6 -std=c++0x
656 * GCC 4.5.4
657 * GCC 4.5.4 -std=c++0x
658 * GCC 4.6.1
659 * GCC 4.6.1 -std=c++0x
660 * Intel 12.1.3
661 * Intel 12.1.3 -std=c++0x
662
663 OsX with
664
665 * GCC 4.1.2
666 * GCC 4.6.2
667 * GCC 4.6.2 -std=c++0x
668 * GCC 4.7.0
669 * GCC 4.7.0 -std=c++0x
670 * GCC 4.7.1
671 * GCC 4.7.1 -std=c++0x
672 * GCC 4.7.2
673 * GCC 4.7.2 -std=c++0x
674 * GCC 4.8.0
675 * GCC 4.8.0 -std=c++0x
676 * GCC 4.8.1
677 * GCC 4.8.1 -std=c++0x
678 * clang 3.1
679 * clang 3.1 -std=c++0x -stdlib=libc++
680 * clang 3.2
681 * clang 3.2 -std=c++11 -stdlib=libc++
682
683
684 The committed code is tested with much more compilers. There are two compilers (VACPP and Borland) that don't provide the needed features.
685 Other as Intel and Sun have some issues with i/o. While everything compiles and link correctly, there are some runtime issues I have not cached yet. See the regression tests for details.
686
687 [note Please let us know how this works on other platforms/compilers.]
688
689 [note Please send any questions, comments and bug reports to boost <at> lists <dot> boost <dot> org.]
690
691 [endsect]
692 [/====================]
693 [section Hello World! ]
694 [/====================]
695
696 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
697 If all you want to do is to time a program's execution, here is a complete program:
698
699 #include <boost/chrono.hpp>
700 #include <cmath>
701
702 int main()
703 {
704 boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now();
705
706 for ( long i = 0; i < 10000000; ++i )
707 std::sqrt( 123.456L ); // burn some time
708
709 boost::chrono::__duration<double> sec = boost::chrono::system_clock::now() - start;
710 std::cout << "took " << sec.count() << " seconds\n";
711 return 0;
712 }
713
714 Output was:
715
716 took 0.832 seconds
717
718 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
719 [/include stopwatches/hello.qbk]
720
721 [endsect]
722
723 [endsect]
724
725
726 [section Tutorial]
727
728 [section Duration]
729
730 The __duration is the heart of this library. The interface that the user will see in everyday use is nearly identical to that of [*Boost.DateTime] time __durations authored by Jeff Garland, both in syntax and in behavior. This has been a very popular boost library for 7 years. There is an enormous positive history with this interface.
731
732 The library consists of six units of time __duration:
733
734 * __hours
735 * __minutes
736 * __seconds
737 * __milliseconds
738 * __microseconds
739 * __nanoseconds
740
741 These units were chosen as a subset of the boost library because they are the most common units used when sleeping, waiting on a condition variable, or waiting to obtain the lock on a mutex. Each of these units is nothing but a thin wrapper around a signed integral count. That is, when you construct __minutes`(3)`, all that happens is a `3` is stored inside `minutes`. When you construct __microseconds`(3)`, all that happens is a `3` is stored inside __microseconds.
742
743 The only context in which these different types differ is when being converted to one another. At this time, unit-specific compile-time conversion constants are used to convert the source unit to the target unit. Only conversions from coarser units to finer units are allowed (in Boost). This restriction ensures that all conversions are always exact. That is, __microseconds can always represent any value __minutes has.
744
745 In [*Boost.DateTime], these units are united via inheritance. __Boost_Chrono__ instead unites these units through the class template __duration. That is, in __Boost_Chrono__ all six of the above units are nothing but typedefs to different instantiations of __duration. This change from Boost.DateTime has a far reaching positive impact, while not changing the syntax of the everyday use at all.
746
747 The most immediate positive impact is that the library can immediately generate any unit, with any precision it needs. This is sometimes necessary when doing comparisons or arithmetic between __durations of differing precision, assuming one wants the comparison and arithmetic to be exact.
748
749 A secondary benefit is that by publishing the class template __duration interface, user code can very easily create __durations with any precision they desire. The __ratio utility is used to specify the precision, so as long as the precision can be expressed by a rational constant with respect to seconds, this framework can exactly represent it (one third of a second is no problem, and neither is one third of a __femto second). All of this utility and flexibility comes at no cost just by making use of the no-run-time-overhead __ratio facility.
750
751 In Boost.DateTime, __hours does not have the same representation as __nanoseconds. The former is usually represented with a `long` whereas a `long long` is required for the latter. The reason for this is simply range. You don't need many hours to cover an extremely large range of time. But this isn't true of nanoseconds. Being able to reduce the sizeof overhead for some units when possible, can be a significant performance advantage.
752
753 __Boost_Chrono__ continues, and generalizes that philosophy. Not only can one specify the precision of a __duration, one can also specify its representation. This can be any integral type, or even a floating-point type. Or it can be a user-defined type which emulates an arithmetic type. The six predefined units all use signed integral types as their representation. And they all have a minimum range of [plusminus] 292 years. __nanoseconds needs 64 bits to cover that range. __hours needs only 23 bits to cover that range.
754
755
756 [section So What Exactly is a `duration` and How Do I Use One?]
757
758 A __duration has a representation and a tick period (precision).
759
760 template <class Rep, class Period = __ratio<1> > class duration;
761
762 The representation is simply any arithmetic type, or an emulation of such a type. The representation stores a count of ticks. This count is the only data member stored in a __duration. If the representation is floating-point, it can store fractions of a tick to the precision of the representation. The tick period is represented by a __ratio and is encoded into the __duration_s type, instead of stored. The tick period only has an impact on the behavior of the __duration when a conversion between different __durations is attempted. The tick period is completely ignored when simply doing arithmetic among like __durations.
763
764 __example
765
766 typedef boost::chrono::__duration<long, boost::ratio<60> > minutes;
767 minutes m1(3); // m1 stores 3
768 minutes m2(2); // m2 stores 2
769 minutes m3 = m1 + m2; // m3 stores 5
770
771 typedef boost::chrono::__duration<long long, boost::micro> microseconds;
772 microseconds us1(3); // us1 stores 3
773 microseconds us2(2); // us2 stores 2
774 microseconds us3 = us1 + us2; // us3 stores 5
775
776 microseconds us4 = m3 + us3; // us4 stores 300000005
777
778 In the final line of code above, there is an implicit conversion from minutes to microseconds, resulting in a relatively large number of microseconds.
779
780 If you need to access the tick count within a __duration, there is a member `count()` which simply returns the stored tick count.
781
782 long long tc = us4.count(); // tc is 300000005
783
784 These __duration_s have very simple, very predictable, and very observable behavior. After all, this is really nothing but the time-tested interface of Jeff's boost time __duration library (unified with templates instead of inheritance).
785
786 [endsect]
787
788 [section What Happens if I Assign `m3 + us3` to `minutes` Instead of `microseconds`?]
789
790 minutes m4 = m3 + us3;
791
792 It won't compile! The rationale is that implicit truncation error should not be allowed to happen. If this were to compile, then `m4` would hold `5`, the same value as `m3`. The value associated with `us3` has been effectively ignored. This is similar to the problem of assigning a double to an `int`: the fractional part gets silently discarded.
793 [endsect]
794
795 [section But What if the Truncation Behavior is What I Want to Do?]
796
797 There is a __duration_cast facility to explicitly ask for this behavior:
798
799 minutes m4 = boost::chrono::__duration_cast<minutes>(m3 + us3); // m4.count() == 5
800
801 In general, one can perform __duration arithmetic at will. If __duration_cast isn't used, and it compiles, the arithmetic is exact. If one wants to override this exact arithmetic behavior, __duration_cast can be used to explicitly specify that desire. The __duration_cast has the same efficiency as the implicit conversion, and will even be exact as often as it can.
802
803 You can use __duration_cast`<>` to convert the __duration into whatever units you desire. This facility will round down (truncate) if an exact conversion is not possible. For example:
804
805 boost::chrono::__nanoseconds start;
806 boost::chrono::__nanoseconds end;
807 typedef boost::chrono::__milliseconds ms;
808 ms d = boost::chrono::__duration_cast<ms>(end - start);
809
810 // d now holds the number of milliseconds from start to end.
811
812 std::cout << ms.count() << "ms\n";
813
814 We can convert to __nanoseconds, or some integral-based duration which __nanoseconds will always exactly convert to, then __duration_cast`<>` is unnecessary:
815
816 typedef boost::chrono::__nanoseconds ns;
817 ns d = end - start;
818 std::cout << ns.count() << "ns\n";
819
820 If you need seconds with a floating-point representation you can also eliminate the __duration_cast`<>`:
821
822 typedef boost::chrono::__duration<double> sec; // seconds, stored with a double
823 sec d = end - start;
824 std::cout << sec.count() << "s\n";
825
826 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.
827
828
829 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 __Boost_Chrono__:
830
831 template <class __ToDuration, class Rep, class Period>
832 ToDuration
833 round_up(boost::chrono::__duration<Rep, Period> d)
834 {
835 // first round down
836 ToDuration result = boost::chrono::__duration_cast<ToDuration>(d);
837 if (result < d) // comparisons are *always* exact
838 ++result; // increment by one tick period
839 return result;
840 }
841
842 typedef boost::chrono::__milliseconds ms;
843 ms d = round_up<ms>(end - start);
844 // d now holds the number of milliseconds from start to end, rounded up.
845 std::cout << ms.count() << "ms\n";
846
847 [endsect]
848
849 [section:round Rounding functions]
850
851
852 __Boost_Chrono__ provides few simple rounding utility functions for working with durations.
853
854
855 // round down
856 template <class __To, class Rep, class Period>
857 To
858 floor(const duration<Rep, Period>& d)
859 {
860 return duration_cast<To>(d);
861 }
862
863 // round to nearest, to even on tie
864 template <class __To, class Rep, class Period>
865 To
866 round(const duration<Rep, Period>& d)
867 {
868 To t0 = duration_cast<To>(d);
869 To t1 = t0;
870 ++t1;
871 BOOST_AUTO(diff0, d - t0);
872 BOOST_AUTO(diff1, t1 - d);
873 if (diff0 == diff1)
874 {
875 if (t0.count() & 1)
876 return t1;
877 return t0;
878 }
879 else if (diff0 < diff1)
880 return t0;
881 return t1;
882 }
883 // round up
884 template <class __To, class Rep, class Period>
885 To
886 ceil(const duration<Rep, Period>& d)
887 {
888 To t = duration_cast<To>(d);
889 if (t < d)
890 ++t;
891 return t;
892 }
893
894
895 The beauty of the chrono library is the ease and accuracy with which such conversions can be made. For example to convert from __milliseconds (`1/1000` of a second), to `1/30` of a second, one must multiply the milliseconds by `0.03`. It is common knowledge that you can't exactly represent `0.03` in a computer. Nevertheless round will exactly (with no round off error) detect a tie and round to even when this happens. The differences `diff0` and `diff1` are not approximate, but exact differences, even when `d` has the units of millisecond and `To` is `1/30` of a second. The unit of `diff0` and `diff1` is `1/3000` of a second which both millisecond and `1/30` of a second exactly convert to (with no truncation error).
896
897 Similarly, the comparison `t < d` in __ceil is exact, even when there is no exact conversion between `t` and `d`.
898 Example use of rounding functions
899
900 #include <iostream>
901 #include <boost/chrono/chrono_io.hpp>
902 #include <boost/chrono/floor.hpp>
903 #include <boost/chrono/round.hpp>
904 #include <boost/chrono/ceil.hpp>
905
906 int main()
907 {
908 using namespace boost::chrono;
909 milliseconds ms(2500);
910 std::cout << floor<seconds>(ms) << '\n';
911 std::cout << round<seconds>(ms) << '\n';
912 std::cout << ceil<seconds>(ms) << '\n';
913 ms = milliseconds(2516);
914 typedef duration<long, boost::ratio<1, 30> > frame_rate;
915 std::cout << floor<frame_rate>(ms) << '\n';
916 std::cout << round<frame_rate>(ms) << '\n';
917 std::cout << ceil<frame_rate>(ms) << '\n';
918
919 return 0;
920 }
921
922 The output of this program should be
923
924 2 seconds
925 2 seconds
926 3 seconds
927 75 [1/30]seconds
928 75 [1/30]seconds
929 76 [1/30]seconds
930
931 [endsect]
932
933 [section Trafficking in floating-point Durations]
934
935 I don't want to deal with writing `duration_cast` all over the place. I'm content with the precision of my floating-point representation.
936
937 Not a problem. When the destination of a conversion has floating-point representation, all conversions are allowed to happen implicitly.
938
939 typedef boost::chrono::__duration<double, __ratio<60> > dminutes;
940 dminutes dm4 = m3 + us3; // dm4.count() == 5.000000083333333
941
942 [endsect]
943
944 [section How Expensive is All of this?]
945
946 If you were writing these conversions by hand, you could not make it more efficient. The use of __ratio ensures that all conversion constants are simplified as much as possible at compile-time. This usually results in the numerator or denominator of the conversion factor simplifying to `1`, and being subsequently ignored in converting the run-time values of the tick counts.
947
948 [endsect]
949
950 [section How Complicated is it to Build a Function Taking a `duration` Parameter?]
951
952 There are several options open to the user:
953
954 * If the author of the function wants to accept any __duration, and is willing to work in floating-point __durations, he can simply use any floating-point __duration as the parameter:
955
956 void f(boost::chrono::duration<double> d) // accept floating-point seconds
957 {
958 // d.count() == 3.e-6 when passed boost::chrono::microseconds(3)
959 }
960
961 f(boost::chrono::microseconds(3));
962
963 * If the author of the function wants to traffic only in integral __durations, and is content with handling nothing finer than say nanoseconds (just as an example), he can simply specify nanoseconds as the parameter:
964
965 void f(boost::chrono::nanoseconds d)
966 {
967 // d.count() == 3000 when passed boost::chrono::microseconds(3)
968 }
969
970 f(boost::chrono::microseconds(3));
971
972 In this design, if the client wants to pass in a floating-point __duration, or a __duration of finer precision than nanoseconds, then the client is responsible for choosing his own rounding mode in the conversion to nanoseconds.
973
974 boost::chrono::__duration<double> s(1./3); // 1/3 of a second
975 f(boost::chrono::duration_cast<boost::chrono::nanoseconds>(s)); // round towards zero in conversion to nanoseconds
976
977 In the example above, the client of f has chosen "round towards zero" as the desired rounding mode to nanoseconds. If the client has a __duration that won't exactly convert to nanoseconds, and fails to choose how the conversion will take place, the compiler will refuse the call:
978
979 f(s); // does not compile
980
981 * If the author of the function wants to accept any __duration, but wants to work with integral representations and wants to control the rounding mode internally, then he can template the function:
982
983 template <class Rep, class Period>
984 void f(boost::chrono::__duration<Rep, Period> d)
985 {
986 // convert d to nanoseconds, rounding up if it is not an exact conversion
987 boost::chrono::nanoseconds ns = boost::chrono::duration_cast<boost::chrono::nanoseconds>(d);
988 if (ns < d)
989 ++ns;
990 // ns.count() == 333333334 when passed 1/3 of a floating-point second
991 }
992
993 f(boost::chrono::__duration<double>(1./3));
994
995 * If the author in the example does not want to accept floating-point based __durations, he can enforce that behavior like so:
996
997 template <class Period>
998 void f(boost::chrono::__duration<long long, Period> d)
999 {
1000 // convert d to nanoseconds, rounding up if it is not an exact conversion
1001 boost::chrono::nanoseconds ns = boost::chrono::duration_cast<nanoseconds>(d);
1002 if (ns < d)
1003 ++ns;
1004 // ns.count() == 333333334 when passed 333333333333 picoseconds
1005 }
1006 // About 1/3 of a second worth of picoseconds
1007 f(boost::chrono::__duration<long long, boost::pico>(333333333333));
1008
1009 Clients with floating-point __durations who want to use f will now have to convert to an integral __duration themselves before passing the result to f.
1010
1011 In summary, the author of f has quite a bit of flexibility and control in the interface he wants to provide his clients with, and easy options for manipulating that __duration internal to his function.
1012 [endsect]
1013
1014 [section Is it possible for the user to pass a __duration to a function with the units being ambiguous?]
1015
1016 No. No matter which option the author of `f` chooses above, the following client code will not compile:
1017
1018 f(3); // Will not compile, 3 is not implicitly convertible to any __duration
1019
1020 [endsect]
1021
1022 [section Can Durations Overflow?]
1023
1024 This depend on the representation. The default typedefs uses a representation that don't handle overflows. The user can define his own representation that manage overflow as required by its application.
1025
1026 [endsect]
1027 [endsect]
1028
1029 [section Clocks]
1030
1031 While __durations only have precision and representation to concern themselves, clocks and __time_points are intimately related and refer to one another. Because clocks are simpler to explain, we will do so first without fully explaining __time_points. Once clocks are introduced, it will be easier to then fill in what a __time_point is.
1032
1033 A clock is a concept which bundles 3 things:
1034
1035 # A concrete __duration type.
1036 # A concrete __time_point type.
1037 # A function called now() which returns the concrete __time_point.
1038
1039 The standard defines three system-wide clocks that are associated to the computer time.
1040
1041 * __system_clock represents system-wide realtime clock that can be synchronized with an external clock.
1042
1043 * __steady_clock can not be changed explicitly and the time since the initial epoch increase in a steady way.
1044
1045 * __high_resolution_clock intend to use the system-wide clock provided by the platform with the highest resolution.
1046
1047 __Boost_Chrono__ provides them when supported by the underlying platform. A given platform may not be able to supply all three of these clocks.
1048
1049 The library adds some clocks that are specific to a process or a thread, that is there is a clock per process or per thread.
1050
1051
1052 The user is also able to easily create more clocks.
1053
1054 Given a clock named Clock, it will have:
1055
1056 class Clock {
1057 public:
1058 typedef an arithmetic-like type rep;
1059 typedef an instantiation of ratio period;
1060 typedef boost::chrono::__duration<rep, period> __duration;
1061 typedef boost::chrono::__time_point<__Clock> time_point;
1062 static constexpr bool is_steady = true or false;
1063
1064 static time_point now();
1065 };
1066
1067 One can get the current time from Clock with:
1068
1069 Clock::time_point t1 = Clock::now();
1070
1071 And one can get the time __duration between two __time_points associated with Clock with:
1072
1073 Clock::duration d = Clock::now() - t1;
1074
1075 And one can specify a past or future __time_point with:
1076
1077 Clock::time_point t2 = Clock::now() + d;
1078
1079 Note how even if a particular clock becomes obsolete, the next clock in line will have the same API. There is no new learning curve to come up. The only source code changes will be simply changing the type of the clock. The same __duration and __time_point framework continues to work as new clocks are introduced. And multiple clocks are safely and easily handled within the same program.
1080
1081
1082 [endsect]
1083
1084
1085 [section Time Point]
1086
1087 A __time_point represents a point in time, as opposed to a __duration of time. Another way of saying the same thing, is that a __time_point represents an epoch plus or minus a __duration. Examples of __time_points include:
1088
1089 * 3 minutes after the computer booted.
1090 * 03:14:07 UTC on Tuesday, January 19, 2038
1091 * 20 milliseconds after I started that timer.
1092
1093 In each of the examples above, a different epoch is implied. Sometimes an epoch has meaning for several millennia. Other times the meaning of an epoch is lost after a while (such as the start of a timer, or when the computer booted). However, if two __time_points are known to share the same epoch, they can be subtracted, yielding a valid __duration, even if the definition of the epoch no longer has meaning.
1094
1095 In __Boost_Chrono__, an epoch is a purely abstract and unspecified concept. There is no type representing an epoch. It is simply an idea that relates (or doesn't) __time_points to a clock, and in the case that they share a clock, __time_points to one another. __time_points associated with different clocks are generally not interoperable unless the relationship between the epochs associated with each clock is known.
1096
1097 [section So What Exactly is a `time_point` and How Do I Use One?]
1098
1099 A __time_point has a clock and a __duration.
1100
1101 template <class __Clock, class __Duration = typename Clock::duration> class __time_point;
1102
1103 The __time_point's clock is not stored. It is simply embedded into the __time_point's type and serves two purposes:
1104
1105 # Because __time_points originating from different clocks have different types, the compiler can be instructed to fail if incompatible __time_points are used in inappropriate ways.
1106 # Given a __time_point, one often needs to compare that __time_point to "now". This is very simple as long as the __time_point knows what clock it is defined with respect to.
1107
1108 A __time_point's __duration is stored as the only data member of the __time_point. Thus __time_points and their corresponding __duration have exactly the same layout. But they have very different meanings. For example, it is one thing to say I want to sleep for 3 minutes. It is a completely different thing to say I want to sleep until 3 minutes past the time I started that timer (unless you just happened to start that timer now). Both meanings (and options for sleeping) have great practical value in common use cases for sleeping, waiting on a condition variable, and waiting for a mutex's lock. These same concepts and tools are found (for example) in Ada.
1109
1110 A timer example:
1111
1112 void f()
1113 {
1114 boost::chrono::steady_clock::time_point start = boost::chrono::steady_clock::now();
1115 g();
1116 h();
1117 __duration<double> sec = boost::chrono::steady_clock::now() - start;
1118 cout << "f() took " << sec.count() << " seconds\n";
1119 }
1120
1121 Note that if one is using the __duration between two clock __time_points in a way where the precision of the __duration matters, it is good practice to convert the clock's __duration to a known __duration. This insulates the code from future changes which may be made to the clock's precision in the future. For example __steady_clock could easily be based on the clock speed of the cpu. When you upgrade to a faster machine, you do not want your code that assumed a certain tick period of this clock to start experiencing run-time failures because your timing code has silently changed meaning.
1122
1123 A delay loop example:
1124
1125 // delay for at least 500 nanoseconds:
1126 auto go = boost::chrono::steady_clock::now() + boost::chrono::nanoseconds(500);
1127 while (boost::chrono::steady_clock::now() < go)
1128 ;
1129
1130 The above code will delay as close as possible to half a microsecond, no matter what the precision of __steady_clock is. The more precise __steady_clock becomes, the more accurate will be the delay to 500 nanoseconds.
1131
1132
1133 [endsect]
1134
1135
1136
1137 [/
1138 [section How to Define a Thread Clock]
1139
1140 On posix systems for which the macro _POSIX_THREAD_CPUTIME is defined we can get the time associated to a specific thread.
1141
1142 class thread_clock {
1143 public:
1144 typedef __nanoseconds duration;
1145 typedef duration::rep rep;
1146 typedef duration::period period;
1147 typedef chrono::__time_point<thread_clock> time_point;
1148 static constexpr bool is_steady = BOOST_CHRONO_THREAD_CLOCK_IS_STEADY;
1149
1150 static time_point now( ) {
1151 // get the current thread
1152 pthread_t pth=pthread_self(void);
1153 // get the clock_id associated to the current thread
1154 clockid_t clock_id;
1155 pthread_getcpuclockid(pth, clock_id);
1156 // get the timespec associated to the thread clock
1157 struct timespec ts;
1158 if ( ::clock_gettime( clock_id, &ts ) )
1159 {
1160 boost::throw_exception(
1161 system::system_error( errno, system::system_category, "chrono::thread_clock" ));
1162 }
1163
1164 // transform to nanoseconds
1165 return time_point(duration(
1166 static_cast<thread_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
1167
1168 }
1169 static time_point now( system::error_code & ec ) {
1170 // get the current thread
1171 pthread_t pth=pthread_self(void);
1172 // get the clock_id associated to the current thread
1173 clockid_t clock_id;
1174 pthread_getcpuclockid(pth, clock_id);
1175 // get the timespec associated to the thread clock
1176 struct timespec ts;
1177 if ( ::clock_gettime( clock_id, &ts ) )
1178 {
1179 ec.assign( errno, system::system_category );
1180 return time_point();
1181 }
1182 ec.clear();
1183 // transform to nanoseconds
1184 return time_point(duration(
1185 static_cast<thread_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
1186 }
1187 };
1188
1189 [endsect]
1190 ]
1191
1192
1193 [endsect]
1194
1195 [section Specific Clocks]
1196 [section system_clock]
1197
1198 __system_clock is useful when you need to correlate the time with a known epoch so you can convert it to a calendar time. Note the specific functions in the __system_clock class.
1199
1200
1201 [endsect]
1202 [section steady_clock]
1203
1204 __steady_clock is useful when you need to wait for a specific amount of time. __steady_clock time can not be reset. As other steady clocks, it is usually based on the processor tick.
1205
1206 Here is a polling solution, but it will probably be too inefficient:
1207
1208 boost::chrono::__steady_clock::time_point start= chrono::__steady_clock::now();
1209 boost::chrono::__steady_clock::duration delay= chrono::seconds(5);
1210 while (boost::chrono::__steady_clock::now() - start <= delay) {}
1211
1212 [endsect]
1213
1214 [section high_resolution_clock]
1215
1216 When available, __high_resolution_clock is usually more expensive than the other system-wide clocks, so they are used only when the provided resolution is required to the application.
1217
1218 [endsect]
1219
1220 [section process_cpu_clock]
1221
1222 Process and thread clocks are used usually to measure the time spent by code blocks, as a basic time-spent profiling of different blocks of code (Boost.Chrono.Stopwatch is a clear example of this use).
1223
1224 [endsect]
1225
1226 [section thread_clock]
1227
1228 You can use __thread_clock whenever you want to measure the time spent by the current thread. For example:
1229
1230 boost::chrono::__thread_clock::time_point start=boost::chrono::__thread_clock::now();
1231 // ... do something ...
1232
1233 typedef boost::chrono::__milliseconds ms;
1234 ms d = boost::chrono::__thread_clock::now() - start;
1235 // d now holds the number of milliseconds from start to end.
1236 std::cout << ms.count() << "ms\n";
1237
1238 If you need seconds with a floating-point representation you can do:
1239
1240 typedef boost::chrono::__duration<double> sec; // seconds, stored with a double.
1241 sec d = end - start;
1242 std::cout << sec.count() << "s\n";
1243
1244 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`.
1245
1246 [endsect]
1247 [endsect]
1248
1249 [section I/O]
1250
1251 [section:duration_io duration]
1252
1253 Any __duration can be streamed out to a `basic_ostream`. The run-time value of the __duration is formatted according to the rules and current format settings for __duration`::rep` get_duration_style and the durationpunct facet.
1254
1255 the format is either
1256
1257 <value> <unit>
1258
1259 or
1260
1261 <unit> <value>
1262
1263
1264
1265 [warning Need to be changed
1266 This is followed by a single space and then the compile-time unit name of the __duration. This unit name is built on the string returned from `ratio_string<>` and the data used to construct the __duration_punct which was inserted into the stream's locale. If a __duration_punct has not been inserted into the stream's locale, a default constructed __duration_punct will be added to the stream's locale.
1267
1268 __duration unit names come in two varieties: long(prefix) and short(symbol). The default constructed __duration_punct provides names in the long(prefix) format. These names are English descriptions. Other languages are supported by constructing a __duration_punct with the proper spellings for "hours", "minutes" and "seconds", and their abbreviations (for the short format). The short or long format can be easily chosen by streaming a `duration_short()` or `duration_long()` manipulator respectively or using the parameterized manipulator `duration_fmt(duration_style::prefix)` or `duration_fmt(duration_style::symbol)`.
1269
1270 ]
1271 __example
1272
1273 #include <iostream>
1274 #include <boost/chrono/chrono_io.hpp>
1275
1276 int main()
1277 {
1278 using namespace std;
1279 using namespace boost;
1280
1281 cout << "milliseconds(1) = "
1282 << boost::chrono::milliseconds(1) << '\n';
1283
1284 cout << "milliseconds(3) + microseconds(10) = "
1285 << boost::chrono::milliseconds(3) + boost::chrono::microseconds(10) << '\n';
1286
1287 cout << "hours(3) + minutes(10) = "
1288 << boost::chrono::hours(3) + boost::chrono::minutes(10) << '\n';
1289
1290 typedef boost::chrono::duration<long long, boost::ratio<1, 2500000000> > ClockTick;
1291 cout << "ClockTick(3) + boost::chrono::nanoseconds(10) = "
1292 << ClockTick(3) + boost::chrono::nanoseconds(10) << '\n';
1293
1294 // ...
1295 return 0;
1296 }
1297
1298 The output could be
1299
1300 milliseconds(1) = 1 microsecond
1301 milliseconds(3) + microseconds(10) = 3010 microseconds
1302 hours(3) + minutes(10) = 190 minutes
1303 ClockTick(3) + nanoseconds(10) = 56 [1/5000000000]seconds
1304
1305 Set cout to use short names:
1306 milliseconds(3) + microseconds(10) = 3010 __mus
1307 hours(3) + minutes(10) = 190 m
1308 ClockTick(3) + nanoseconds(10) = 56 [1/5000000000]s
1309
1310 system_clock::now() = 129387415616250000 [1/10000000]s since Jan 1, 1970
1311 monotonic_clock::now() = 37297387636417 ns since boot
1312
1313 Set cout to use long names:
1314 high_resolution_clock::now() = 37297387655134 nanoseconds since boot
1315
1316 As can be seen, each duration type can be streamed without having to manually stream the compile-time units after the run-time value. And when the compile-time unit is known to be a "common unit", English names are used. For "uncommon units" a unit name is composed from the reduced numerator and denominator of the associated __ratio. Whatever stream/locale settings are set for `duration::rep` are used for the value. Additionally, when the value is 1, singular forms for the units are used.
1317
1318 Sometimes it is desired to shorten these names by using the SI symbols instead of SI prefixes. This can be accomplished with the use of the __symbol_format manipulator [footnote __duration_short in V1]:
1319
1320 cout << "\nSet cout to use short names:\n";
1321 cout << boost::chrono::symbol_format;
1322
1323 cout << "milliseconds(3) + microseconds(10) = "
1324 << boost::chrono::milliseconds(3) + boost::chrono::microseconds(10) << '\n';
1325
1326 cout << "hours(3) + minutes(10) = "
1327 << boost::chrono::hours(3) + boost::chrono::minutes(10) << '\n';
1328
1329 cout << "ClockTick(3) + nanoseconds(10) = "
1330 << ClockTick(3) + boost::chrono::nanoseconds(10) << '\n';
1331
1332
1333 The output could be
1334
1335 Set cout to use short names:
1336 milliseconds(3) + microseconds(10) = 3010 __mus
1337 hours(3) + minutes(10) = 190 m
1338 ClockTick(3) + nanoseconds(10) = 56 [1/5000000000]s
1339
1340 system_clock::now() = 129387415616250000 [1/10000000]s since Jan 1, 1970
1341 monotonic_clock::now() = 37297387636417 ns since boot
1342
1343 Set cout to use long names:
1344 high_resolution_clock::now() = 37297387655134 nanoseconds since boot
1345
1346 The [mu] for microsecond is specified to be U+00B5, encoded as UTF-8, UTF-16 or UTF-32 as appropriate for the stream's character size.
1347
1348 When the format decision is taken at runtime, it could be better to use the parameterized manipulator __duration_fmt as in
1349
1350 duration_style style;
1351 //...
1352 cout << duration_fmt(style);
1353
1354
1355
1356 Parsing a __duration follows rules analogous to the __duration converting constructor. A value and a unit (SI symbol or prefixed) are read from the `basic_istream`. If the __duration has an integral representation, then the value parsed must be exactly representable in the target __duration (after conversion to the target __duration units), else __failbit is set. __durations based on floating-point representations can be parsed using any units that do not cause overflow.
1357
1358 For example a stream containing "5000 milliseconds" can be parsed into seconds, but if the stream contains "3001 ms", parsing into `seconds` will cause __failbit to be set.
1359
1360 __example
1361
1362 #include <boost/chrono/chrono_io.hpp>
1363 #include <sstream>
1364 #include <cassert>
1365
1366 int main()
1367 {
1368 using namespace std;
1369
1370 istringstream in("5000 milliseconds 4000 ms 3001 ms");
1371 boost::chrono::seconds d(0);
1372 in >> d;
1373 assert(in.good());
1374 assert(d == seconds(5));
1375 in >> d;
1376 assert(in.good());
1377 assert(d == seconds(4));
1378 in >> d;
1379 assert(in.fail());
1380 assert(d == seconds(4));
1381
1382 return 0;
1383 }
1384
1385
1386 Note that a __duration failure may occur late in the parsing process. This means that the characters making up the failed parse in the stream are usually consumed despite the failure to successfully parse.
1387
1388 Sometimes in templated code it is difficult to know what the unit of your duration is. It is all deterministic, and inspect-able. But it can be inconvenient to do so, especially if you just need to print out a "debugging" statement. For example:
1389
1390 // round to nearest, to even on tie
1391 template <class __To, class Rep, class Period>
1392 To
1393 round(const duration<Rep, Period>& d)
1394 {
1395 To t0 = duration_cast<To>(d);
1396 To t1 = t0;
1397 ++t1;
1398 auto diff0 = d - t0;
1399 cout << "diff0 = " << diff0 << '\n';
1400 auto diff1 = t1 - d;
1401 cout << "diff1 = " << diff1 << '\n';
1402 if (diff0 == diff1)
1403 {
1404 if (t0.count() & 1)
1405 return t1;
1406 return t0;
1407 }
1408 else if (diff0 < diff1)
1409 return t0;
1410 return t1;
1411 }
1412
1413 This is where I/O for duration really shines. The compiler knows what the type of diff0 is and with this proposal that type (with proper units) will automatically be printed out for you. For example:
1414
1415 milliseconds ms = round<milliseconds>(nanoseconds(123)); // diff0 = 123 nanoseconds
1416 // diff1 = 999877 nanoseconds
1417 milliseconds ms = round<milliseconds>(Ticks(44)); // diff0 = 2 [1/3000]seconds
1418 // diff1 = 1 [1/3000]second
1419
1420 This simple I/O will make duration so much more accessible to programmers.
1421
1422 [endsect]
1423
1424 [section:system_clock_time_point_io `system_clock::time_point`]
1425
1426 [/warning
1427
1428 This feature has been disable defining `BOOST_CHRONO_DONT_PROVIDE_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT` until a fix for the following ticket is found:
1429
1430 - [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile
1431
1432 - [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile
1433
1434 In this case the io operators behave like any time_point as defined in next section.
1435
1436 In order to enable this features on compilers working with, you will need to define `BOOST_CHRONO_PROVIDES_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT`.
1437
1438 ]
1439
1440 __system_clock is special. It is the only clock that has conversions between its `time_point` and `time_t`. C subsequently relates time_t to the [@http://en.wikipedia.org/wiki/Gregorian_calendar Gregorian calendar] via `ctime`, `gmtime`, `localtime`, and `strftime`. Neither C, nor POSIX relate `time_t` to any calendar other than the [@http://en.wikipedia.org/wiki/Gregorian_calendar Gregorian calendar]. ISO 8601 is specified only in terms of the [@http://en.wikipedia.org/wiki/Gregorian_calendar Gregorian calendar].
1441
1442 __Boost_Chrono provides `system_clock::time_point` I/O in terms of the Gregorian calendar, and no other calendar. However as `system_clock::time_point` remains convertible with `time_t`, it is possible for clients to create other calendars which interoperate with `time_t` and subsequently `system_clock::time_point`.
1443
1444 Furthermore, it is existing practice for all major hosted operating systems to store system time in a format which facilitates display as [@http://en.wikipedia.org/wiki/Coordinated_Universal_Time Coordinated Universal Time] (UTC). Therefore __Boost_Chrono provides that the default output for `system_clock::time_point` be in a format that represents a point in time with respect to UTC.
1445
1446 cout << system_clock::now() << '\n';
1447
1448 could output
1449
1450 2011-09-15 18:36:59.325132 +0000
1451
1452 This format is strongly influenced by ISO 8601, but places a ' ' between the date and time instead of a 'T'. The former appears to more accurately represent existing practice. A fully numeric format was chosen so as to be understandable to as large a group of human readers as possible. A 24 hour format was chosen for the same reasons.
1453
1454 Of the referenced standards, only ISO 8601 discusses the output of fractional seconds. Neither C nor POSIX have built-in functionality for this. However it appears to be universal (as of this writing) that `system_clock::period` is sub-second. And it seems desirable that if you stream out a `system_clock::time_point`, you ought to be able to stream it back in and get the same value. Therefore the streaming of fractional seconds (at least by default) appears to be unavoidable.
1455
1456 Finally the trailing " +0000" disambiguates the UTC-formatted `system_clock::time_point` from one formatted with respect to the local time zone of the computer. The latter can easily be achieved with:
1457
1458 cout << time_fmt(local) << system_clock::now() << '\n';
1459
1460 that could result in
1461
1462 2011-09-15 14:36:59.325132 -0400
1463
1464 Note that `system_clock::time_point` itself is neither UTC, nor the local time. However in practice, `system_clock::time_point` is a count of ticks beyond some epoch which is synchronized with UTC. So as a mobile computer moves across time zones, the time zone traversal does not impact the value of a `system_clock::time_point` produced by `system_clock::now()`. And it is only in formatting it for human consumption that one can choose UTC or the local time zone. C and POSIX treat `time_t` just as __Boost_Chrono treats `system_clock::time_point`:
1465
1466 tm* gmtime(const time_t* timer) -> UTC
1467 tm* localtime(const time_t* timer) -> local time
1468
1469 This proposal simply extends the C/POSIX `time_t` functionality to C++ syntax and `system_clock::time_point`.
1470
1471 The `time_fmt()` manipulator is "sticky". It will remain in effect until the stream destructs or until it is changed. The stream can be reset to its default state with:
1472
1473 cout << time_fmt(utc);
1474
1475 And the formatting can be further customized by using the time format sequences. For example:
1476
1477 cout << time_fmt(local, "%A %B %e, %Y %r");
1478 cout << system_clock::now() << '\n'; // Sunday April 24, 2011 02:36:59 PM
1479
1480 When specifying formatting manipulators for wide streams, use wide strings.
1481
1482 You can use the same manipulators with istreams to specify parsing sequences.
1483
1484 Unfortunately there are no formatting/parsing sequences which indicate fractional seconds. __Boost_Chrono does not provide such sequences. In the meantime, one can format and parse fractional seconds for `system_clock::time_point` by defaulting the format, or by using an empty string in `time_fmt()`.
1485
1486 The stream's current locale may impact the parsing/format sequences supplied to the `system_clock::time_point` manipulators (e.g. names of days of the week, and names of months).
1487 [endsect]
1488
1489 [section:other_clocks_time_point_io Other clocks time_point]
1490
1491 Unlike `system_clock::time_point`, the other clocks have no conversion with `time_t`. There is likely no relationship between steady_clock::time_point and UTC at all (UTC is not steady).
1492
1493 In general a __time_point is formatted by outputting its internal __duration followed by a string that describes the __time_point`::clock` epoch. This string will vary for each distinct clock, and for each implementation of the supplied clocks.
1494
1495 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
1496 cout << "steady_clock::now() = " << boost::chrono::steady_clock::now() << '\n';
1497 #endif
1498 cout << "\nSet cout to use long names:\n"
1499 << boost::chrono::duration_long
1500 << "high_resolution_clock::now() = "
1501 << boost::chrono::high_resolution_clock::now() << '\n';
1502
1503 The output could be
1504
1505 steady_clock::now() = 37297387636417 ns since boot
1506
1507 Set cout to use long names:
1508 high_resolution_clock::now() = 37297387655134 nanoseconds since boot
1509
1510
1511 [/
1512 There ...
1513 cout << "\nsystem_clock::now() = " << boost::chrono::system_clock::now() << '\n';
1514
1515 The output could be
1516 system_clock::now() = 129387415616250000 [1/10000000]s since Jan 1, 1970
1517
1518 ]
1519
1520 Parsing a __time_point involves first parsing a __duration and then parsing the epoch string. If the epoch string does not match that associated with `time_point::clock` then failbit will be set.
1521
1522 __example
1523
1524 #include <boost/chrono/chrono_io.hpp>
1525 #include <sstream>
1526 #include <iostream>
1527 #include <cassert>
1528
1529 int main()
1530 {
1531 using namespace std;
1532
1533 boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now();
1534 stringstream io;
1535 io << t0;
1536 boost::chrono::high_resolution_clock::time_point t1;
1537 io >> t1;
1538 assert(!io.fail());
1539 cout << io.str() << '\n';
1540 cout << t0 << '\n';
1541 cout << t1 << '\n';
1542 boost::chrono::high_resolution_clock::time_point t = boost::chrono::high_resolution_clock::now();
1543 cout << t << '\n';
1544
1545 cout << "That took " << t - t0 << '\n';
1546 cout << "That took " << t - t1 << '\n';
1547
1548 return 0;
1549 }
1550
1551 The output could be:
1552
1553 50908679121461 nanoseconds since boot
1554 That took 649630 nanoseconds
1555
1556 Here's a simple example to find out how many hours the computer has been up (on this platform):
1557
1558 #include <boost/chrono/chrono_io.hpp>
1559 #include <iostream>
1560
1561 int main()
1562 {
1563 using namespace std;
1564 using namespace boost;
1565
1566 typedef boost::chrono::time_point<boost::chrono::steady_clock, boost::chrono::duration<double, boost::ratio<3600> > > T;
1567 T tp = boost::chrono::steady_clock::now();
1568 std::cout << tp << '\n';
1569 return 0;
1570 }
1571
1572 The output could be:
1573
1574 17.8666 hours since boot
1575
1576 [endsect]
1577
1578 [section Low level I/O]
1579 [/====================]
1580
1581 The I/O interface described in the preceding I/O sections were at the user level. These services are based on low level services that are useful when writing libraries. The low level services are related to access to the associated ios state and locale facets. The design follows the C++ IOStreams standard design:
1582
1583 The library encapsulate the locale-dependent parsing and formatting of __duration into a new facet class. Let's focus on formatting in this example. The concerned facet class is __duration_put, analogous to time_put, money_put, etc.
1584
1585 The use of this facet is similar to the time_put facet.
1586
1587 [endsect] [/ Low level I/O]
1588
1589 [endsect] [/ I/O]
1590
1591 [/include stopwatches/tutorial.qbk]
1592
1593 [endsect]
1594 [/===============]
1595 [section Examples]
1596 [/===============]
1597
1598
1599
1600 [section Duration]
1601
1602 [/===============]
1603 [section How you Override the Duration's Default Constructor]
1604
1605 Next we show how to override the __duration_s default constructor to do anything you want (in this case set it to zero). All we need to do is to change the representation
1606
1607 namespace I_dont_like_the_default_duration_behavior {
1608
1609 template <class R>
1610 class zero_default
1611 {
1612 public:
1613 typedef R rep;
1614
1615 private:
1616 rep rep_;
1617 public:
1618 zero_default(rep i = 0) : rep_(i) {}
1619 operator rep() const {return rep_;}
1620
1621 zero_default& operator+=(zero_default x) {rep_ += x.rep_; return *this;}
1622 zero_default& operator-=(zero_default x) {rep_ -= x.rep_; return *this;}
1623 zero_default& operator*=(zero_default x) {rep_ *= x.rep_; return *this;}
1624 zero_default& operator/=(zero_default x) {rep_ /= x.rep_; return *this;}
1625
1626 zero_default operator+ () const {return *this;}
1627 zero_default operator- () const {return zero_default(-rep_);}
1628 zero_default& operator++() {++rep_; return *this;}
1629 zero_default operator++(int) {return zero_default(rep_++);}
1630 zero_default& operator--() {--rep_; return *this;}
1631 zero_default operator--(int) {return zero_default(rep_--);}
1632
1633 friend zero_default operator+(zero_default x, zero_default y) {return x += y;}
1634 friend zero_default operator-(zero_default x, zero_default y) {return x -= y;}
1635 friend zero_default operator*(zero_default x, zero_default y) {return x *= y;}
1636 friend zero_default operator/(zero_default x, zero_default y) {return x /= y;}
1637
1638 friend bool operator==(zero_default x, zero_default y) {return x.rep_ == y.rep_;}
1639 friend bool operator!=(zero_default x, zero_default y) {return !(x == y);}
1640 friend bool operator< (zero_default x, zero_default y) {return x.rep_ < y.rep_;}
1641 friend bool operator<=(zero_default x, zero_default y) {return !(y < x);}
1642 friend bool operator> (zero_default x, zero_default y) {return y < x;}
1643 friend bool operator>=(zero_default x, zero_default y) {return !(x < y);}
1644 };
1645
1646 typedef boost::chrono::__duration<zero_default<long long>, boost::nano > nanoseconds;
1647 typedef boost::chrono::__duration<zero_default<long long>, boost::micro > microseconds;
1648 typedef boost::chrono::__duration<zero_default<long long>, boost::milli > milliseconds;
1649 typedef boost::chrono::__duration<zero_default<long long> > seconds;
1650 typedef boost::chrono::__duration<zero_default<long long>, boost::ratio<60> > minutes;
1651 typedef boost::chrono::__duration<zero_default<long long>, boost::ratio<3600> > hours;
1652 }
1653
1654 Usage
1655
1656 using namespace I_dont_like_the_default_duration_behavior;
1657
1658 milliseconds ms;
1659 std::cout << ms.count() << '\n';
1660
1661 ['See the source file [@boost:libs/chrono/example/i_dont_like_the_default_duration_behavior.cpp example/i_dont_like_the_default_duration_behavior.cpp]]
1662
1663 [endsect]
1664 [/
1665 [/=========================]
1666 [section runtime_resolution]
1667
1668 This example shows how to handle duration with resolution not known until run-time
1669
1670 class duration
1671 {
1672 public:
1673 typedef long long rep;
1674 private:
1675 rep rep_;
1676
1677 static const double ticks_per_nanosecond;
1678
1679 public:
1680 typedef boost::chrono::duration<double, boost::nano> tonanosec;
1681
1682 duration() {} // = default;
1683 explicit duration(const rep& r) : rep_(r) {}
1684
1685 // conversions
1686 explicit duration(const tonanosec& d)
1687 : rep_(static_cast<rep>(d.count() * ticks_per_nanosecond)) {}
1688
1689 // explicit
1690 operator tonanosec() const {return tonanosec(rep_/ticks_per_nanosecond);}
1691
1692 // observer
1693
1694 rep count() const {return rep_;}
1695
1696 // arithmetic
1697
1698 duration& operator+=(const duration& d) {rep_ += d.rep_; return *this;}
1699 duration& operator-=(const duration& d) {rep_ += d.rep_; return *this;}
1700 duration& operator*=(rep rhs) {rep_ *= rhs; return *this;}
1701 duration& operator/=(rep rhs) {rep_ /= rhs; return *this;}
1702
1703 duration operator+() const {return *this;}
1704 duration operator-() const {return duration(-rep_);}
1705 duration& operator++() {++rep_; return *this;}
1706 duration operator++(int) {return duration(rep_++);}
1707 duration& operator--() {--rep_; return *this;}
1708 duration operator--(int) {return duration(rep_--);}
1709
1710 friend duration operator+(duration x, duration y) {return x += y;}
1711 friend duration operator-(duration x, duration y) {return x -= y;}
1712 friend duration operator*(duration x, rep y) {return x *= y;}
1713 friend duration operator*(rep x, duration y) {return y *= x;}
1714 friend duration operator/(duration x, rep y) {return x /= y;}
1715
1716 friend bool operator==(duration x, duration y) {return x.rep_ == y.rep_;}
1717 friend bool operator!=(duration x, duration y) {return !(x == y);}
1718 friend bool operator< (duration x, duration y) {return x.rep_ < y.rep_;}
1719 friend bool operator<=(duration x, duration y) {return !(y < x);}
1720 friend bool operator> (duration x, duration y) {return y < x;}
1721 friend bool operator>=(duration x, duration y) {return !(x < y);}
1722 };
1723
1724 ['See the source file [@boost:libs/chrono/example/runtime_resolution.cpp here]]
1725
1726 [endsect]
1727 ]
1728 [/================]
1729 [section Saturating]
1730
1731 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 template parameter Rep in boost::chrono::__duration to demonstrate a duration class that does not silently ignore overflow.
1732
1733 ['See the source file [@boost:libs/chrono/example/saturating.cpp example/saturating.cpp]]
1734
1735 [endsect]
1736
1737
1738
1739 [/==================]
1740 [section xtime Conversions]
1741
1742 Example round_up utility: converts d to To, rounding up for inexact conversions
1743 Being able to *easily* write this function is a major feature!
1744
1745 #include <boost/chrono.hpp>
1746 #include <boost/type_traits.hpp>
1747
1748 #include <iostream>
1749
1750 template <class To, class Rep, class Period>
1751 To
1752 round_up(boost::chrono::duration<Rep, Period> d)
1753 {
1754 To result = boost::chrono::duration_cast<To>(d);
1755 if (result < d)
1756 ++result;
1757 return result;
1758 }
1759
1760 To demonstrate interaction with an xtime-like facility:
1761
1762
1763 struct xtime
1764 {
1765 long sec;
1766 unsigned long usec;
1767 };
1768
1769 template <class Rep, class Period>
1770 xtime
1771 to_xtime_truncate(boost::chrono::__duration<Rep, Period> d)
1772 {
1773 xtime xt;
1774 xt.sec = static_cast<long>(boost::chrono::__duration_cast<__seconds>(d).count());
1775 xt.usec = static_cast<long>(boost::chrono::__duration_cast<__microseconds>(d - __seconds(xt.sec)).count());
1776 return xt;
1777 }
1778
1779 template <class Rep, class Period>
1780 xtime
1781 to_xtime_round_up(boost::chrono::__duration<Rep, Period> d)
1782 {
1783 xtime xt;
1784 xt.sec = static_cast<long>(boost::chrono::__duration_cast<__seconds>(d).count());
1785 xt.usec = static_cast<unsigned long>(round_up<boost::chrono::__microseconds>(d - boost::chrono::__seconds(xt.sec)).count());
1786 return xt;
1787 }
1788
1789 microseconds
1790 from_xtime(xtime xt)
1791 {
1792 return boost::chrono::__seconds(xt.sec) + boost::chrono::__microseconds(xt.usec);
1793 }
1794
1795 void print(xtime xt)
1796 {
1797 std::cout << '{' << xt.sec << ',' << xt.usec << "}\n";
1798 }
1799
1800 Usage
1801
1802 xtime xt = to_xtime_truncate(seconds(3) + boost::chrono::__milliseconds(251));
1803 print(xt);
1804 boost::chrono::milliseconds ms = boost::chrono::__duration_cast<boost::chrono::__milliseconds>(from_xtime(xt));
1805 std::cout << ms.count() << " milliseconds\n";
1806 xt = to_xtime_round_up(ms);
1807 print(xt);
1808 xt = to_xtime_truncate(boost::chrono::seconds(3) + __nanoseconds(999));
1809 print(xt);
1810 xt = to_xtime_round_up(boost::chrono::seconds(3) + __nanoseconds(999));
1811 print(xt);
1812
1813
1814 ['See the source file [@boost:libs/chrono/example/xtime.cpp xtime.cpp]]
1815
1816 [endsect]
1817
1818
1819 [endsect]
1820 [section Clocks]
1821
1822 [/==================]
1823 [section Cycle count]
1824
1825 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.
1826
1827
1828 #include <boost/chrono.hpp>
1829 #include <boost/type_traits.hpp>
1830 #include <iostream>
1831
1832 template <long long speed>
1833 struct cycle_count
1834 {
1835 typedef typename boost::__ratio_multiply__<boost::__ratio<speed>, boost::__mega>::type
1836 frequency; // Mhz
1837 typedef typename boost::__ratio_divide__<boost::__ratio<1>, frequency>::type period;
1838 typedef long long rep;
1839 typedef boost::chrono::__duration<rep, period> duration;
1840 typedef boost::chrono::__time_point<cycle_count> time_point;
1841
1842 static time_point now()
1843 {
1844 static long long tick = 0;
1845 // return exact cycle count
1846 return time_point(duration(++tick)); // fake access to clock cycle count
1847 }
1848 };
1849
1850 template <long long speed>
1851 struct approx_cycle_count
1852 {
1853 static const long long frequency = speed * 1000000; // MHz
1854 typedef nanoseconds duration;
1855 typedef duration::rep rep;
1856 typedef duration::period period;
1857 static const long long nanosec_per_sec = period::den;
1858 typedef boost::chrono::__time_point<approx_cycle_count> time_point;
1859
1860 static time_point now()
1861 {
1862 static long long tick = 0;
1863 // return cycle count as an approximate number of nanoseconds
1864 // compute as if nanoseconds is only duration in the std::lib
1865 return time_point(duration(++tick * nanosec_per_sec / frequency));
1866 }
1867 };
1868
1869 ['See the source file [@boost:libs/chrono/example/cycle_count.cpp cycle_count.cpp]]
1870
1871 [endsect]
1872
1873 [/==================]
1874 [section xtime_clock]
1875
1876 This example demonstrates the use of a timeval-like struct to be used as the representation type for both __duration and __time_point.
1877
1878 class xtime {
1879 private:
1880 long tv_sec;
1881 long tv_usec;
1882
1883 void fixup() {
1884 if (tv_usec < 0) {
1885 tv_usec += 1000000;
1886 --tv_sec;
1887 }
1888 }
1889
1890 public:
1891 explicit xtime(long sec, long usec) {
1892 tv_sec = sec;
1893 tv_usec = usec;
1894 if (tv_usec < 0 || tv_usec >= 1000000) {
1895 tv_sec += tv_usec / 1000000;
1896 tv_usec %= 1000000;
1897 fixup();
1898 }
1899 }
1900
1901 explicit xtime(long long usec) {
1902 tv_usec = static_cast<long>(usec % 1000000);
1903 tv_sec = static_cast<long>(usec / 1000000);
1904 fixup();
1905 }
1906
1907 // explicit
1908 operator long long() const {return static_cast<long long>(tv_sec) * 1000000 + tv_usec;}
1909
1910 xtime& operator += (xtime rhs) {
1911 tv_sec += rhs.tv_sec;
1912 tv_usec += rhs.tv_usec;
1913 if (tv_usec >= 1000000) {
1914 tv_usec -= 1000000;
1915 ++tv_sec;
1916 }
1917 return *this;
1918 }
1919
1920 xtime& operator -= (xtime rhs) {
1921 tv_sec -= rhs.tv_sec;
1922 tv_usec -= rhs.tv_usec;
1923 fixup();
1924 return *this;
1925 }
1926
1927 xtime& operator %= (xtime rhs) {
1928 long long t = tv_sec * 1000000 + tv_usec;
1929 long long r = rhs.tv_sec * 1000000 + rhs.tv_usec;
1930 t %= r;
1931 tv_sec = static_cast<long>(t / 1000000);
1932 tv_usec = static_cast<long>(t % 1000000);
1933 fixup();
1934 return *this;
1935 }
1936
1937 friend xtime operator+(xtime x, xtime y) {return x += y;}
1938 friend xtime operator-(xtime x, xtime y) {return x -= y;}
1939 friend xtime operator%(xtime x, xtime y) {return x %= y;}
1940
1941 friend bool operator==(xtime x, xtime y)
1942 { return (x.tv_sec == y.tv_sec && x.tv_usec == y.tv_usec); }
1943
1944 friend bool operator<(xtime x, xtime y) {
1945 if (x.tv_sec == y.tv_sec)
1946 return (x.tv_usec < y.tv_usec);
1947 return (x.tv_sec < y.tv_sec);
1948 }
1949
1950 friend bool operator!=(xtime x, xtime y) { return !(x == y); }
1951 friend bool operator> (xtime x, xtime y) { return y < x; }
1952 friend bool operator<=(xtime x, xtime y) { return !(y < x); }
1953 friend bool operator>=(xtime x, xtime y) { return !(x < y); }
1954
1955 friend std::ostream& operator<<(std::ostream& os, xtime x)
1956 {return os << '{' << x.tv_sec << ',' << x.tv_usec << '}';}
1957 };
1958
1959 Clock based on timeval-like struct.
1960
1961 class xtime_clock
1962 {
1963 public:
1964 typedef xtime rep;
1965 typedef boost::micro period;
1966 typedef boost::chrono::duration<rep, period> duration;
1967 typedef boost::chrono::time_point<xtime_clock> time_point;
1968
1969 static time_point now()
1970 {
1971 #if defined(BOOST_CHRONO_WINDOWS_API)
1972 time_point t(duration(xtime(0)));
1973 gettimeofday((timeval*)&t, 0);
1974 return t;
1975
1976 #elif defined(BOOST_CHRONO_MAC_API)
1977
1978 time_point t(duration(xtime(0)));
1979 gettimeofday((timeval*)&t, 0);
1980 return t;
1981
1982 #elif defined(BOOST_CHRONO_POSIX_API)
1983 //time_point t(0,0);
1984
1985 timespec ts;
1986 ::clock_gettime( CLOCK_REALTIME, &ts );
1987
1988 xtime xt( ts.tv_sec, ts.tv_nsec/1000);
1989 return time_point(duration(xt));
1990
1991 #endif // POSIX
1992 }
1993 };
1994
1995 Usage of xtime_clock
1996
1997 std::cout << "sizeof xtime_clock::time_point = " << sizeof(xtime_clock::time_point) << '\n';
1998 std::cout << "sizeof xtime_clock::duration = " << sizeof(xtime_clock::duration) << '\n';
1999 std::cout << "sizeof xtime_clock::rep = " << sizeof(xtime_clock::rep) << '\n';
2000 xtime_clock::duration delay(boost::chrono::milliseconds(5));
2001 xtime_clock::time_point start = xtime_clock::now();
2002 while (xtime_clock::now() - start <= delay) {}
2003 xtime_clock::time_point stop = xtime_clock::now();
2004 xtime_clock::duration elapsed = stop - start;
2005 std::cout << "paused " << boost::chrono::::nanoseconds(elapsed).count() << " nanoseconds\n";
2006
2007
2008 ['See the source file [@boost:libs/chrono/example/timeval_demo.cpp example/timeval_demo.cpp]]
2009
2010 [endsect]
2011 [endsect]
2012
2013
2014
2015 [/
2016 [/======================================================]
2017 [section Howard Hinnant's original demonstration program]
2018
2019 ['See the source file [@boost:libs/chrono/example/time2_demo.cpp example/time2_demo.cpp]]
2020
2021 [endsect]
2022 ]
2023 [section Time Point]
2024
2025 [/==================]
2026 [section min Utility]
2027
2028 The user can define a function returning the earliest __time_point as follows:
2029
2030 template <class __Clock, class __Duration1, class __Duration2>
2031 typename boost::__common_type<__time_point<__Clock, __Duration1>,
2032 __time_point<__Clock, __Duration2> >::type
2033 min(__time_point<__Clock, __Duration1> t1, __time_point<__Clock, __Duration2> t2)
2034 {
2035 return t2 < t1 ? t2 : t1;
2036 }
2037
2038 Being able to *easily* write this function is a major feature!
2039
2040 BOOST_AUTO(t1, system_clock::now() + seconds(3));
2041 BOOST_AUTO(t2, system_clock::now() + nanoseconds(3));
2042 BOOST_AUTO(t3, min(t1, t2));
2043
2044 ['See the source file [@boost:libs/chrono/example/min_time_point.cpp example/min_time_point.cpp]]
2045
2046 [endsect]
2047
2048
2049 [/===============================================================]
2050 [section A Tiny Program that Times How Long Until a Key is Struck]
2051
2052 #include <boost/chrono.hpp>
2053 #include <iostream>
2054 #include <iomanip>
2055
2056 using namespace boost::chrono;
2057
2058 template< class __Clock >
2059 class timer
2060 {
2061 typename __Clock::time_point start;
2062 public:
2063 timer() : start( __Clock::now() ) {}
2064 typename __Clock::duration elapsed() const
2065 {
2066 return __Clock::now() - start;
2067 }
2068 double seconds() const
2069 {
2070 return elapsed().count() * ((double)Clock::period::num/Clock::period::den);
2071 }
2072 };
2073
2074 int main()
2075 {
2076 timer<__system_clock> t1;
2077 timer<__steady_clock> t2;
2078 timer<__high_resolution_clock> t3;
2079
2080 std::cout << "Type the Enter key: ";
2081 std::cin.get();
2082
2083 std::cout << std::fixed << std::setprecision(9);
2084 std::cout << "system_clock-----------: "
2085 << t1.seconds() << " seconds\n";
2086 std::cout << "steady_clock--------: "
2087 << t2.seconds() << " seconds\n";
2088 std::cout << "high_resolution_clock--: "
2089 << t3.seconds() << " seconds\n";
2090
2091 __system_clock::time_point d4 = __system_clock::now();
2092 __system_clock::time_point d5 = __system_clock::now();
2093
2094 std::cout << "\nsystem_clock latency-----------: " << (d5 - d4).count() << std::endl;
2095
2096 __steady_clock::time_point d6 = __steady_clock::now();
2097 __steady_clock::time_point d7 = __steady_clock::now();
2098
2099 std::cout << "steady_clock latency--------: " << (d7 - d6).count() << std::endl;
2100
2101 __high_resolution_clock::time_point d8 = __high_resolution_clock::now();
2102 __high_resolution_clock::time_point d9 = __high_resolution_clock::now();
2103
2104 std::cout << "high_resolution_clock latency--: " << (d9 - d8).count() << std::endl;
2105
2106 std::time_t now = __system_clock::to_time_t(__system_clock::now());
2107
2108 std::cout << "\nsystem_clock::now() reports UTC is "
2109 << std::asctime(std::gmtime(&now)) << "\n";
2110
2111 return 0;
2112 }
2113
2114 The output of this program run looks like this:
2115
2116
2117
2118
2119 ['See the source file [@boost:libs/chrono/example/await_keystroke.cpp example/await_keystroke.cpp]]
2120
2121 [endsect]
2122
2123 [/
2124 [/===============================================================]
2125 [section Time Command]
2126
2127 #include <boost/chrono/stopclock.hpp>
2128 #include <cstdlib>
2129 #include <string>
2130 #include <iostream>
2131
2132 int main( int argc, char * argv[] )
2133 {
2134 if ( argc == 1 )
2135 {
2136 std::cout << "invoke: timex [-v] command [args...]\n"
2137 " command will be executed and timings displayed\n"
2138 " -v option causes command and args to be displayed\n";
2139 return 1;
2140 }
2141
2142 std::string s;
2143
2144 bool verbose = false;
2145 if ( argc > 1 && *argv[1] == '-' && *(argv[1]+1) == 'v' )
2146 {
2147 verbose = true;
2148 ++argv;
2149 --argc;
2150 }
2151
2152 for ( int i = 1; i < argc; ++i )
2153 {
2154 if ( i > 1 ) s += ' ';
2155 s += argv[i];
2156 }
2157
2158 if ( verbose )
2159 { std::cout << "command: \"" << s.c_str() << "\"\n"; }
2160
2161 boost::chrono::__stopclock<> t;
2162
2163 return std::system( s.c_str() );
2164 }
2165
2166 ['See the source file [@boost:libs/chrono/example/timex.cpp example/timex.cpp]]
2167
2168 [endsect]
2169 ]
2170
2171 [section 24 Hours Display]
2172
2173 In the example above we take advantage of the fact that __time_points convert as long as they have the same clock, and as long as their internal __durations convert. We also take advantage of the fact that a __duration with a floating-point representation will convert from anything. Finally the I/O system discovers the more readable "hours" unit for our `duration<double, ratio<3600>>`.
2174
2175 There are many other ways to format __durations and __time_points. For example see [@http://en.wikipedia.org/wiki/ISO_8601#Durations ISO 8601]. Instead of coding every possibility into `operator<<`, which would lead to significant code bloat for even the most trivial uses, this document seeks to inform the reader how to write custom I/O when desired.
2176
2177 As an example, the function below streams arbitrary __durations to arbitrary `basic_ostreams` using the format:
2178
2179 [-]d/hh:mm:ss.cc
2180
2181 Where:
2182
2183 * `d` is the number of `days`
2184 * `h` is the number of `hours`
2185 * `m` is the number of `minutes`
2186 * `ss.cc` is the number of `seconds` rounded to the nearest hundredth of a second
2187
2188 #include <boost/chrono/chrono_io.hpp>
2189 #include <ostream>
2190 #include <iostream>
2191
2192 // format duration as [-]d/hh::mm::ss.cc
2193 template <class CharT, class Traits, class Rep, class Period>
2194 std::basic_ostream<CharT, Traits>&
2195 display(std::basic_ostream<CharT, Traits>& os,
2196 boost::chrono::duration<Rep, Period> d)
2197 {
2198 using namespace std;
2199 using namespace boost;
2200
2201 typedef boost::chrono::duration<long long, boost::ratio<86400> > days;
2202 typedef boost::chrono::duration<long long, boost:centi> centiseconds;
2203
2204 // if negative, print negative sign and negate
2205 if (d < boost::chrono::duration<Rep, Period>(0))
2206 {
2207 d = -d;
2208 os << '-';
2209 }
2210 // round d to nearest centiseconds, to even on tie
2211 centiseconds cs = boost::chrono::duration_cast<centiseconds>(d);
2212 if (d - cs > boost::chrono::milliseconds(5)
2213 || (d - cs == boost::chrono::milliseconds(5) && cs.count() & 1))
2214 ++cs;
2215 // separate seconds from centiseconds
2216 boost::chrono::seconds s = boost::chrono::duration_cast<boost::chrono::seconds>(cs);
2217 cs -= s;
2218 // separate minutes from seconds
2219 boost::chrono::minutes m = boost::chrono::duration_cast<boost::chrono::minutes>(s);
2220 s -= m;
2221 // separate hours from minutes
2222 boost::chrono::hours h = boost::chrono::duration_cast<boost::chrono::hours>(m);
2223 m -= h;
2224 // separate days from hours
2225 days dy = boost::chrono::duration_cast<days>(h);
2226 h -= dy;
2227 // print d/hh:mm:ss.cc
2228 os << dy.count() << '/';
2229 if (h < boost::chrono::hours(10))
2230 os << '0';
2231 os << h.count() << ':';
2232 if (m < boost::chrono::minutes(10))
2233 os << '0';
2234 os << m.count() << ':';
2235 if (s < boost::chrono::seconds(10))
2236 os << '0';
2237 os << s.count() << '.';
2238 if (cs < boost::chrono::centiseconds(10))
2239 os << '0';
2240 os << cs.count();
2241 return os;
2242 }
2243
2244 int main()
2245 {
2246 using namespace std;
2247 using namespace boost;
2248
2249 display(cout, boost::chrono::steady_clock::now().time_since_epoch()
2250 + boost::chrono::duration<long, boost::mega>(1)) << '\n';
2251 display(cout, -boost::chrono::milliseconds(6)) << '\n';
2252 display(cout, boost::chrono::duration<long, boost::mega>(1)) << '\n';
2253 display(cout, -boost::chrono::duration<long, boost::mega>(1)) << '\n';
2254 }
2255
2256 The output could be:
2257
2258 12/06:03:22.95
2259 -0/00:00:00.01
2260 11/13:46:40.00
2261 -11/13:46:40.00
2262
2263 [endsect]
2264
2265
2266 [/=======================================================]
2267 [section Simulated Thread Interface Demonstration Program]
2268
2269 The C++11 standard library's multi-threading library requires the ability to deal with the representation of time in a manner consistent with modern C++ practices. Next is a simulation of this interface.
2270
2271 The non-member sleep functions can be emulated as follows:
2272
2273 namespace boost { namespace this_thread {
2274
2275 template <class Rep, class Period>
2276 void sleep_for(const chrono::__duration<Rep, Period>& d) {
2277 chrono::__microseconds t = chrono::__duration_cast<chrono::__microseconds>(d);
2278 if (t < d)
2279 ++t;
2280 if (t > chrono::__microseconds(0))
2281 std::cout << "sleep_for " << t.count() << " microseconds\n";
2282 }
2283
2284 template <class __Clock, class __Duration>
2285 void sleep_until(const chrono::__time_point<__Clock, __Duration>& t) {
2286 using namespace chrono;
2287 typedef __time_point<__Clock, __Duration> Time;
2288 typedef __system_clock::time_point SysTime;
2289 if (t > __Clock::now()) {
2290 typedef typename __common_type<typename Time::duration,
2291 typename SysTime::duration>::type D;
2292 /* auto */ D d = t - __Clock::now();
2293 microseconds us = __duration_cast<__microseconds>(d);
2294 if (us < d)
2295 ++us;
2296 SysTime st = __system_clock::now() + us;
2297 std::cout << "sleep_until ";
2298 detail::print_time(st);
2299 std::cout << " which is " << (st - __system_clock::now()).count() << " microseconds away\n";
2300 }
2301 }
2302
2303 }}
2304
2305
2306 Next is the `boost::thread::timed_mutex` modified functions
2307
2308 namespace boost {
2309 struct timed_mutex {
2310 // ...
2311
2312 template <class Rep, class Period>
2313 bool try_lock_for(const chrono::__duration<Rep, Period>& d) {
2314 chrono::__microseconds t = chrono::__duration_cast<chrono::__microseconds>(d);
2315 if (t <= chrono::__microseconds(0))
2316 return try_lock();
2317 std::cout << "try_lock_for " << t.count() << " microseconds\n";
2318 return true;
2319 }
2320
2321 template <class __Clock, class __Duration>
2322 bool try_lock_until(const chrono::__time_point<__Clock, __Duration>& t)
2323 {
2324 using namespace chrono;
2325 typedef __time_point<__Clock, __Duration> Time;
2326 typedef __system_clock::time_point SysTime;
2327 if (t <= __Clock::now())
2328 return try_lock();
2329 typedef typename __common_type<typename Time::duration,
2330 typename __Clock::duration>::type D;
2331 /* auto */ D d = t - __Clock::now();
2332 microseconds us = __duration_cast<__microseconds>(d);
2333 SysTime st = __system_clock::now() + us;
2334 std::cout << "try_lock_until ";
2335 detail::print_time(st);
2336 std::cout << " which is " << (st - __system_clock::now()).count()
2337 << " microseconds away\n";
2338 return true;
2339 }
2340 };
2341 }
2342
2343 `boost::thread::condition_variable` time related function are modified as follows:
2344
2345 namespace boost {
2346 struct condition_variable
2347 {
2348 // ...
2349
2350 template <class Rep, class Period>
2351 bool wait_for(mutex&, const chrono::__duration<Rep, Period>& d) {
2352 chrono::microseconds t = chrono::__duration_cast<chrono::microseconds>(d);
2353 std::cout << "wait_for " << t.count() << " microseconds\n";
2354 return true;
2355 }
2356
2357 template <class __Clock, class __Duration>
2358 bool wait_until(mutex&, const chrono::__time_point<__Clock, __Duration>& t) {
2359 using namespace boost::chrono;
2360 typedef __time_point<__Clock, __Duration> Time;
2361 typedef __system_clock::time_point SysTime;
2362 if (t <= __Clock::now())
2363 return false;
2364 typedef typename __common_type<typename Time::duration,
2365 typename __Clock::duration>::type D;
2366 /* auto */ D d = t - __Clock::now();
2367 microseconds us = __duration_cast<__microseconds>(d);
2368 SysTime st = __system_clock::now() + us;
2369 std::cout << "wait_until ";
2370 detail::print_time(st);
2371 std::cout << " which is " << (st - __system_clock::now()).count()
2372 << " microseconds away\n";
2373 return true;
2374 }
2375 };
2376 }
2377
2378 Next follows how simple is the usage of this functions:
2379
2380 boost::mutex m;
2381 boost::timed_mutex mut;
2382 boost::condition_variable cv;
2383
2384 using namespace boost;
2385
2386 this_thread::sleep_for(chrono::__seconds(3));
2387 this_thread::sleep_for(chrono::__nanoseconds(300));
2388 chrono::__system_clock::time_point time_limit = chrono::__system_clock::now() + chrono::__seconds_(4) + chrono::__milliseconds(500);
2389 this_thread::sleep_until(time_limit);
2390
2391 mut.try_lock_for(chrono::__milliseconds(30));
2392 mut.try_lock_until(time_limit);
2393
2394 cv.wait_for(m, chrono::__minutes(1)); // real code would put this in a loop
2395 cv.wait_until(m, time_limit); // real code would put this in a loop
2396
2397 // For those who prefer floating-point
2398 this_thread::sleep_for(chrono::__duration<double>(0.25));
2399 this_thread::sleep_until(chrono::__system_clock::now() + chrono::__duration<double>(1.5));
2400
2401
2402 ['See the source file [@boost:libs/chrono/example/simulated_thread_interface_demo.cpp example/simulated_thread_interface_demo.cpp]]
2403
2404 [endsect]
2405
2406 [endsect]
2407 [section IO]
2408 [/=======================================================]
2409 [section:french French Output]
2410
2411 Example use of output in French
2412
2413 #include <boost/chrono/chrono_io.hpp>
2414 #include <iostream>
2415 #include <locale>
2416
2417 int main()
2418 {
2419 using namespace std;
2420 using namespace boost;
2421 using namespace boost::chrono;
2422
2423 cout.imbue(locale(locale(), new duration_punct<char>
2424 (
2425 duration_punct<char>::use_long,
2426 "secondes", "minutes", "heures",
2427 "s", "m", "h"
2428 )));
2429 hours h(5);
2430 minutes m(45);
2431 seconds s(15);
2432 milliseconds ms(763);
2433 cout << h << ", " << m << ", " << s << " et " << ms << '\n';
2434 }
2435
2436 Output is:
2437
2438 5 heures, 45 minutes, 15 secondes et 763 millisecondes
2439
2440 ['See the source file [@boost:libs/chrono/example/french.cpp example/french.cpp]]
2441
2442 [endsect] [/section:french French Output]
2443 [endsect] [/section IO]
2444
2445 [endsect] [/section Examples]
2446
2447
2448 [/================================]
2449 [section:ext_references External Resources]
2450 [/================================]
2451
2452 [variablelist
2453
2454 [
2455 [[@http://www.open-std.org/jtc1/sc22/wg21 [*C++ Standards Committee's current Working Paper]]]
2456 [The most authoritative reference material for the library is the C++ Standards Committee's current Working Paper (WP). 20.11 Time utilities "time"]
2457 ]
2458
2459 [
2460 [[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]]]
2461 [From Howard E. Hinnant, Walter E. Brown, Jeff Garland and Marc Paterno. Is very informative and provides motivation for key design decisions]
2462 ]
2463
2464
2465 [
2466 [[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3134.html#934 [*LGW 934. duration is missing operator%]]]
2467 [From Terry Golubiewski. Is very informative and provides motivation for key design decisions]
2468 ]
2469
2470 [
2471 [[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3135.html#935 [*LGW 935. clock error handling needs to be specified]]]
2472 [From Beman Dawes. This issue has been stated as NAD Future.]
2473 ]
2474
2475 ]
2476
2477 [endsect]
2478
2479 [endsect]
2480
2481 [/=================]
2482 [section:reference Reference ]
2483 [/=================]
2484
2485 As `constexpr` will not be supported by some compilers, it is replaced in the code by `BOOST_CONSTEXPR` for `constexpr` functions and `BOOST_STATIC_CONSTEXPR` for struct/class static fields. The same applies to `noexecpt` which is replaced by `noexcept` in the code.
2486
2487 The documentation doesn't use these macros.
2488
2489 [/=============================================]
2490 [section:chrono_include_hpp Header `<boost/chrono/include.hpp>`]
2491 [/=============================================]
2492
2493 Include all the chrono header files.
2494
2495 #include <boost/chrono/chrono.hpp>
2496 #include <boost/chrono/chrono_io.hpp>
2497 #include <boost/chrono/process_cpu_clocks.hpp>
2498 #include <boost/chrono/thread_clocks.hpp>
2499 #include <boost/chrono/ceil.hpp>
2500 #include <boost/chrono/floor.hpp>
2501 #include <boost/chrono/round.hpp>
2502
2503 [/ /////////////////////////////////////////////////////
2504 #include <boost/chrono/stopwatches.hpp>
2505 ] [////////////////////////////////////////////////////]
2506 [endsect]
2507
2508 [section:cpp0x Included on the C++11 Recommendation]
2509
2510 [/=============================================]
2511 [section:chrono_hpp Header `<boost/chrono.hpp>`]
2512 [/=============================================]
2513
2514 Include only the standard files.
2515
2516 #include <boost/chrono/chrono.hpp>
2517
2518 [endsect]
2519
2520 [/=============================================]
2521 [section:chrono_chrono_hpp Header `<boost/chrono/chrono.hpp>`]
2522 [/=============================================]
2523
2524 Include only the standard files.
2525
2526 #include <boost/chrono/duration.hpp>
2527 #include <boost/chrono/time_point.hpp>
2528 #include <boost/chrono/system_clocks.hpp>
2529 #include <boost/chrono/typeof/boost/chrono/chrono.hpp>
2530
2531 [section:limitations Limitations and Extensions]
2532
2533 At present, there is no know limitation respect to the C++11 standard.
2534
2535 The current implementation provides in addition:
2536
2537 * clock error handling as specified in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3135.html#935 clock error handling needs to be specified].
2538 * process and thread clocks.
2539
2540
2541 [endsect] [/section:limitations Limitations and Extensions]
2542
2543 [section:conf Configuration Macros]
2544
2545 [section:assert How Assert Behaves?]
2546
2547 When `BOOST_NO_CXX11_STATIC_ASSERT` is defined, the user can select the way static assertions are reported. Define
2548
2549 * `BOOST_CHRONO_USES_STATIC_ASSERT`: define it if you want to use Boost.StaticAssert.
2550 * `BOOST_CHRONO_USES_MPL_ASSERT`: define it if you want to use Boost.MPL static assertions.
2551 * `BOOST_CHRONO_USES_ARRAY_ASSERT`: define it if you want to use internal static assertions.
2552
2553 The default behavior is as `BOOST_CHRONO_USES_ARRAY_ASSERT` was defined.
2554
2555 When `BOOST_CHRONO_USES_MPL_ASSERT` is not defined the following symbols are defined as
2556
2557 #define BOOST_CHRONO_A_DURATION_REPRESENTATION_CAN_NOT_BE_A_DURATION \
2558 "A duration representation can not be a duration"
2559 #define BOOST_CHRONO_SECOND_TEMPLATE_PARAMETER_OF_DURATION_MUST_BE_A_STD_RATIO \
2560 "Second template parameter of duration must be a boost::ratio"
2561 #define BOOST_CHRONO_DURATION_PERIOD_MUST_BE_POSITIVE \
2562 "duration period must be positive"
2563 #define BOOST_CHRONO_SECOND_TEMPLATE_PARAMETER_OF_TIME_POINT_MUST_BE_A_BOOST_CHRONO_DURATION \
2564 "Second template parameter of time_point must be a boost::chrono::duration"
2565
2566 Depending on the static assertion used system you will have an hint of the failing assertion either through the symbol or through the text.
2567
2568 [endsect]
2569
2570 [section:no_hybrid Don't provide Hybrid Error Handling]
2571
2572 When `BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING` is defined the lib don't provides the hybrid error handling prototypes:
2573
2574 Clock::time_point Clock::now(system::error_code&ec=boost::throws());
2575
2576 This allow to be closer to the standard and to avoid the Boost.System dependency, making possible to have Boost.Chrono as a header-only library.
2577
2578 By default `BOOST_CHRONO_PROVIDE_HYBRID_ERROR_HANDLING` is defined.
2579
2580 [endsect] [/section:header_only How to Build Boost.Chrono as a Header Only Library?]
2581
2582 [section:header_only How to Build Boost.Chrono as a Header Only Library?]
2583
2584 When `BOOST_CHRONO_HEADER_ONLY` is defined the lib is header-only.
2585
2586 If in addition `BOOST_USE_WINDOWS_H` is defined `<windows.h>` is included, otherwise files in `boost/detail/win` are used to reduce the impact of including `<windows.h>`.
2587
2588 However, you will either need to define `BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING` or link with Boost.System.
2589
2590 [endsect] [/section:header_only How to Build Boost.Chrono as a Header Only Library?]
2591
2592 [section:deprecated_io Deprecated IO]
2593
2594 Version 2.0.0 deprecates the preceding IO features.
2595
2596 However the default version is always version 1.
2597 If you don't want to include the deprecated features you could define `BOOST_CHRONO_DONT_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0`.
2598
2599 [/
2600 These deprecated features will be provided by default up to boost 1.55.
2601 Since 1.55 these features will not be included any more by default.
2602 Since this version, if you want to include the deprecated features yet you could define `BOOST_CHRONO_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0`.
2603 These id features will be only available until boost 1.58, that is you have 1 year and a half to move to the new features.
2604 ]
2605
2606 [endsect]
2607
2608
2609 [section:system_clock_time_point time_point<system_clock,D> specialization limitation]
2610
2611 [/warning
2612
2613 The time_point<system_clock,D> formatter/parser specializations don't work yet. It has been disable defining `BOOST_CHRONO_DONT_PROVIDE_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT` until a fix for the following ticket is found:
2614
2615 - [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile
2616
2617 - [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile
2618
2619 In this case the io operators behave like any time_point as if the specialization was removed.
2620
2621 In order to enable this features on compilers working with, you will need to define `BOOST_CHRONO_PROVIDES_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT`.
2622
2623 ]
2624
2625 [endsect]
2626
2627 [section:version Version]
2628
2629 `BOOST_CHRONO_VERSION` defines the Boost.Chrono version.
2630 The default version is 1. In this case the following breaking or extending macros are defined if the opposite is not requested:
2631
2632 * `BOOST_CHRONO_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0`
2633
2634 The user can request the version 2 by defining `BOOST_CHRONO_VERSION` to 2. In this case the following breaking or extending macros are defined if the opposite is not requested:
2635
2636 * Breaking change `BOOST_CHRONO_DONT_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0 `
2637
2638 The default value for `BOOST_CHRONO_VERSION` will be changed to 2 since Boost 1.55.
2639
2640 [endsect]
2641
2642
2643 [endsect] [/section:conf Configuration Macros]
2644
2645 [endsect] [/section:chrono_hpp Header `<boost/chrono.hpp>`]
2646
2647
2648 [/=============================================]
2649 [section:duration_hpp Header `<boost/chrono/duration.hpp>`]
2650 [/=============================================]
2651
2652 This file contains duration specific classes and non-member functions.
2653
2654 namespace boost {
2655 namespace chrono {
2656
2657 template <class Rep, class Period = __ratio<1> > class __duration;
2658
2659 }
2660 template <class Rep1, class Period1, class Rep2, class Period2>
2661 struct __common_type_spe<duration<Rep1, Period1>,
2662 duration<Rep2, Period2> >;
2663
2664 namespace chrono {
2665
2666 // customization traits
2667 template <class Rep> struct __treat_as_floating_point;
2668 template <class Rep> struct __duration_values;
2669
2670 // duration arithmetic
2671 template <class Rep1, class Period1, class Rep2, class Period2>
2672 constexpr
2673 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
2674 __duration__op_plus_1(
2675 const duration<Rep1, Period1>& lhs,
2676 const duration<Rep2, Period2>& rhs);
2677
2678 template <class Rep1, class Period1, class Rep2, class Period2>
2679 constexpr
2680 typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
2681 __duration__op_minus_1(
2682 const duration<Rep1, Period1>& lhs,
2683 const duration<Rep2, Period2>& rhs);
2684
2685 template <class Rep1, class Period, class Rep2>
2686 constexpr
2687 duration<typename common_type<Rep1, Rep2>::type, Period>
2688 __duration__op_mult_1(
2689 const duration<Rep1, Period>& d,
2690 const Rep2& s);
2691
2692 template <class Rep1, class Period, class Rep2>
2693 constexpr
2694 duration<typename common_type<Rep1, Rep2>::type, Period>
2695 __duration__op_mult_2(
2696 const Rep1& s,
2697 const duration<Rep2, Period>& d);
2698
2699 template <class Rep1, class Period, class Rep2>
2700 constexpr
2701 duration<typename common_type<Rep1, Rep2>::type, Period>
2702 __duration__op_div_2(
2703 const duration<Rep1, Period>& d,
2704 const Rep2& s);
2705
2706 template <class Rep1, class Period1, class Rep2, class Period2>
2707 constexpr
2708 typename common_type<Rep1, Rep2>::type
2709 __duration__op_div_3(
2710 const duration<Rep1, Period1>& lhs,
2711 const duration<Rep2, Period2>& rhs);
2712
2713 #ifdef BOOST_CHRONO_EXTENSIONS
2714 // Used to get frequency of events
2715 template <class Rep1, class Rep2, class Period>
2716 constexpr
2717 double __duration__op_div_1(
2718 const Rep1& s,
2719 const duration<Rep2, Period>& d);
2720 #endif
2721
2722 // duration comparisons
2723 template <class Rep1, class Period1, class Rep2, class Period2>
2724 constexpr bool __duration__op_eq_1(
2725 const duration<Rep1, Period1>& lhs,
2726 const duration<Rep2, Period2>& rhs);
2727
2728 template <class Rep1, class Period1, class Rep2, class Period2>
2729 constexpr bool __duration__op_neq_1(
2730 const duration<Rep1, Period1>& lhs,
2731 const duration<Rep2, Period2>& rhs);
2732
2733 template <class Rep1, class Period1, class Rep2, class Period2>
2734 constexpr bool __duration__op_le_1(
2735 const duration<Rep1, Period1>& lhs,
2736 const duration<Rep2, Period2>& rhs);
2737 template <class Rep1, class Period1, class Rep2, class Period2>
2738 constexpr bool __duration__op_leq_1(
2739 const duration<Rep1, Period1>& lhs,
2740 const duration<Rep2, Period2>& rhs);
2741
2742 template <class Rep1, class Period1, class Rep2, class Period2>
2743 constexpr bool __duration__op_gt_1(
2744 const duration<Rep1, Period1>& lhs,
2745 const duration<Rep2, Period2>& rhs);
2746 template <class Rep1, class Period1, class Rep2, class Period2>
2747 constexpr bool __duration__op_geq_1(
2748 const duration<Rep1, Period1>& lhs,
2749 const duration<Rep2, Period2>& rhs);
2750
2751 // duration_cast
2752
2753 template <class ToDuration, class Rep, class Period>
2754 constexpr
2755 ToDuration __duration_cast(const duration<Rep, Period>& d);
2756
2757 // convenience typedefs
2758 typedef duration<boost::int_least64_t, nano> __nanoseconds; // at least 64 bits needed
2759 typedef duration<boost::int_least64_t, micro> __microseconds; // at least 55 bits needed
2760 typedef duration<boost::int_least64_t, milli> __milliseconds; // at least 45 bits needed
2761 typedef duration<boost::int_least64_t> __seconds; // at least 35 bits needed
2762 typedef duration<boost::int_least32_t, ratio< 60> > __minutes; // at least 29 bits needed
2763 typedef duration<boost::int_least32_t, ratio<3600> > __hours; // at least 23 bits needed
2764
2765 }
2766 }
2767
2768
2769 [section:traits Time-related Traits]
2770
2771 [section:treat_as_floating_point Metafunction `treat_as_floating_point<>`]
2772
2773 template <class Rep> struct treat_as_floating_point
2774 : boost::is_floating_point<Rep> {};
2775
2776 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 __durations. Otherwise, the implicit convertibility depends on the tick periods of the __durations. 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.
2777
2778
2779 [endsect]
2780 [section:duration_values Class Template `duration_values`]
2781
2782 template <class Rep>
2783 struct duration_values
2784 {
2785 public:
2786 static constexpr Rep __zero();
2787 static constexpr Rep __max();
2788 static constexpr Rep __min();
2789 };
2790
2791 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.
2792
2793 [section:zero Static Member Function `zero()`]
2794
2795 static constexpr Rep zero();
2796
2797 __returns `Rep(0)`. [*Note:] `Rep(0)` is specified instead of `Rep()` since `Rep()` may have some other meaning, such as an uninitialized value.
2798
2799 __remarks The value returned corresponds to the additive identity.
2800
2801 [endsect]
2802 [section:max Static Member Function `max()`]
2803
2804 static constexpr Rep max();
2805
2806 __returns `numeric_limits<Rep>::max()`.
2807
2808 __remarks The value returned compares greater than zero().
2809
2810 [endsect]
2811 [section:min Static Member Function `min()`]
2812
2813 static constexpr Rep min();
2814
2815 __returns `numeric_limits<Rep>::lowest()`.
2816
2817 __remarks The value returned compares less than or equal to `zero()`.
2818
2819 [endsect]
2820
2821 [endsect]
2822
2823 [endsect]
2824
2825 [section:common_type_spe `common_type` Specialization]
2826
2827 template <class Rep1, class Period1, class Rep2, class Period2>
2828 struct __common_type<chrono::__duration<Rep1, Period1>, chrono::__duration<Rep2, Period2> >
2829 {
2830 typedef chrono::__duration<typename __common_type<Rep1, Rep2>::type, __see_bellow__> type;
2831 };
2832
2833 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`.
2834
2835 [*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 __durations are involved (but not truncation error).
2836
2837 [endsect]
2838
2839
2840 [section:duration Class Template `duration<>`]
2841
2842 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.
2843
2844 namespace boost { namespace chrono {
2845
2846 template <class Rep, class Period>
2847 class duration {
2848 public:
2849 typedef Rep rep;
2850 typedef Period period;
2851 private:
2852 rep rep_; // exposition only
2853 public:
2854 constexpr __duration__c_0();
2855 template <class Rep2>
2856 constexpr explicit __duration__c_1(const Rep2& r);
2857
2858 template <class Rep2, class Period2>
2859 constexpr __duration__c_2(const duration<Rep2, Period2>& d);
2860
2861 duration& operator=(const duration&) = default;
2862
2863 constexpr rep __duration__count() const;
2864
2865 constexpr duration __duration__op_plus();
2866 constexpr duration __duration__op_minus();
2867 duration& __duration__op_pre_inc();
2868 duration __duration__op_post_inc(int);
2869 duration& __duration__op_pre_dec();
2870 duration __duration__op_post_dec(int);
2871
2872 duration& __duration__op_plus_eq(const duration& d);
2873 duration& __duration__op_minus_eq(const duration& d);
2874
2875 duration& __duration__op_mult_eq(const rep& rhs);
2876 duration& __duration__op_div_eq(const rep& rhs);
2877 duration& __duration__op_mod_eq(const rep& rhs);
2878 duration& __duration__op_mod_eq2(const duration& rhs);
2879
2880 static constexpr duration __duration__zero();
2881 static constexpr duration __duration__min();
2882 static constexpr duration __duration__max();
2883 };
2884
2885 }}
2886
2887 `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.
2888
2889 `Period` must be an instantiation of `ratio`, compile diagnostic otherwise.
2890
2891 `Period::num` must be positive, compile diagnostic otherwise.
2892
2893 Examples:
2894
2895 * `__duration<long, __ratio<60> >` holds a count of minutes using a long.
2896
2897 * `__duration<long long, milli>` holds a count of milliseconds using a long long.
2898
2899 * `__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).
2900
2901 The following members of __duration do not throw an exception unless the indicated operations on the representations throw an exception.
2902
2903 [section:duration_c_0 Constructor `duration()`]
2904
2905 constexpr duration();
2906
2907 __effects Constructs an object of type __duration initialized from `duration_values<rep>::zero()` in C++98 or `BOOST_CHRONO_DURATION_DEFAULTS_TO_ZERO` is defined, otherwise the duration is uninitialized.
2908
2909 [endsect]
2910
2911 [section:duration_c_1 Constructor `duration(const Rep2&)`]
2912
2913 template <class Rep2>
2914 constexpr explicit duration(const Rep2& r);
2915
2916 __remarks `Rep2` is implicitly convertible to `rep`, and
2917
2918 * `treat_as_floating_point<rep>::value` is `true`, or
2919 * `!treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value` is `true`.
2920
2921 If these constraints are not met, this constructor will 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.
2922
2923 __example
2924
2925 __duration<int, milli> d(3.5); // do not compile
2926 __duration<int, milli> d(3); // ok
2927
2928 __effects Constructs an object of type __duration.
2929
2930 __post_conditions `count() == static_cast<rep>(r)`.
2931
2932 [endsect]
2933 [section:duration_c_2 Constructor `duration(const duration&)`]
2934
2935 template <class Rep2, class Period2>
2936 constexpr __duration(const __duration<Rep2, Period2>& d);
2937
2938 __remarks `treat_as_floating_point<rep>::value`, or `ratio_divide<Period2, period>::type::den == 1`, else this constructor will not participate in overload resolution. [*note] This requirement prevents implicit truncation error when converting between integral-based __durations. Such a construction could easily lead to confusion about the value of the __duration.
2939
2940 __example
2941
2942 __duration<int, milli> ms(3);
2943 __duration<int, micro> us = ms; // ok
2944 __duration<int, milli> ms2 = us; // do not compile
2945
2946 __effects Constructs an object of type __duration, constructing `rep_` from `duration_cast<__duration>(d).count()`.
2947
2948 [endsect]
2949 [section:count Member Function `count() const`]
2950
2951 constexpr rep count() const;
2952
2953 __returns `rep_`.
2954
2955 [endsect]
2956 [section:op_unary_plus Member Function `operator+() const`]
2957
2958 constexpr __duration operator+() const;
2959
2960 __returns `*this`.
2961
2962 [endsect]
2963 [section:op_unary_minus Member Function `operator-() const`]
2964
2965 constexpr __duration operator-() const;
2966
2967 __returns `__duration(-rep_)`.
2968
2969 [endsect]
2970 [section:op_pre_inc Member Function `operator++()`]
2971
2972 __duration& operator++();
2973
2974 __effects `++rep_`.
2975
2976 __returns `*this`.
2977
2978 [endsect]
2979 [section:op_post_inc Member Function `operator++(int)`]
2980
2981 __duration operator++(int);
2982
2983 __returns `__duration(rep_++)`.
2984
2985 [endsect]
2986 [section:op_pre_dec Member Function `operator--()`]
2987
2988 __duration& operator--();
2989
2990 __effects `--rep_`.
2991
2992 __returns `*this`.
2993
2994 [endsect]
2995 [section:op_post_dec Member Function `operator--(int)`]
2996
2997 __duration operator--(int);
2998
2999 __returns `__duration(rep_--)`.
3000
3001 [endsect]
3002 [section:op_plus_eq Member Function `operator+=(const duration&)`]
3003
3004 __duration& operator+=(const __duration& d);
3005
3006 __effects `rep_ += d.count()`.
3007
3008 __returns `*this`.
3009
3010 [endsect]
3011 [section:op_minus_eq Member Function `operator-=(const duration&)`]
3012
3013 __duration& operator-=(const __duration& d);
3014
3015 __effects `rep_ -= d.count()`.
3016
3017 __returns `*this`.
3018
3019 [endsect]
3020 [section:op_mod_eq Member Function `operator%=(const duration&)`]
3021
3022 __duration& operator%=(const __duration& d);
3023
3024 __effects `rep_ %= d.count()`.
3025
3026 __returns `*this`.
3027
3028 [endsect]
3029 [section:op_mult_eq Member Function `operator*=(const rep&)`]
3030
3031 __duration& operator*=(const rep& rhs);
3032
3033 __effects `rep_ *= rhs`.
3034
3035 __returns `*this`.
3036
3037 [endsect]
3038 [section:op_div_eq Member Function `operator/=(const rep&)`]
3039
3040 __duration& operator/=(const rep& rhs);
3041
3042 __effects `rep_ /= rhs`.
3043
3044 __returns `*this`.
3045
3046 [endsect]
3047 [section:op_mod_eq2 Member Function `operator%=(const rep&)`]
3048
3049 __duration& operator%=(const rep& rhs);
3050
3051 __effects `rep_ %= rhs`.
3052
3053 __returns `*this`.
3054
3055 [endsect]
3056
3057
3058 [section:zero Static Member Function `zero()`]
3059
3060 static constexpr __duration zero();
3061
3062 __returns `__duration(__duration_values<rep>::zero())`.
3063
3064 [endsect]
3065 [section:min Static Member Function `min()`]
3066
3067 static constexpr __duration min();
3068
3069 __returns `__duration(__duration_values<rep>::min()).`
3070
3071 [endsect]
3072 [section:max Static Member Function `max()`]
3073
3074 static constexpr __duration max();
3075
3076 __returns `__duration(__duration_values<rep>::max())`.
3077
3078 [endsect]
3079
3080 [endsect]
3081
3082
3083 [section:arith `duration` Non-Member Arithmetic]
3084
3085 [section:duration__op_plus_1 Non-Member Function `operator+(duration,duration)`]
3086
3087 template <class Rep1, class Period1, class Rep2, class Period2>
3088 constexpr
3089 typename __common_type<__duration<Rep1, Period1>, __duration<Rep2, Period2> >::type
3090 operator+(const __duration<Rep1, Period1>& lhs, const __duration<Rep2, Period2>& rhs);
3091
3092 __returns `CD(CD(lhs).count() + CD(rhs).count())` where `CD` is the type of the return value.
3093
3094 [endsect]
3095 [section:duration__op_minus_1 Non-Member Function `operator-(duration,duration)`]
3096
3097 template <class Rep1, class Period1, class Rep2, class Period2>
3098 constexpr
3099 typename __common_type<__duration<Rep1, Period1>, __duration<Rep2, Period2> >::type
3100 operator-(const __duration<Rep1, Period1>& lhs, const __duration<Rep2, Period2>& rhs);
3101
3102 __returns `CD(CD(lhs).count() - CD(rhs).count())` where `CD` is the type of the return value.
3103
3104 [endsect]
3105 [section:duration__op_mult_1 Non-Member Function `operator*(duration,Rep1)`]
3106
3107 template <class Rep1, class Period, class Rep2>
3108 constexpr
3109 __duration<typename __common_type<Rep1, Rep2>::type, Period>
3110 operator*(const __duration<Rep1, Period>& d, const Rep2& s);
3111
3112 __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`.
3113
3114 __returns `CD(CD(d).count() * s)` where `CD` is the type of the return value.
3115
3116 [endsect]
3117 [section:duration__op_mult_2 Non-Member Function `operator*(Rep1,duration)`]
3118
3119 template <class Rep1, class Period, class Rep2>
3120 constexpr
3121 __duration<typename __common_type<Rep1, Rep2>::type, Period>
3122 operator*(const Rep1& s, const __duration<Rep2, Period>& d);
3123
3124 __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`.
3125
3126 __returns `d * s`.
3127
3128 [endsect]
3129
3130
3131 [section:duration__op_div_1 Non-Member Function `operator/(duration,Rep2)`]
3132
3133 template <class Rep1, class Period, class Rep2>
3134 constexpr
3135 __duration<typename __common_type<Rep1, Rep2>::type, Period>
3136 operator/(const __duration<Rep1, Period>& d, const Rep2& s);
3137
3138 __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.
3139
3140 __returns `CD(CD(d).count() / s)` where `CD` is the type of the return value.
3141
3142 [endsect]
3143 [section:duration__op_div_2 Non-Member Function `operator/(duration,duration)`]
3144
3145 template <class Rep1, class Period1, class Rep2, class Period2>
3146 constexpr
3147 typename __common_type<Rep1, Rep2>::type
3148 operator/(const __duration<Rep1, Period1>& lhs, const __duration<Rep2, Period2>& rhs);
3149
3150 __remarks Let `CD` represent the __common_type of the two __duration arguments.
3151 __returns Returns `CD(lhs).count() / CD(rhs).count()`.
3152
3153 [endsect]
3154
3155 [section:duration__op_div_3 Non-Member Function `operator/(Rep1,duration)`]
3156
3157 Included only if BOOST_CHRONO_EXTENSIONS is defined.
3158
3159 This overloading could be used to get the frequency of an event counted by `Rep1`.
3160
3161 template <class Rep1, class Rep2, class Period>
3162 constexpr
3163 double operator/(const Rep1& s, const __duration<Rep2, Period>& d);
3164
3165 __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. Let `CD` represent __duration<CR,Period>.
3166
3167 __returns `CR(s)/CD(d).count()` where `CD` is the type of the return value.
3168
3169
3170 [endsect]
3171
3172
3173 [section:duration__op_mod_1 Non-Member Function `operator%(duration,Rep2)`]
3174
3175 template <class Rep1, class Period, class Rep2>
3176 constexpr
3177 __duration<typename __common_type<Rep1, Rep2>::type, Period>
3178 operator%(const __duration<Rep1, Period>& d, const Rep2& s);
3179
3180 __remarks Let `CR` represent the __common_type of `Rep1` and `Rep2`. This function will not participate in overload resolution unless Rep2 must be implicitly convertible to CR and Rep2 must not be an instantiation of __duration.
3181
3182 __returns CD(CD(d).count() % s) where `CD` is the type of the return value.
3183
3184 [endsect]
3185
3186 [section:duration__op_mod_2 Non-Member Function `operator%(duration,duration)`]
3187
3188 template <class Rep1, class Period1, class Rep2, class Period2>
3189 constexpr
3190 typename __common_type<__duration<Rep1, Period1>, __duration<Rep2, Period2> >::type
3191 operator%(const __duration<Rep1, Period1>& lhs,
3192 const __duration<Rep2, Period2>& rhs);
3193
3194 __remarks This function will not participate in overload resolution unless
3195
3196 __returns CD(CD(lhs).count() % CD(rhs).count()) where `CD` is the type of the return value.
3197
3198 [endsect]
3199 [endsect]
3200
3201 [section:cmp `duration` Non-Member Comparaisons]
3202
3203 [section:duration__op_eq_1 Non-Member Function `operator==(duration,duration)`]
3204
3205 template <class Rep1, class Period1, class Rep2, class Period2>
3206 bool operator==(const __duration<Rep1, Period1>& lhs,
3207 const __duration<Rep2, Period2>& rhs);
3208
3209 __returns Let `CD` represent the __common_type of the two __duration arguments.
3210
3211 __returns Returns `CD(lhs).count() == CD(rhs).count()`
3212
3213 [endsect]
3214 [section:duration__op_neq_1 Non-Member Function `operator!=(duration,duration)`]
3215
3216 template <class Rep1, class Period1, class Rep2, class Period2>
3217 bool operator!=(const __duration<Rep1, Period1>& lhs,
3218 const __duration<Rep2, Period2>& rhs);
3219
3220 __returns `!(lhs == rhs)`.
3221
3222 [endsect]
3223 [section:duration__op_lt_1 Non-Member Function `operator<(duration,duration)`]
3224
3225 template <class Rep1, class Period1, class Rep2, class Period2>
3226 bool operator< (const __duration<Rep1, Period1>& lhs,
3227 const __duration<Rep2, Period2>& rhs);
3228
3229 __returns Let `CD` represent the __common_type of the two __duration arguments. Returns `CD(lhs).count() < CD(rhs).count()`
3230
3231 [endsect]
3232 [section:duration__op_leq_1 Non-Member Function `operator<=(duration,duration)`]
3233
3234 template <class Rep1, class Period1, class Rep2, class Period2>
3235 bool operator<=(const __duration<Rep1, Period1>& lhs,
3236 const __duration<Rep2, Period2>& rhs);
3237
3238 __returns `!(rhs < lhs)`.
3239
3240 [endsect]
3241 [section:duration__op_gt_1 Non-Member Function `operator>(duration,duration)`]
3242
3243 template <class Rep1, class Period1, class Rep2, class Period2>
3244 bool operator> (const __duration<Rep1, Period1>& lhs,
3245 const __duration<Rep2, Period2>& rhs);
3246
3247 __returns `rhs < lhs`.
3248
3249 [endsect]
3250 [section:duration__op_geq_1 Non-Member Function `operator>=(duration,duration)`]
3251
3252 template <class Rep1, class Period1, class Rep2, class Period2>
3253 bool operator>=(const __duration<Rep1, Period1>& lhs,
3254 const __duration<Rep2, Period2>& rhs);
3255
3256 __returns `!(lhs < rhs)`.
3257
3258 [endsect]
3259 [endsect]
3260 [section:duration_cast Non-Member Function `duration_cast(duration)`]
3261
3262 template <class __ToDuration, class Rep, class Period>
3263 __ToDuration duration_cast(const __duration<Rep, Period>& d);
3264
3265 __requires This function will not participate in overload resolution unless `ToDuration` is an instantiation of __duration.
3266
3267 __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`.
3268
3269 * If `CF::num == 1` and `CF::den == 1`, then returns `ToDuration(static_cast<typename ToDuration::rep>(d.count())) `
3270 * else if `CF::num != 1` and `CF::den == 1`, then returns
3271 `ToDuration(static_cast<typename ToDuration::rep>(static_cast<CR>(d.count()) *
3272 static_cast<CR>(CF::num)))`
3273 * else if `CF::num == 1` and `CF::den != 1`, then returns
3274 `ToDuration(static_cast<typename ToDuration::rep>(static_cast<CR>(d.count()) /
3275 static_cast<CR>(CF::den)))`
3276 * else returns
3277 `ToDuration(static_cast<typename ToDuration::rep>(static_cast<CR>(d.count()) *
3278 static_cast<CR>(CF::num) /
3279 static_cast<CR>(CF::den)))`
3280
3281 __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.
3282
3283
3284 [endsect]
3285
3286
3287 [section:duration_typedefs `duration` typedefs]
3288
3289 // convenience typedefs
3290 typedef __duration<boost::int_least64_t, nano> nanoseconds; // at least 64 bits needed
3291 typedef __duration<boost::int_least64_t, micro> microseconds; // at least 55 bits needed
3292 typedef __duration<boost::int_least64_t, milli> milliseconds; // at least 45 bits needed
3293 typedef __duration<boost::int_least64_t> seconds; // at least 35 bits needed
3294 typedef __duration<boost::int_least32_t, __ratio< 60> > minutes; // at least 29 bits needed
3295 typedef __duration<boost::int_least32_t, __ratio<3600> > hours; // at least 23 bits needed
3296
3297 [endsect]
3298
3299 [endsect]
3300
3301 [section:clock `Clock` Requirements]
3302
3303 A clock represents a bundle consisting of a __duration, a __time_point, and a function `now()` to get the current __time_point. A clock must meet the requirements in the following Table.
3304
3305 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 occur before `C1::time_point::max()`.
3306 (note This means C1 did not wrap around between t1 and t2.).
3307
3308 [table Clock Requirements
3309 [[expression] [return type] [operational semantics]]
3310 [[`C1::rep`] [An arithmetic type or class emulating an arithmetic type. ] [The representation type of the __duration and __time_point.]]
3311 [[`C1::period`] [`ratio`] [The tick period of the clock in seconds.]]
3312 [[`C1::duration`] [`chrono::duration<C1::rep, C1::period>`] [The __duration type of the `clock`.]]
3313 [[`C1::time_point`] [`chrono::time_point<C1> or chrono::time_point<C2, C1::duration>`] [The __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 __durations. `C1` and `C2` must refer to the same epoch.]]
3314 [[`C1::is_steady`] [`constexpr bool`] [`true` if `t1 <= t2` is always `true`, else `false`. *Note*: A `clock` that can be adjusted backwards is not steady]]
3315 [[`C1::now()`] [`C1::time_point`] [Returns a __time_point representing the current point in time.]]
3316 ]
3317
3318 Models of __Clock:
3319
3320 * __system_clock
3321 * __steady_clock
3322 * __high_resolution_clock
3323 * __process_real_cpu_clock
3324 * __process_user_cpu_clock
3325 * __process_system_cpu_clock
3326 * __process_cpu_clock
3327 * __thread_clock
3328
3329 [endsect]
3330
3331 [section:trivial_clock `TrivialClock` Requirements]
3332
3333 A type `TC` meets the `TrivialClock` requirements if:
3334
3335 * `TC` satisfies the `Clock` requirements,
3336 * the types `TC::rep`, `TC::duration`, and `TC::time_point` satisfy the requirements of `EqualityComparable`, `LessThanComparable`, `DefaultConstructible`, `CopyConstructible`, `CopyAssignable`, `Destructible`, and the requirements of numeric types.
3337
3338 [note This means, in particular, that operations on these types will not throw exceptions.]
3339
3340 * lvalues of the types `TC::rep`, `TC::duration`, and `TC::time_point` are swappable,
3341 * the function `TC::now()` does not throw exceptions and it is thread-safe, and
3342 * the type `TC::time_point::clock` meets the `TrivialClock` requirements, recursively.
3343
3344 Models of __TrivialClock:
3345
3346 * __system_clock
3347 * __steady_clock
3348 * __high_resolution_clock
3349 * __process_real_cpu_clock
3350 * __process_user_cpu_clock
3351 * __process_system_cpu_clock
3352 * __thread_clock
3353
3354 [endsect]
3355
3356 [section:ecclock `EcClock` Requirements]
3357
3358 A type `EcC` meets the `EcClock` requirements if
3359
3360 * `TC` satisfies the `TrivialClock ` requirements, and
3361 * it adds `now()` interfaces allowing to recover internal error codes as described in the following table.
3362 * the added now() function is thread-safe.
3363
3364 In this table `C1` denotes a `EcClock` type and `ec` is an instance of a `boost::system::error_code`.
3365
3366 [table Clock Requirements
3367 [[expression] [return type] [operational semantics]]
3368 [[`C1::now(ec)`] [`C1::time_point`] [Returns a __time_point representing the current point in time. `ec` will stores the error-code in case something was wrong internally.]]
3369 [[`C1::now(boost::throws())`] [`C1::time_point`] [Returns a __time_point representing the current point in time.
3370 Throws a `boost::system::system_error` exception in case something was wrong internally.]]
3371 ]
3372
3373 Models of __Clock:
3374
3375 * __system_clock
3376 * __steady_clock
3377 * __high_resolution_clock
3378 * __process_real_cpu_clock
3379 * __process_user_cpu_clock
3380 * __process_system_cpu_clock
3381 * __process_cpu_clock
3382 * __thread_clock
3383
3384 [endsect]
3385
3386
3387 [/=============================================]
3388 [section:time_point_hpp Header `<boost/chrono/time_point.hpp>`]
3389 [/=============================================]
3390
3391 This file contains __time_point specific classes and non-member functions.
3392
3393 namespace boost {
3394 namespace chrono {
3395
3396 template <class __Clock, class __Duration = typename Clock::duration>
3397 class __time_point;
3398
3399 }
3400 template <class __Clock, class __Duration1, class __Duration2>
3401 struct __common_type_spe<time_point<Clock, Duration1>,
3402 time_point<Clock, Duration2> >;
3403
3404 namespace chrono {
3405
3406 // time_point arithmetic
3407 template <class __Clock, class __Duration1, class Rep2, class Period2>
3408 constexpr time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
3409 __time_point__op_plus_1(const time_point<Clock, Duration1>& lhs,
3410 const duration<Rep2, Period2>& rhs);
3411
3412 template <class Rep1, class Period1, class __Clock, class __Duration2>
3413 constexpr time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
3414 __time_point__op_plus_2(const duration<Rep1, Period1>& lhs,
3415 const time_point<Clock, Duration2>& rhs);
3416
3417 template <class __Clock, class __Duration1, class Rep2, class Period2>
3418 constexpr time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
3419 __time_point__op_minus_1(const time_point<Clock, Duration1>& lhs,
3420 const duration<Rep2, Period2>& rhs);
3421
3422 template <class __Clock, class __Duration1, class __Duration2>
3423 constexpr typename common_type<Duration1, Duration2>::type
3424 __time_point__op_minus_2(const time_point<Clock, Duration1>& lhs,
3425 const time_point<Clock, Duration2>& rhs);
3426
3427 // time_point comparisons
3428 template <class __Clock, class __Duration1, class __Duration2>
3429 constexpr bool
3430 __time_point__op_eq(const time_point<Clock, Duration1>& lhs,
3431 const time_point<Clock, Duration2>& rhs);
3432 template <class __Clock, class __Duration1, class __Duration2>
3433 constexpr bool
3434 __time_point__op_neq(const time_point<Clock, Duration1>& lhs,
3435 const time_point<Clock, Duration2>& rhs);
3436 template <class __Clock, class __Duration1, class __Duration2>
3437 constexpr bool
3438 __time_point__op_lt(const time_point<Clock, Duration1>& lhs,
3439 const time_point<Clock, Duration2>& rhs);
3440 template <class __Clock, class __Duration1, class __Duration2>
3441 constexpr bool
3442 __time_point__op_leq(const time_point<Clock, Duration1>& lhs,
3443 const time_point<Clock, Duration2>& rhs);
3444 template <class __Clock, class __Duration1, class __Duration2>
3445 constexpr bool
3446 __time_point__op_gt(const time_point<Clock, Duration1>& lhs,
3447 const time_point<Clock, Duration2>& rhs);
3448 template <class __Clock, class __Duration1, class __Duration2>
3449 constexpr bool
3450 __time_point__op_geq(const time_point<Clock, Duration1>& lhs,
3451 const time_point<Clock, Duration2>& rhs);
3452
3453 // time_point_cast
3454 template <class __ToDuration, class __Clock, class __Duration>
3455 constexpr time_point<Clock, ToDuration>
3456 __time_point_cast(const time_point<Clock, Duration>& t);
3457
3458 }
3459 }
3460
3461
3462 [section:common_type_spe2 `common_type` specialization]
3463
3464 template <class __Clock, class __Duration1, class __Duration2>
3465 struct __common_type<chrono::__time_point<__Clock, __Duration1>, chrono::__time_point<__Clock, __Duration2> >
3466 {
3467 typedef chrono::__time_point<__Clock, typename __common_type<Duration1, __Duration2>::type> type;
3468 };
3469
3470 The __common_type of two __time_points is a __time_point with the same __Clock (both have the same __Clock), and the __common_type of the two __durations.
3471
3472 [endsect]
3473
3474 [section:time_point Class template `time_point<>`]
3475
3476 A __time_point represents a point in time with respect to a specific clock.
3477
3478 template <class __Clock, class __Duration>
3479 class time_point {
3480 public:
3481 typedef Clock clock;
3482 typedef Duration duration;
3483 typedef typename duration::rep rep;
3484 typedef typename duration::period period;
3485 private:
3486 duration d_; // exposition only
3487 public:
3488 constexpr __time_point__c_1();
3489
3490 constexpr explicit __time_point__c_2(const duration& d);
3491
3492 // conversions
3493 template <class __Duration2>
3494 constexpr
3495 __time_point__c_3(const time_point<clock, __Duration2>& t);
3496
3497 // observer
3498 constexpr duration __time_point__time_since_epoch() const;
3499
3500 // arithmetic
3501
3502 #ifdef BOOST_CHRONO_EXTENSIONS
3503 constexpr time_point __time_point__op_unary_plus();
3504 constexpr time_point __time_point__op_unary_minus();
3505 time_point& __time_point__op_pre_inc();
3506 time_point __time_point__op_post_inc(int);
3507 time_point& __time_point__op_pre_dec();
3508 time_point __time_point__op_post_dec(int);
3509
3510 time_point& __time_point__op_plus_eq_1(const rep& d);
3511 time_point& __time_point__op_minus_eq_1(const rep& d);
3512 #endif
3513
3514 time_point& __time_point__op_plus_eq_2(const duration& d);
3515 time_point& __time_point__op_minus_eq_2(const duration& d);
3516
3517 // special values
3518
3519 static constexpr time_point __time_point__min();
3520 static constexpr time_point __time_point__max();
3521 };
3522
3523 Clock must meet the __clock_req.
3524
3525 Duration must be an instantiation of __duration, compile diagnostic otherwise.
3526
3527 [section:time_point_c_1 Constructor `time_point()`]
3528
3529 constexpr time_point();
3530
3531 __effects Constructs an object of __time_point, initializing `d_` with `duration::zero()`. This __time_point represents the epoch.
3532
3533 [endsect]
3534 [section:time_point_c_2 Constructor `time_point(const duration&)`]
3535
3536 constexpr time_point(const duration& d);
3537
3538 __effects Constructs an object of __time_point, initializing `d_` with `d`. This __time_point represents the epoch `+ d`.
3539
3540 [endsect]
3541 [section:time_point_c_3 Copy Constructor `time_point(const time_point&)`]
3542
3543 template <class __Duration2>
3544 constexpr
3545 time_point(const __time_point<clock, __Duration2>& t);
3546
3547 __requires This function will not participate in overload resolution unless `Duration2` is implicitly convertible to __duration.
3548
3549 __effects Constructs an object of __time_point, initializing `d_` with `t.time_since_epoch()`.
3550
3551 [endsect]
3552
3553 [section:time_since_epoch Member Function `time_since_epoch() const`]
3554
3555 constexpr duration time_since_epoch() const;
3556
3557 __returns `d_`.
3558
3559 [endsect]
3560
3561 [section:op_unary_plus Member Function `operator+() const`]
3562
3563 constexpr __time_point operator+() const;
3564
3565 __returns `*this`.
3566
3567 [endsect]
3568 [section:op_unary_minus Member Function `operator-() const`]
3569
3570 constexpr __time_point operator-() const;
3571
3572 __returns `__time_point(-d_)`.
3573
3574 [endsect]
3575 [section:op_pre_inc Member Function `operator++()`]
3576
3577 __time_point& operator++();
3578
3579 __effects `++d_`.
3580
3581 __returns `*this`.
3582
3583 [endsect]
3584 [section:op_post_inc Member Function `operator++(int)`]
3585
3586 __time_point operator++(int);
3587
3588 __returns `__time_point(d_++)`.
3589
3590 [endsect]
3591 [section:op_pre_dec Member Function `operator--()`]
3592
3593 __time_point& operator--();
3594
3595 __effects `--d_`.
3596
3597 __returns `*this`.
3598
3599 [endsect]
3600 [section:op_post_dec Member Function `operator--(int)`]
3601
3602 __time_point operator--(int);
3603
3604 __returns `__time_point(d_--)`.
3605
3606 [endsect]
3607
3608 [section:op_plus_eq_1 Member Function `operator+=(const rep&)`]
3609
3610 __time_point& operator+=(const rep& r);
3611
3612 __effects `d_ += duration(r)`.
3613
3614 __returns `*this`.
3615
3616 [endsect]
3617 [section:op_minus_eq_1 Member Function `operator-=(const rep&)`]
3618
3619 __time_point& operator-=(const rep& r);
3620
3621 __effects `d_ -= duration(r)`
3622
3623 __returns `*this`.
3624
3625 [endsect]
3626
3627
3628 [section:op_plus_eq_2 Member Function `operator+=`]
3629
3630 time_point& operator+=(const duration& d);
3631
3632 __effects `d_ += d`.
3633
3634 __returns `*this`.
3635
3636 [endsect]
3637 [section:op_minus_eq_2 Member Function `operator-=`]
3638
3639 time_point& operator-=(const duration& d);
3640
3641 __effects `d_ -= d`
3642
3643 __returns `*this`.
3644
3645 [endsect]
3646 [section:min Static Member Function `min`]
3647
3648 static constexpr time_point min();
3649
3650 __returns `time_point(duration::min())`.
3651
3652 [endsect]
3653 [section:max Static Member Function `max`]
3654
3655 static constexpr time_point max();
3656
3657 __returns `time_point(duration::max())`.
3658
3659 [endsect]
3660 [endsect]
3661
3662
3663 [section:arith `time_point` non-member arithmetic]
3664
3665
3666 [section:time_point__op_plus_1 Non-Member Function `operator+(time_point,duration)`]
3667
3668 template <class __Clock, class __Duration1, class Rep2, class Period2>
3669 constexpr
3670 __time_point<__Clock, typename __common_type<Duration1, duration<Rep2, Period2> >::type>
3671 operator+(const __time_point<__Clock, __Duration1>& lhs,
3672 const duration<Rep2, Period2>& rhs);
3673
3674 __returns `CT(lhs.time_since_epoch() + rhs)` where `CT` is the type of the return value.
3675
3676 [endsect]
3677 [section:time_point__op_plus_2 Non-Member Function `operator+(duration,time_point)`]
3678
3679 template <class Rep1, class Period1, class __Clock, class __Duration2>
3680 constexpr
3681 __time_point<__Clock, typename __common_type<duration<Rep1, Period1>, __Duration2>::type>
3682 operator+(const duration<Rep1, Period1>& lhs,
3683 const __time_point<__Clock, __Duration2>& rhs);
3684
3685 __returns `rhs + lhs`.
3686
3687 [endsect]
3688 [section:time_point__op_minus_1 Non-Member Function `operator-(time_point,duration)`]
3689
3690 template <class __Clock, class __Duration1, class Rep2, class Period2>
3691 constexpr
3692 __time_point<__Clock, typename __common_type<Duration1, duration<Rep2, Period2> >::type>
3693 operator-(const __time_point<__Clock, __Duration1>& lhs,
3694 const duration<Rep2, Period2>& rhs);
3695
3696 __returns `lhs + (-rhs)`.
3697
3698 [endsect]
3699 [section:time_point__op_minus_2 Non-Member Function `operator-(time_point,time_point)`]
3700
3701 template <class __Clock, class __Duration1, class __Duration2>
3702 constexpr
3703 typename __common_type<Duration1, __Duration2>::type
3704 operator-(const __time_point<__Clock, __Duration1>& lhs,
3705 const __time_point<__Clock, __Duration2>& rhs);
3706
3707 __returns `lhs.time_since_epoch() - rhs.time_since_epoch()`.
3708
3709 [endsect]
3710 [endsect]
3711
3712 [section:cmp `time_point` non-member comparisons]
3713 [section:time_point__op_eq Non-Member Function `operator==(time_point,time_point)`]
3714
3715 template <class __Clock, class __Duration1, class __Duration2>
3716 constexpr
3717 bool operator==(const __time_point<__Clock, __Duration1>& lhs,
3718 const __time_point<__Clock, __Duration2>& rhs);
3719
3720 __returns `lhs.time_since_epoch() == rhs.time_since_epoch()`.
3721
3722 [endsect]
3723 [section:time_point__op_neq Non-Member Function `operator!=(time_point,time_point)`]
3724
3725 template <class __Clock, class __Duration1, class __Duration2>
3726 constexpr
3727 bool operator!=(const __time_point<__Clock, __Duration1>& lhs,
3728 const __time_point<__Clock, __Duration2>& rhs);
3729
3730 __returns `!(lhs == rhs)`.
3731
3732 [endsect]
3733 [section:time_point__op_lt Non-Member Function `operator<(time_point,time_point)`]
3734
3735 template <class __Clock, class __Duration1, class __Duration2>
3736 constexpr
3737 bool operator< (const __time_point<__Clock, __Duration1>& lhs,
3738 const __time_point<__Clock, __Duration2>& rhs);
3739
3740 __returns lhs.time_since_epoch() < rhs.time_since_epoch().
3741
3742 [endsect]
3743 [section:time_point__op_leq Non-Member Function `operator<=(time_point,time_point)`]
3744
3745 template <class __Clock, class __Duration1, class __Duration2>
3746 constexpr
3747 bool operator<=(const __time_point<__Clock, __Duration1>& lhs,
3748 const __time_point<__Clock, __Duration2>& rhs);
3749
3750 __returns `!(rhs < lhs)`.
3751
3752 [endsect]
3753 [section:time_point__op_gt Non-Member Function `operator>(time_point,time_point)`]
3754
3755 template <class __Clock, class __Duration1, class __Duration2>
3756 constexpr
3757 bool operator>(const __time_point<__Clock, __Duration1>& lhs,
3758 const __time_point<__Clock, __Duration2>& rhs);
3759
3760 __returns `rhs < lhs`.
3761
3762 [endsect]
3763 [section:time_point__op_geq Non-Member Function `operator>=(time_point,time_point)`]
3764
3765 template <class __Clock, class __Duration1, class __Duration2>
3766 constexpr
3767 bool operator>=(const __time_point<__Clock, __Duration1>& lhs,
3768 const __time_point<__Clock, __Duration2>& rhs);
3769
3770 __returns `!(lhs < rhs)`.
3771
3772 [endsect]
3773 [endsect]
3774
3775
3776 [section:time_point_cast Non-Member Function `time_point_cast(time_point)`]
3777
3778 template <class __ToDuration, class __Clock, class __Duration>
3779 constexpr
3780 __time_point<__Clock, ToDuration> __time_point_cast(const __time_point<__Clock, __Duration>& t);
3781
3782 __requires This function will not participate in overload resolution unless `ToDuration` is an instantiation of __duration.
3783
3784 __returns `__time_point<__Clock, ToDuration>(__duration_cast<ToDuration>(t.time_since_epoch()))`.
3785
3786 [endsect]
3787
3788 [endsect]
3789
3790 [/=============================================]
3791 [section:system_clocks_hpp Header `<boost/chrono/system_clocks.hpp>`]
3792 [/=============================================]
3793
3794 This file contains the standard clock classes. The types defined in this section satisfy the __TrivialClock requirements
3795
3796 namespace boost {
3797 namespace chrono {
3798
3799 // Clocks
3800 class __system_clock;
3801 class __steady_clock;
3802 class __high_resolution_clock;
3803
3804 template <class CharT>
3805 struct clock_string<system_clock, CharT>;
3806 template <class CharT>
3807 struct clock_string<steady_clock, CharT>;
3808
3809 }
3810 }
3811
3812
3813 [section:system_clock Class `system_clock`]
3814
3815 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::from_time_t()` functions. If system clock is not steady, 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).
3816
3817 The current implementation of __system_clock is related an epoch (midnight UTC of January 1, 1970), but this is not in the contract. You need to use the static function static
3818
3819 std::time_t to_time_t(const time_point& t);
3820
3821 which returns a `time_t` type that is based on midnight UTC of January 1, 1970.
3822
3823 class system_clock {
3824 public:
3825 typedef __see_bellow__ duration;
3826 typedef duration::rep rep;
3827 typedef duration::period period;
3828 typedef chrono::__time_point<system_clock> time_point;
3829 static constexpr bool is_steady = false;
3830
3831
3832 static time_point now() noexcept;
3833 static time_point now(system::error_code & ec);
3834
3835 // Map to C API
3836 static std::time_t to_time_t(const time_point& t) noexcept;
3837 static time_point from_time_t(std::time_t t) noexcept;
3838 };
3839
3840 __system_clock satisfy the __clock_req:
3841
3842 * `system_clock::duration::min() < system_clock::duration::zero()` is `true`.
3843
3844 * The nested `duration` typedef has a resolution that depends on the one provided by the platform.
3845
3846 [section:to_time_t Static Member Function `to_time_t(time_point)`]
3847
3848 time_t to_time_t(const time_point& t) noexcept;
3849
3850 __returns A `time_t` such that the `time_t` and `t` represent the same point in time, truncated to the coarser of the precisions among `time_t` and `time_point`.
3851
3852 [endsect]
3853 [section:from_time_t Static Member Function `from_time_t(time_t)`]
3854
3855 time_point from_time_t(time_t t) noexcept;
3856
3857 __returns A __time_point such that the __time_point and `t` represent the same point in time, truncated to the coarser of the precisions among __time_point and `time_t`.
3858
3859 [endsect]
3860 [endsect]
3861
3862 [section:BOOST_CHRONO_HAS_CLOCK_STEADY Macro `BOOST_CHRONO_HAS_CLOCK_STEADY`]
3863
3864 Defined if the platform support steady clocks.
3865
3866 [endsect]
3867
3868 [section:steady_clock Class `steady_clock`]
3869
3870 __steady_clock satisfy the __clock_req.
3871
3872 __steady_clock class provides access to the system-wide steady clock. The current time can be obtained by calling `steady_clock::now()`. There is no fixed relationship between values returned by `steady_clock::now()` and wall-clock time.
3873
3874 #ifdef BOOST_HAS_CLOCK_STEADY
3875 class steady_clock {
3876 public:
3877 typedef __nanoseconds duration;
3878 typedef duration::rep rep;
3879 typedef duration::period period;
3880 typedef chrono::__time_point<steady_clock> time_point;
3881 static constexpr bool is_steady = true;
3882
3883 static time_point now() noexcept;
3884 static time_point now(system::error_code & ec);
3885 };
3886 #endif
3887
3888 [endsect]
3889
3890 [section:high_resolution_clock Class `high_resolution_clock`]
3891
3892 __high_resolution_clock satisfy the __clock_req.
3893
3894 #ifdef __BOOST_CHRONO_HAS_CLOCK_STEADY
3895 typedef __steady_clock high_resolution_clock; // as permitted by [time.clock.hires]
3896 #else
3897 typedef __system_clock high_resolution_clock; // as permitted by [time.clock.hires]
3898 #endif
3899
3900 [endsect]
3901
3902 [section:clock_string_system_clock `clock_string<system_clock>` Specialization]
3903
3904 template <class CharT>
3905 struct clock_string<system_clock, CharT>
3906 {
3907 static std::basic_string<CharT> name();
3908 static std::basic_string<CharT> since();
3909 };
3910
3911 `clock_string<>::name()` returns "system_clock".
3912
3913 `clock_string<>::since()` returns " since Jan 1, 1970"
3914
3915
3916 [endsect]
3917
3918 [section:clock_string_steady_clock `clock_string<steady_clock>` Specialization]
3919
3920 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
3921
3922 template <class CharT>
3923 struct clock_string<steady_clock, CharT>
3924 {
3925 static std::basic_string<CharT> name();
3926 static std::basic_string<CharT> since();
3927 };
3928 #endif
3929
3930 `clock_string<>::name()` returns "steady_clock".
3931
3932 `clock_string<>::since()` returns " since boot"
3933
3934 [endsect]
3935
3936 [endsect]
3937
3938 [/==================================================================]
3939 [section:clock_strings_hpp Header `<boost/chrono/clock_strings.hpp>`]
3940 [/==================================================================]
3941
3942 namespace boost {
3943 namespace chrono {
3944
3945 template <class __Clock, class CharT>
3946 struct clock_string;
3947
3948 }
3949 }
3950
3951 [section:clock_string Template Class `clock_string<>`]
3952
3953 template <class __Clock, class CharT>
3954 struct clock_string;
3955
3956 This template must be specialized for specific clocks. The specialization must define the following functions
3957
3958 static std::basic_string<CharT> name();
3959 static std::basic_string<CharT> since();
3960
3961 `clock_string<>::name()` return the clock name, which usually corresponds to the class name.
3962
3963 `clock_string<>::since()` return the textual format of the clock epoch.
3964
3965
3966 [endsect]
3967
3968 [endsect] [/section:clock_strings_hpp Header `<boost/chrono/clock_strings.hpp>`]
3969
3970 [/=============================================]
3971 [section:chrono_typeof_hpp Header `<boost/chrono/typeof/boost/chrono/chrono.hpp>`]
3972 [/=============================================]
3973
3974 Register __duration`<>` and __time_point`<>` class templates to [*Boost.Typeof].
3975
3976 [endsect]
3977 [endsect]
3978
3979 [section:io_v1 Chrono I/O V1]
3980 [/==================================================================]
3981 [section:chrono_io_hpp Header `<boost/chrono/chrono_io.hpp>`]
3982 [/==================================================================]
3983
3984
3985
3986 namespace boost {
3987 namespace chrono {
3988
3989 template <class CharT>
3990 class duration_punct;
3991
3992 template <class CharT, class Traits>
3993 std::basic_ostream<CharT, Traits>&
3994 duration_short(std::basic_ostream<CharT, Traits>& os);
3995
3996 template <class CharT, class Traits>
3997 std::basic_ostream<CharT, Traits>&
3998 duration_long(std::basic_ostream<CharT, Traits>& os);
3999
4000 template <class CharT, class Traits, class Rep, class Period>
4001 std::basic_ostream<CharT, Traits>&
4002 operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep, Period>& d);
4003
4004 template <class CharT, class Traits, class Rep, class Period>
4005 std::basic_istream<CharT, Traits>&
4006 operator>>(std::basic_istream<CharT, Traits>& is, duration<Rep, Period>& d)
4007
4008 template <class CharT, class Traits, class Clock, class Duration>
4009 std::basic_ostream<CharT, Traits>&
4010 operator<<(std::basic_ostream<CharT, Traits>& os,
4011 const time_point<Clock, Duration>& tp);
4012
4013 template <class CharT, class Traits, class Clock, class Duration>
4014 std::basic_istream<CharT, Traits>&
4015 operator>>(std::basic_istream<CharT, Traits>& is,
4016 time_point<Clock, Duration>& tp);
4017
4018 }
4019 }
4020
4021 [section:duration_punct Template Class `duration_punct<>`]
4022
4023 The __duration unit names can be customized through the facet: __duration_punct. __duration unit names come in two varieties: long and short. The default constructed __duration_punct provides names in the long format. These names are English descriptions. Other languages are supported by constructing a __duration_punct with the proper spellings for "hours", "minutes" and "seconds", and their abbreviations (for the short format).
4024
4025 template <class CharT>
4026 class duration_punct
4027 : public std::locale::facet
4028 {
4029 public:
4030 typedef std::basic_string<CharT> string_type;
4031 enum {use_long, use_short};
4032
4033 static std::locale::id id;
4034
4035 explicit duration_punct(int use = use_long);
4036
4037 duration_punct(int use,
4038 const string_type& long_seconds, const string_type& long_minutes,
4039 const string_type& long_hours, const string_type& short_seconds,
4040 const string_type& short_minutes, const string_type& short_hours);
4041
4042 duration_punct(int use, const duration_punct& d);
4043
4044 template <class Period> string_type short_name() const;
4045 template <class Period> string_type long_name() const;
4046 template <class Period> string_type name() const;
4047
4048 bool is_short_name() const;
4049 bool is_long_name() const;
4050 };
4051
4052 [endsect]
4053
4054 [section:manipulators I/O Manipulators]
4055
4056 The short or long format can be easily chosen by streaming a `duration_short` or `duration_long` manipulator respectively.
4057
4058 template <class CharT, class Traits>
4059 std::basic_ostream<CharT, Traits>&
4060 duration_short(std::basic_ostream<CharT, Traits>& os);
4061
4062 __effects Set the __duration_punct facet to stream __durations and __time_points as abbreviations.
4063
4064 __returns the output stream
4065
4066 template <class CharT, class Traits>
4067 std::basic_ostream<CharT, Traits>&
4068 duration_long(std::basic_ostream<CharT, Traits>& os);
4069
4070
4071 __effects Set the __duration_punct facet to stream durations and time_points as long text.
4072
4073 __returns the output stream
4074
4075
4076 [endsect]
4077
4078 [section:streams I/O Streams Operations]
4079
4080 Any __duration can be streamed out to a `basic_ostream`. The run-time value of the __duration is formatted according to the rules and current format settings for __duration`::rep`. This is followed by a single space and then the compile-time unit name of the __duration. This unit name is built on the string returned from `ratio_string<>` and the data used to construct the __duration_punct which was inserted into the stream's locale. If a __duration_punct has not been inserted into the stream's locale, a default constructed __duration_punct will be added to the stream's locale.
4081
4082 A __time_point is formatted by outputting its internal __duration followed by a string that describes the __time_point`::clock` epoch. This string will vary for each distinct clock, and for each implementation of the supplied clocks.
4083
4084 template <class CharT, class Traits, class Rep, class Period>
4085 std::basic_ostream<CharT, Traits>&
4086 operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep, Period>& d);
4087
4088 __effects outputs the __duration as an abbreviated or long text format depending on the state of the __duration_punct facet.
4089
4090 __returns the output stream
4091
4092 template <class CharT, class Traits, class Rep, class Period>
4093 std::basic_istream<CharT, Traits>&
4094 operator>>(std::basic_istream<CharT, Traits>& is, duration<Rep, Period>& d)
4095
4096 __effects reads a __duration from the input stream. If a format error is found, the input stream state will be set to `failbit`.
4097
4098 __returns the input stream
4099
4100 template <class CharT, class Traits, class Clock, class Duration>
4101 std::basic_ostream<CharT, Traits>&
4102 operator<<(std::basic_ostream<CharT, Traits>& os,
4103 const time_point<Clock, Duration>& tp);
4104
4105 __effects outputs the __time_point as an abbreviated or long text format depending on the state of the __duration_punct facet.
4106
4107 __returns the output stream
4108
4109
4110 template <class CharT, class Traits, class Clock, class Duration>
4111 std::basic_istream<CharT, Traits>&
4112 operator>>(std::basic_istream<CharT, Traits>& is,
4113 time_point<Clock, Duration>& tp);
4114
4115 __effects reads a __time_point from the input stream. If a format error is found, the input stream state will be set to `failbit`.
4116
4117 __returns the input stream
4118
4119 [endsect]
4120
4121
4122 [endsect]
4123 [endsect]
4124
4125 [section:io Chrono I/O V2]
4126
4127 [/==================================================================]
4128 [section:chrono_io_hpp Header `<boost/chrono/chrono_io.hpp>`]
4129 [/==================================================================]
4130
4131
4132 This file includes the i/o of the two major components, duration and time_point.
4133
4134 #include <boost/chrono/io/duration_style.hpp>
4135 #include <boost/chrono/io/timezone.hpp>
4136 #include <boost/chrono/io/ios_base_state.hpp>
4137 #include <boost/chrono/io/duration_get.hpp>
4138 #include <boost/chrono/io/duration_put.hpp>
4139 #include <boost/chrono/io/duration_units.hpp>
4140 #include <boost/chrono/io/duration_io.hpp>
4141 #include <boost/chrono/io/time_point_get.hpp>
4142 #include <boost/chrono/io/time_point_put.hpp>
4143 #include <boost/chrono/io/time_point_units.hpp>
4144 #include <boost/chrono/io/time_point_io.hpp>
4145
4146
4147 [endsect] [/section:chrono_io_hpp Header `<boost/chrono/chrono_io.hpp>`]
4148
4149 [/==================================================================]
4150 [section:duration_style_hpp Header `<boost/chrono/io/duration_style.hpp>`]
4151 [/==================================================================]
4152
4153
4154 namespace boost {
4155 namespace chrono {
4156
4157 // typedefs
4158 enum class __duration_style {
4159 __prefix, __symbol
4160 };
4161 }
4162 }
4163
4164 [section:duration_style Scoped enum `duration_style`]
4165
4166 enum class duration_style {
4167 prefix, symbol
4168 };
4169
4170 __duration unit names come in two varieties: prefix and symbol.
4171
4172 [endsect] [/section:duration_style Scoped enum `duration_style`]
4173
4174 [endsect] [/section:duration_style_hpp Header `<boost/chrono/io/duration_style.hpp>`]
4175
4176 [/==================================================================]
4177 [section:timezone_hpp Header `<boost/chrono/io/timezone.hpp>`]
4178 [/==================================================================]
4179
4180 namespace boost {
4181 namespace chrono {
4182
4183 struct __timezone
4184 {
4185 enum type {
4186 __utc, __local
4187 };
4188 };
4189 }
4190 }
4191
4192 [section:timezone Scoped enum `timezone`]
4193
4194 enum class timezone {
4195 utc, local
4196 };
4197
4198 [endsect] [/section:timezone Scoped enum `timezone`]
4199
4200
4201 [endsect] [/section:timezone_hpp Header `<boost/chrono/io/timezone.hpp>`]
4202
4203
4204 [/==================================================================]
4205 [section:ios_state_hpp Header `<boost/chrono/io/ios_base_state.hpp>`]
4206 [/==================================================================]
4207
4208 namespace boost {
4209 namespace chrono {
4210
4211 // setters and getters
4212 duration_style __get_duration_style(std::ios_base & ios);
4213 void __set_duration_style(std::ios_base& ios, duration_style style);
4214
4215 timezone __get_timezone(std::ios_base & ios);
4216 void __set_timezone(std::ios_base& ios, timezone tz);
4217
4218 template<typename CharT>
4219 std::basic_string<CharT> __get_time_fmt(std::ios_base & ios);
4220 template<typename CharT>
4221 void __set_time_fmt(std::ios_base& ios, std::basic_string<CharT> const& fmt);
4222
4223 // i/o state savers
4224 struct __duration_style_io_saver;
4225 template<typename CharT = char, typename Traits = std::char_traits<CharT> >
4226 struct __timezone_io_saver;
4227 template<typename CharT = char, typename Traits = std::char_traits<CharT> >
4228 struct __time_fmt_io_saver;
4229 }
4230 }
4231
4232 [section:sag Setter and getters]
4233
4234 [section:get_duration_style Non Member Function `get_duration_style(std::ios_base &)`]
4235
4236 duration_style get_duration_style(std::ios_base & ios);
4237
4238 __returns The stream's __duration_style attribute associated to `ios`.
4239
4240 [endsect]
4241
4242 [section:set_duration_style Non Member Function `set_duration_style(std::ios_base &,duration_style)`]
4243
4244 void set_duration_style(std::ios_base& ios, duration_style style);
4245
4246 __effects Set the stream's __duration_style attribute associated to `ios` with the `style` parameter.
4247
4248 [endsect]
4249
4250 [section:get_timezone Non Member Function `get_timezone(std::ios_base&)`]
4251
4252 timezone get_timezone(std::ios_base & ios);
4253
4254 __returns The stream's __timezone attribute associated to `ios`.
4255
4256 [endsect]
4257
4258 [section:set_timezone Non Member Function `set_timezone(std::ios_base&,duration_style)`]
4259
4260 void set_timezone(std::ios_base& ios, timezone tz);
4261
4262 __effects Set the stream's __timezone attribute associated to `ios` with the `tz` parameter.
4263
4264 [endsect]
4265
4266 [section:get_time_fmt Non Member Function `get_time_fmt(std::ios_base &)`]
4267
4268 template<typename CharT>
4269 std::basic_string<CharT> get_time_fmt(std::ios_base & ios);
4270
4271 __returns The stream's time format attribute associated to `ios`.
4272
4273 [endsect]
4274
4275 [section:set_time_fmt Non Member Function `set_time_fmt(std::ios_base&, std::basic_string<CharT> const&)`]
4276
4277 template<typename CharT>
4278 void set_time_fmt(std::ios_base& ios, std::basic_string<CharT> const& fmt);
4279
4280 __effects Set the stream's time format attribute associated to `ios` with the `fmt` parameter.
4281
4282 The format is composed of zero or more directives.
4283 Each directive is composed of one of the following:
4284
4285 * one or more white-space characters (as specified by isspace());
4286 * an ordinary character (neither '%' nor a white-space character);
4287 * or a conversion specification.
4288
4289 Each conversion specification is composed of a '%' character followed by a conversion character which specifies the replacement required.
4290 The application shall ensure that there is white-space or other non-alphanumeric characters between any two conversion specifications.
4291 The following conversion specifications are supported:
4292
4293 [table Format tags
4294 [[Format Specifier] [Description ] [Example]]
4295 [[`%%`] [Replaced by `%`.] [.]]
4296 [[`%a %A`] [The day of the week, using the locale's weekday names; either the abbreviated or full name may be specified.] ["Monday".]]
4297 [[`%b %B %h`] [The month, using the locale's month names; either the abbreviated or full name may be specified.] ["February".]]
4298 [[`%c`] [Not supported.] [.]]
4299 [[`%d %e`] [The day of the month `[01,31]`; leading zeros are permitted but not required..] [.]]
4300 [[`%D`] [The date as `%m/%d/%y`.] [.]]
4301 [[`%F`] [The date as `%Y/%m/%d`.] [.]]
4302 [[`%H`] [The hour (24-hour clock) `[00,23]`; leading zeros are permitted but not required.] [.]]
4303 [[`%I`] [The hour (12-hour clock) `[01,12]`; leading zeros are permitted but not required.] [.]]
4304 [[`%j`] [The day number of the year `[001,366]`; leading zeros are permitted but not required.] ["060" => Feb-29.]]
4305 [[`%m`] [The month number `[01,12]`; leading zeros are permitted but not required..] ["01" => January.]]
4306 [[`%M`] [The minute `[00,59]`; leading zeros are permitted but not required.] [.]]
4307 [[`%n %t`] [Any white space..] [.]]
4308 [[`%p`] [Not supported.] [.]]
4309 [[`%r`] [Not supported.] [.]]
4310 [[`%R`] [The time as `%H:%M`.] [.]]
4311 [[`%S`] [The seconds `[00,60]`; leading zeros are permitted but not required.] [.]]
4312 [[`%T`] [The time as `%H:%M:%S`.] [.]]
4313 [[`%U`] [Not supported.] [.]]
4314 [[`%w`] [The weekday as a decimal number `[0,6]`, with 0 representing Sunday; leading zeros are permitted but not required..] ["0" => Sunday.]]
4315 [[`%W`] [Not supported.] [.]]
4316 [[`%x`] [The date, using the locale's date format..] [.]]
4317 [[`%X`] [Not supported.] [.]]
4318 [[`%y`] [Not supported.] ["2005".]]
4319 [[`%Y`] [The year, including the century (for example, 1988).] [.]]
4320 ]
4321
4322
4323 [endsect]
4324
4325 [endsect]
4326 [section:ioss I/O State Savers]
4327 [section:duration_style_io_saver Template Class `duration_style_io_saver`]
4328
4329 // i/o state savers
4330
4331 struct duration_style_io_saver
4332 {
4333 typedef std::ios_base state_type; // the state type is ios_base
4334 typedef __duration_style aspect_type; // the aspect type is the __duration_style
4335
4336 explicit __duration_style_io_saver__c1(state_type &s);
4337 __duration_style_io_saver__c2(state_type &s, aspect_type new_value);
4338 __duration_style_io_saver__d();
4339 void __duration_style_io_saver__restore();
4340 };
4341
4342 The `state_type` is a version of the IOStreams base class `std::ios_base`.
4343
4344 [section:c1 Constructor `duration_style_io_saver(state_type&)`]
4345
4346 This constructor takes a stream object and saves a reference to the stream and
4347 the current value of a particular stream attribute.
4348
4349 explicit duration_style_io_saver(state_type &s);
4350
4351 __effects Constructs a __duration_style_io_saver by storing `s`.
4352
4353 [endsect]
4354
4355 [section:c2 Constructor `duration_style_io_saver(state_type&, aspect_type)`]
4356
4357 This constructor works like the previous one, and in addition
4358 uses its second argument to change the stream's attribute to the new `aspect_type` value given.
4359
4360 explicit duration_style_io_saver(state_type &s, aspect_type new_value);
4361
4362 __effects Constructs a __duration_style_io_saver by storing `s`. Sets the `state_type` `aspect_type` with the value `new_value`.
4363
4364 [endsect]
4365
4366 [section:d Destructor `~duration_style_io_saver()`]
4367
4368 The destructor restores the stream's attribute to the saved value.
4369
4370 ~duration_style_io_saver();
4371
4372 __effects As if __duration_style_io_saver__restore().
4373
4374 [endsect]
4375 [section:restore Member Function `restore()`]
4376
4377 The restoration can be activated early (and often) with the restore member function.
4378
4379 void restore();
4380
4381 __effects Restores the stream's __duration_style attribute to the saved value.
4382
4383 [endsect]
4384
4385
4386 [endsect]
4387 [section:timezone_io_saver Template Class `timezone_io_saver<>`]
4388
4389
4390 template<typename CharT = char, typename Traits = std::char_traits<CharT> >
4391 struct __timezone_io_saver
4392 {
4393 typedef std::basic_ios<CharT, Traits> state_type;
4394 typedef __timezone aspect_type;
4395
4396 explicit __timezone_io_saver__c1(state_type &s);
4397 __timezone_io_saver__c2(state_type &s, aspect_type new_value);
4398 __timezone_io_saver__d();
4399 void timezone_io_saver__restore();
4400 };
4401
4402
4403 The `state_type` is a version of the IOStreams base class template `std::basic_ios<CharT, Traits>`, where `CharT` is a character type and `Traits` is a character traits class. The user would usually place an actual input, output, or combined stream object for the state-type parameter, and not a base class object.
4404
4405 [section:c1 Constructor `timezone_io_saver(state_type&)`]
4406
4407 This constructor takes a stream object and saves a reference to the stream and the current value of a particular stream attribute.
4408
4409 explicit timezone_io_saver(state_type &s);
4410
4411 __effects Constructs a __timezone_io_saver by storing `s`.
4412
4413 [endsect]
4414
4415 [section:c2 Constructor `timezone_io_saver(state_type&, aspect_type)`]
4416
4417 This constructor works like the previous one, and
4418 uses its second argument to change the stream's attribute to the new aspect_type value given.
4419
4420 explicit timezone_io_saver(state_type &s, aspect_type new_value);
4421
4422 __effects Constructs a __timezone_io_saver by storing `s`. Sets the `state_type` `aspect_type` with the value `new_value`.
4423
4424
4425 [endsect]
4426
4427 [section:d Destructor `~timezone_io_saver()`]
4428
4429 The destructor restores the stream's attribute to the saved value.
4430
4431 ~timezone_io_saver();
4432
4433 __effects As if __timezone_io_saver__restore().
4434
4435 [endsect]
4436 [section:restore Member Function `restore()`]
4437
4438 The restoration can be activated early (and often) with the restore member function.
4439
4440 void restore();
4441
4442 __effects Restores the stream's __timezone attribute to the saved value.
4443
4444 [endsect]
4445
4446
4447 [endsect]
4448
4449 [section:time_fmt_io_saver Template Class `time_fmt_io_saver<>`]
4450
4451 template<typename CharT = char, typename Traits = std::char_traits<CharT> >
4452 struct __time_fmt_io_saver
4453 {
4454 typedef std::basic_ios<CharT, Traits> state_type;
4455
4456 explicit __time_fmt_io_saver__c1(state_type &s);
4457 __time_fmt_io_saver__c2(state_type &s, basic_string<CharT> const& new_value);
4458 __time_fmt_io_saver__d();
4459 void __time_fmt_io_saver__restore();
4460 };
4461
4462
4463 The `state_type` is a version of the IOStreams base class template `std::basic_ios<CharT, Traits>`, where `CharT` is a character type and `Traits` is a character traits class. The user would usually place an actual input, output, or combined stream object for the state-type parameter, and not a base class object.
4464
4465 [section:c1 Constructor `time_fmt_io_saver(state_type&)`]
4466
4467 This constructor takes a stream object and saves a reference to the stream and the current value of a particular stream attribute.
4468
4469 explicit time_fmt_io_saver(state_type &s);
4470
4471 __effects Constructs a __time_fmt_io_saver by storing `s`.
4472
4473 [endsect]
4474
4475 [section:c2 Constructor `time_fmt_io_saver(state_type&, aspect_type)`]
4476
4477 This constructor works like the previous one, and
4478 uses its second argument to change the stream's attribute to the new aspect_type value given.
4479
4480 explicit time_fmt_io_saver(state_type &s, aspect_type new_value);
4481
4482 __effects Constructs a __time_fmt_io_saver by storing `s`. Sets the `state_type` `aspect_type` with the value `new_value`.
4483
4484
4485 [endsect]
4486
4487 [section:d Destructor `~time_fmt_io_saver()`]
4488
4489 The destructor restores the stream's attribute to the saved value.
4490
4491 ~time_fmt_io_saver();
4492
4493 __effects As if __time_fmt_io_saver__restore().
4494
4495 [endsect]
4496 [section:restore Member Function `restore()`]
4497
4498 The restoration can be activated early (and often) with the restore member function.
4499
4500 void restore();
4501
4502 __effects Restores the stream's time format attribute to the saved value.
4503
4504 [endsect]
4505
4506 [endsect]
4507 [endsect]
4508
4509 [endsect] [/section:ios_state_hpp Header `<boost/chrono/io/ios_sate.hpp>`]
4510
4511 [/==================================================================]
4512 [section:duration_get_hpp Header `<boost/chrono/io/duration_get.hpp>`]
4513 [/==================================================================]
4514
4515 namespace boost {
4516 namespace chrono {
4517
4518 template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
4519 class __duration_get;
4520
4521 }
4522 }
4523
4524 [section:duration_get Template Class `duration_get`]
4525
4526 template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
4527 class duration_get: public std::locale::facet
4528 {
4529 public:
4530 typedef CharT char_type; // Type of character the facet is instantiated on
4531 typedef std::basic_string<CharT> string_type; // Type of character string passed to member functions.
4532 typedef InputIterator iter_type; // Type of iterator used to scan the character buffer.
4533
4534 explicit __duration_get_c(size_t refs = 0);
4535
4536 template <typename Rep, typename Period>
4537 iter_type __duration_get_get(
4538 iter_type s,
4539 iter_type end,
4540 std::ios_base& ios,
4541 std::ios_base::iostate& err,
4542 duration<Rep, Period>& d,
4543 const char_type* pattern,
4544 const char_type* pat_end
4545 ) const;
4546
4547 template <typename Rep, typename Period>
4548 iter_type __duration_get_get2(
4549 iter_type s,
4550 iter_type end,
4551 std::ios_base& ios,
4552 std::ios_base::iostate& err,
4553 duration<Rep, Period>& d
4554 ) const;
4555
4556 template <typename Rep>
4557 iter_type __duration_get_get_value(
4558 iter_type s,
4559 iter_type end,
4560 std::ios_base& ios,
4561 std::ios_base::iostate& err,
4562 Rep& r
4563 ) const;
4564
4565 iter_type __duration_get_get_unit(
4566 iter_type i,
4567 iter_type e,
4568 std::ios_base& is,
4569 std::ios_base::iostate& err,
4570 detail::rt_ratio &rt
4571 ) const
4572
4573 static std::locale::id id; // Unique identifier for this type of facet.
4574
4575 __duration_get_d()
4576 {
4577 }
4578
4579 };
4580
4581
4582 The __duration_get facet extracts duration from a character string and stores the resulting value in a class
4583 duration d argument. The facet parses the string using a specific format as a guide.
4584 If the string does not fit the format, then the facet will indicate an error by setting the err argument to
4585 iosbase::failbit.
4586 In other words, user confirmation is required for reliable parsing of
4587 user-entered durations, but machine-generated formats can be parsed
4588 reliably. This allows parsers to be aggressive about interpreting user
4589 variations on standard formats.
4590
4591 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4592 [section:c Constructor `duration_get(size_t)`]
4593
4594 explicit duration_get(size_t refs);
4595
4596 Constructs a __duration_get facet.
4597
4598 __params
4599
4600 * [param refs] references
4601
4602 __effects Constructs a __duration_get facet.
4603 If the `refs` argument is `0` then destruction of the object is
4604 delegated to the locale, or locales, containing it. This allows
4605 the user to ignore lifetime management issues. On the other had,
4606 if `refs` is `1` then the object must be explicitly deleted;
4607 `locale` will not do so. In this case, the object can be
4608 maintained across the lifetime of multiple locales.
4609
4610 [endsect]
4611 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4612 [section:d Destructor `~duration_get()`]
4613
4614 ~duration_get();
4615
4616 Destructs a __duration_get facet.
4617
4618 [endsect]
4619 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4620 [section:get Template Member Function `get(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,duration<Rep,Period>&,const char_type*, const char_type*) const`]
4621
4622 template <typename Rep, typename Period>
4623 iter_type get(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err,
4624 duration<Rep, Period> &d, const char_type *pattern, const char_type *pat_end) const;
4625
4626 Extracts a duration from the range `[s,end)` following the pattern `[pattern,pat_end)`.
4627
4628 __params
4629
4630 * [param s] start input stream iterator
4631 * [param end] end input stream iterator
4632 * [param ios] a reference to a ios_base
4633 * [param err] the ios_base state
4634 * [param d] the duration
4635 * [param pattern] begin of the formatting pattern
4636 * [param pat_end] end of the formatting pattern
4637
4638 __requires `[s, end) and [pattern, pat_end)` shall be valid ranges.
4639
4640 __effects The function starts by evaluating `err = std::ios_base::goodbit`.
4641
4642 Then it computes an intermediate representation based on `Rep` according to the following rules:
4643
4644 * If `Rep` is a floating point type, the intermediate representation is `long double`.
4645 * Else if `Rep` is a signed integral type, the intermediate representation is `long long`.
4646 * Else if `Rep` is an unsigned integral type, the intermediate representation is unsigned long long.
4647 * Else intermediate representation is `Rep`.
4648
4649 Next the following local variable `r` of type intermediate representation and `rt` of type `rt_ratio` are default constructed.
4650
4651 It then enters a loop, reading zero or more characters from `s` at
4652 each iteration. Unless otherwise specified below, the loop
4653 terminates when the first of the following conditions holds:
4654
4655 * The expression `pattern == pat_end` evaluates to `true`.
4656 * The expression `err == std::ios_base::goodbit` evaluates to false.
4657 * The expression `s == end` evaluates to `true`, in which case the
4658 function evaluates `err = std::ios_base::eofbit | std::ios_base::failbit`.
4659 * The next element of pattern is equal to `'%'`, followed by a conversion
4660 specifier character, format.
4661 If the number of elements in the range `[pattern,pat_end)` is not
4662 sufficient to unambiguously determine whether the conversion
4663 specification is complete and valid, the function evaluates
4664 `err = std::ios_base::failbit`. Otherwise, the function evaluates
4665 `s = get_value(s, end, ios, err, r)` when the conversion specification is 'v' and
4666 `s = get_value(s, end, ios, err, rt)` when the conversion specification is 'u'.
4667 If `err == std::ios_base::goodbit` holds after
4668 the evaluation of the expression, the function increments pattern to
4669 point just past the end of the conversion specification and continues
4670 looping.
4671 * The expression `isspace(*pattern, ios.getloc())` evaluates to `true`, in
4672 which case the function first increments pattern until
4673 `pattern == pat_end || !isspace(*pattern, ios.getloc())` evaluates to `true`,
4674 then advances `s` until `s == end || !isspace(*s, ios.getloc())` is `true`,
4675 and finally resumes looping.
4676 * The next character read from `s` matches the element pointed to by
4677 pattern in a case-insensitive comparison, in which case the function
4678 evaluates `++pattern, ++s` and continues looping.
4679 Otherwise, the function evaluates `err = std::ios_base::failbit`.
4680
4681 If a duration representation value and a unit specifier have successfully been parsed, compute
4682 `(rt.num/rt.den)/(Period::num/Period::den)` reduced to lowest terms.
4683 If this ratio can not be stored without overflow, evaluates `err = std::ios_base::failbit`.
4684 Otherwise store the result of this division in `num` and `den`.
4685
4686 If the division did not result in overflow, then compute `r * num / den` in such a way as to avoid intermediate overflow.
4687 If `r` has integral type and this computation would not be exact, evaluates `err = std::ios_base::failbit`.
4688 If the result of the computation would overflow `Rep`, evaluates `err = std::ios_base::failbit`.
4689 Otherwise the result of `r * num / den` is used to construct a `duration<Rep, Period>` which is assigned to `d`.
4690
4691 __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid duration.
4692
4693 [endsect]
4694 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4695 [section:get2 Template Member Function `get(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,duration<Rep,Period>&) const`]
4696
4697 template <typename Rep, typename Period>
4698 iter_type get(
4699 iter_type s,
4700 iter_type end,
4701 std::ios_base& ios,
4702 std::ios_base::iostate& err,
4703 duration<Rep, Period>& d
4704 ) const;
4705
4706 Extracts a duration from the range `[s,end)` following the default pattern.
4707
4708 __params
4709
4710 * [param s] start input stream iterator
4711 * [param end] end input stream iterator
4712 * [param ios] a reference to a ios_base
4713 * [param err] the ios_base state
4714 * [param d] the duration
4715
4716
4717 __effects
4718 Stores the duration pattern from the __duration_unit facet associated to 'ios` in let say `str`. Last as if
4719
4720 return get(s, end, ios, err, ios, d, str.data(), str.data() + str.size());
4721
4722 __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid duration.
4723
4724
4725 [endsect]
4726 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4727 [section:get_value Template Member Function `get_value(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,Rep&) const`]
4728
4729 template <typename Rep>
4730 iter_type get_value(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err, Rep& r) const;
4731
4732 Extracts a duration representation from the range `[s,end)`.
4733
4734 __params
4735
4736 * [param s] start input stream iterator
4737 * [param end] end input stream iterator
4738 * [param ios] a reference to a ios_base
4739 * [param err] the ios_base state
4740 * [param r] a reference to the duration representation
4741
4742 __effects As if
4743
4744 return std::use_facet<std::num_get<char_type, iter_type>>(ios.getloc()).get(s, end, ios, err, r);
4745
4746 __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid `Rep` value.
4747
4748 [endsect]
4749 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4750 [section:get_unit Member Function `get_unit(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,rt_ratio&) const`]
4751
4752 iter_type get_unit(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err, detail::rt_ratio &rt) const;
4753
4754 Extracts a duration unit from the range `[s,end)`.
4755
4756 __params
4757
4758 * [param s] start input stream iterator
4759 * [param end] end input stream iterator
4760 * [param ios] a reference to a ios_base
4761 * [param err] the ios_base state
4762 * [param rt] a reference to the duration run-time ratio.
4763
4764 __effects
4765
4766 * If the first character is `'['`, an attempt is made to consume a pattern of the form
4767 `"[N/D]"` where `N` and `D` have type `unsigned long long`.
4768 * If successful, rt records the values of `N` and `D`, otherwise evaluates `err = std::ios_base::failbit` and return `i`.
4769 * Return the parse the longest string possible matching one of the durations units that can follow the pattern `"[N/D]"`, as if
4770
4771 return do_get_n_d_prefix_unit(facet, i, e, is, err);
4772
4773 * Otherwise the next character is not `'['`. Return the parse the longest string possible matching one of the
4774 durations units, as if
4775
4776 return do_get_prefix_unit(facet, i, e, is, err, rt);
4777
4778 __returns `i`, an iterator pointing just beyond the last character that can be determined to be part of a valid duration unit.
4779
4780 [endsect]
4781 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4782 [section:do_get_n_d_prefix_unit Protected Member Function `do_get_n_d_prefix_unit(duration_units<CharT> const&,iter_type,iter_type,std::ios_base&,std::ios_base::iostate&) const`]
4783
4784 virtual iter_type do_get_n_d_prefix_unit(
4785 duration_units<CharT> const &facet,
4786 iter_type i,
4787 iter_type e,
4788 std::ios_base&,
4789 std::ios_base::iostate& err
4790 ) const;
4791
4792 Extracts the run-time ratio associated to the duration when it is given in [N/D] form.
4793
4794 This is an extension point of this facet so that we can take in account other periods that can have a useful
4795 translation in other contexts, as e.g. days and weeks.
4796
4797 __params
4798
4799 * [param s] start input stream iterator
4800 * [param end] end input stream iterator
4801 * [param ios] a reference to a ios_base
4802 * [param err] the ios_base state
4803 * [param rt] a reference to the duration run-time ratio.
4804
4805
4806 __effects Scan `s` for the longest of all the plural forms associated with the duration units.
4807 If successful, sets the matched ratio in `rt`. Otherwise evaluates `err = std::ios_base::failbit`.
4808
4809 __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid name.
4810
4811 [endsect]
4812 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4813 [section:do_get_prefix_unit Protected Member Function `do_get_prefix_unit(duration_units<CharT> const&,iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,detail::rt_ratio&) const`]
4814
4815 virtual iter_type do_get_prefix_unit(
4816 duration_units<CharT> const &facet,
4817 iter_type i,
4818 iter_type e,
4819 std::ios_base&,
4820 std::ios_base::iostate& err,
4821 detail::rt_ratio &rt
4822 ) const;
4823
4824 Extracts the run-time ratio associated to the duration when it is given in prefix form.
4825
4826 This is an extension point of this facet so that we can take in account other periods that can have a useful
4827 translation in other contexts, as e.g. days and weeks.
4828
4829 __params
4830
4831 * [param s] start input stream iterator
4832 * [param end] end input stream iterator
4833 * [param ios] a reference to a ios_base
4834 * [param err] the ios_base state
4835 * [param rt] a reference to the duration run-time ratio.
4836
4837
4838 __effects Scan `s` for the longest of all the plural forms associated with the duration units.
4839 If successful, sets the matched ratio in `rt`. Otherwise evaluates `err = std::ios_base::failbit`.
4840
4841 __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid name.
4842
4843 [endsect]
4844 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4845
4846 [endsect]
4847
4848 [endsect] [/section:duration_get_hpp]
4849
4850 [/==================================================================]
4851 [section:duration_put_hpp Header `<boost/chrono/io/duration_put.hpp>`]
4852 [/==================================================================]
4853
4854 namespace boost {
4855 namespace chrono {
4856
4857 template <class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
4858 class __duration_put;
4859
4860 }
4861 }
4862
4863 [section:duration_put Template Class `duration_put`]
4864
4865 template <class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
4866 class duration_put: public std::locale::facet
4867 {
4868 public:
4869 typedef CharT char_type; // Type of character the facet is instantiated on.
4870 typedef std::basic_string<CharT> string_type; // Type of character string passed to member functions.
4871 typedef OutputIterator iter_type; // Type of iterator used to write in the character buffer.
4872
4873 explicit __duration_put_c(size_t refs = 0);
4874
4875 template <typename Rep, typename Period>
4876 iter_type __duration_put_put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d, const CharT* pattern,
4877 const CharT* pat_end) const;
4878
4879 template <typename Rep, typename Period>
4880 iter_type __duration_put_put2(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
4881
4882 template <typename Rep, typename Period>
4883 iter_type __duration_put_put_value(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
4884
4885 template <typename Rep, typename Period>
4886 iter_type __duration_put_put_unit(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
4887
4888
4889 static std::locale::id id; // Unique identifier for this type of facet.
4890
4891 __duration_put_d();
4892 };
4893
4894 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4895 [section:c Constructor `duration_put(size_t)`]
4896
4897 explicit duration_put(size_t refs);
4898
4899 Constructs a __duration_put facet.
4900
4901 __params
4902
4903 * [param refs] references
4904
4905 __effects Constructs a __duration_put facet.
4906 If the `refs` argument is `0` then destruction of the object is
4907 delegated to the locale, or locales, containing it. This allows
4908 the user to ignore lifetime management issues. On the other had,
4909 if `refs` is `1` then the object must be explicitly deleted;
4910 `locale` will not do so. In this case, the object can be
4911 maintained across the lifetime of multiple locales.
4912
4913 [endsect]
4914 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4915 [section:d Destructor `~duration_put()`]
4916
4917 ~duration_put();
4918
4919 Destructs a __duration_put facet.
4920
4921 [endsect]
4922 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4923 [section:put Member Function `put(iter_type,std::ios_base&,char_type,duration<Rep,Period> const&, const CharT*,const CharT*)`]
4924
4925 template <typename Rep, typename Period>
4926 iter_type put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d, const CharT* pattern,
4927 const CharT* pat_end) const;
4928
4929 __params
4930
4931 * [param s] an output stream iterator
4932 * [param ios] a reference to a ios_base
4933 * [param d] the duration
4934 * [param pattern] begin of the formatting pattern
4935 * [param pat_end] end of the formatting pattern
4936
4937 __effects Steps through the sequence from `pattern` to `pat_end`,
4938 identifying characters that are part of a pattern sequence. Each character
4939 that is not part of a pattern sequence is written to `s` immediately, and
4940 each pattern sequence, as it is identified, results in a call to `put_value` or `put_unit`;
4941 thus, pattern elements and other characters are interleaved in the output
4942 in the order in which they appear in the pattern. Pattern sequences are
4943 identified by converting each character `c` to a `char` value as if by
4944 `ct.narrow(c,0)`, where `ct` is a reference to `ctype<charT>` obtained from
4945 `ios.getloc()`. The first character of each sequence is equal to `'%'`,
4946 followed by a pattern specifier character specifier, which can be `'v'` for
4947 the duration value or `'u'` for the duration unit. .
4948 For each valid pattern sequence identified, calls
4949 `put_value(s, ios, d)` or `put_unit(s, ios, d)`.
4950
4951 __returns An iterator pointing immediately after the last character produced.
4952
4953
4954 [endsect]
4955 [section:put2 Member Function `put(iter_type,std::ios_base&,char_type fill, duration<Rep, Period> const&)`]
4956
4957 template <typename Rep, typename Period>
4958 iter_type put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
4959
4960 __params
4961
4962 * [param s] an output stream iterator
4963 * [param ios] a reference to a ios_base
4964 * [param d] the duration
4965
4966 Retrieves Stores the duration pattern from the __duration_unit facet in let say `str`. Last as if
4967
4968 return put(s, ios, d, str.data(), str.data() + str.size());
4969
4970 __returns An iterator pointing immediately after the last character produced.
4971
4972 [endsect]
4973 [section:put_value Member Function `put_value(iter_type, std::ios_base&, char_type, duration<Rep,Period> const&)`]
4974
4975 template <typename Rep, typename Period>
4976 iter_type put_value(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
4977
4978 __params
4979
4980 * [param s] an output stream iterator
4981 * [param ios] a reference to a ios_base
4982 * [param d] the duration
4983
4984 __effects As if std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, ' ', static_cast<long int> (d.count())).
4985
4986 __returns An iterator pointing immediately after the last character produced.
4987
4988 [endsect]
4989 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4990 [section:put_unit Member Function `put_unit(iter_type,std::ios_base&,char_type,duration<Rep, Period> const&)`]
4991
4992 template <typename Rep, typename Period>
4993 iter_type put_unit(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
4994
4995 __params
4996
4997 * [param s] an output stream iterator
4998 * [param ios] a reference to a ios_base
4999 * [param fill] the fill character
5000 * [param d] the duration
5001
5002 __effects Let `facet` be the `duration_units<CharT>` facet associated to `ios`. If the associated unit is named, as if
5003
5004 string_type str = facet.get_unit(get_duration_style(ios), d);
5005 s=std::copy(str.begin(), str.end(), s);
5006
5007 Otherwise, format the unit as `"[Period::num/Period::den]"` followed by the unit associated to [N/D] obtained using `facet.get_n_d_unit(get_duration_style(ios), d)`.
5008
5009 __returns s, iterator pointing immediately after the last character produced.
5010
5011 [endsect]
5012 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
5013 [endsect]
5014
5015 [endsect] [/section:duration_put_hpp]
5016
5017 [/==================================================================]
5018 [section:duration_units_hpp Header `<boost/chrono/io/duration_units.hpp>`]
5019 [/==================================================================]
5020
5021 namespace boost {
5022 namespace chrono {
5023 class rt_ratio;
5024 template <typename CharT = char>
5025 class duration_units;
5026
5027 }
5028 }
5029
5030
5031 [section:rt_ratio Class `rt_ratio`]
5032
5033 class rt_ratio
5034 {
5035 public:
5036 template <typename Period>
5037 rt_ratio(Period const&) :
5038 num(Period::type::num), den(Period::type::den)
5039 {
5040 }
5041
5042 rt_ratio(intmax_t n = 0, intmax_t d = 1) :
5043 num(n), den(d)
5044 {
5045 }
5046
5047 intmax_t num;
5048 intmax_t den;
5049 };
5050
5051 [endsect]
5052 [section:duration_units Template Class `duration_units`]
5053
5054 template <typename CharT = char>
5055 class duration_units: public std::locale::facet
5056 {
5057 public:
5058 typedef CharT char_type; // Type of character the facet is instantiated on.
5059 typedef std::basic_string<CharT> string_type; // Type of character string passed to member functions.
5060 static std::locale::id id; // Unique identifier for this type of facet.
5061
5062 explicit __duration_units_c(size_t refs = 0);
5063 virtual const string_type* __duration_units_get_n_d_valid_units_start() const =0;
5064 virtual const string_type* __duration_units_get_n_d_valid_units_end() const=0;
5065 virtual const string_type* __duration_units_get_valid_units_start() const=0;
5066 virtual const string_type* __duration_units_get_valid_units_end() const=0;
5067 virtual bool __duration_units_match_n_d_valid_unit(const string_type* k) const = 0;
5068 virtual bool __duration_units_match_valid_unit(const string_type* k, rt_ratio& rt) const = 0;
5069 virtual string_type __duration_units_get_pattern() const=0;
5070 template <typename Rep, typename Period>
5071 string_type __duration_units_get_unit(duration_style style, duration<Rep, Period> const& d) const;
5072 template <typename Rep, typename Period>
5073 string_type __duration_units_get_n_d_unit(duration_style style, duration<Rep, Period> const& d) const;
5074 template <typename Period>
5075 bool __duration_units_is_named_unit() const;
5076
5077 protected:
5078 virtual __duration_units_d();
5079 virtual string_type __duration_units_do_get_n_d_unit(duration_style style, rt_ratio rt, intmax_t v) const = 0;
5080 virtual string_type __duration_units_do_get_unit(duration_style style,rt_ratio rt, intmax_t v) const = 0;
5081 virtual bool __duration_units_do_is_named_unit(rt_ratio rt) const =0;
5082 };
5083
5084 __duration_units facet gives useful information about the duration units,
5085 as the number of plural forms, the plural form associated to a duration,
5086 the text associated to a plural form and a duration's period,
5087
5088 [section:c Constructor `duration_units()`]
5089
5090 explicit duration_units(size_t refs = 0);
5091
5092 Construct a __duration_units facet.
5093
5094 __params
5095
5096 * [param refs] references
5097
5098 __effects Construct a __duration_units facet.
5099 If the `refs` argument is `0` then destruction of the object is
5100 delegated to the locale, or locales, containing it. This allows
5101 the user to ignore lifetime management issues. On the other had,
5102 if `refs` is `1` then the object must be explicitly deleted;
5103 the locale will not do so. In this case, the object can be
5104 maintained across the lifetime of multiple locales.
5105
5106 [endsect]
5107 [section:d Destructor `~duration_units()`]
5108
5109 virtual ~duration_units();
5110
5111 __effects Destroys the facet.
5112
5113 [endsect]
5114 [section:get_n_d_valid_units_start Member Function `get_n_d_valid_units_start()`]
5115
5116 virtual const string_type* get_n_d_valid_units_start() const =0;
5117
5118 __returns pointer to the start of valid [N/D] units.
5119
5120
5121 [endsect]
5122 [section:get_n_d_valid_units_end Member Function `get_n_d_valid_units_end()`]
5123
5124 virtual const string_type* get_n_d_valid_units_end() const=0;
5125
5126 __returns pointer to the end of valid [N/D] units.
5127
5128 [endsect]
5129 [section:get_valid_units_start Member Function `get_valid_units_start()`]
5130
5131 virtual const string_type* get_valid_units_start() const=0;
5132
5133 __returns pointer to the start of valid units, symbol or prefix with its different plural forms.
5134
5135 [endsect]
5136 [section:get_valid_units_end Member Function `get_valid_units_end()`]
5137
5138 virtual const string_type* get_valid_units_end() const=0;
5139
5140 __returns pointer to the end of valid units.
5141
5142 [endsect]
5143 [section:match_n_d_valid_unit Member Function `match_n_d_valid_unit(const string_type*)`]
5144
5145 virtual bool match_n_d_valid_unit(const string_type* k) const = 0;
5146
5147 __params
5148
5149 * [param k] the found pointer to the [N/D] unit.
5150
5151 __returns `true` if `k` matches a valid unit.
5152
5153 [endsect]
5154 [section:match_valid_unit Member Function `match_valid_unit(const string_type*,rt_ratio&)`]
5155
5156 virtual bool match_valid_unit(const string_type* k, rt_ratio& rt) const = 0;
5157
5158 __params
5159
5160 * [param k] the found pointer to the unit.
5161
5162 __effects `rt` is set to the valid Period when the `k` matches a valid unit.
5163 __returns `true` if `k` matches a valid unit.
5164
5165 [endsect]
5166 [section:get_pattern Member Function `get_pattern()`]
5167
5168 virtual string_type get_pattern() const=0;
5169
5170 __returns the pattern to be used by default.
5171
5172 [endsect]
5173 [section:get_unit Template Member Function `get_unit(duration_style,duration<Rep,Period> const&)`]
5174
5175 template <typename Rep, typename Period>
5176 string_type get_unit(duration_style style, duration<Rep, Period> const& d) const;
5177
5178
5179 __returns `get_unit(style, d.count(), rt_ratio(Period()))`, the unit associated to this duration.
5180
5181 [endsect]
5182
5183 [section:get_n_d_unit Template Member Function `get_n_d_unit(duration_style,duration<Rep,Period> const&)`]
5184
5185 template <typename Rep, typename Period>
5186 string_type get_n_d_unit(duration_style style, duration<Rep, Period> const& d) const;
5187
5188 __returns get_n_d_unit(style, d.count(), rt_ratio(Period())), i.e. the [N/D] suffix unit associated to this duration.
5189
5190 [endsect]
5191
5192 [section:is_named_unit Template Member Function `is_named_unit()`]
5193
5194 template <typename Period>
5195 bool is_named_unit() const;
5196
5197 __returns `do_is_named_unit(rt_ratio(Period()))`, true if the unit associated to the given Period is named, false otherwise.
5198
5199 [endsect]
5200
5201 [section:do_get_n_d_unit Protected Member Function `do_get_n_d_unit(duration_style,rt_ratio,intmax_t)`]
5202
5203 virtual string_type do_get_n_d_unit(duration_style style, rt_ratio rt, intmax_t v) const = 0;
5204
5205 __returns the [N/D] suffix unit associated to this duration.
5206
5207 [endsect]
5208
5209 [section:do_get_unit Protected Member Function `do_get_unit(duration_style,rt_ratio,intmax_t)`]
5210
5211 virtual string_type do_get_unit(duration_style style,rt_ratio rt, intmax_t v) const = 0;
5212
5213 __returns the unit associated to this duration.
5214
5215 [endsect]
5216
5217 [section:do_is_named_unit Protected Member Function `do_is_named_unit(rt_ratio)`]
5218
5219 virtual bool do_is_named_unit(rt_ratio rt) const =0;
5220
5221 __returns true if the unit associated to the given Period is named, false otherwise.
5222
5223 [endsect]
5224
5225 [endsect] [/section:duration_units]
5226
5227 [section:duration_units_default Template Class `duration_units_default`]
5228
5229 template <typename CharT = char>
5230 class duration_units_default: public duration_units<CharT>
5231 {
5232 protected:
5233 static const std::size_t pfs_ = 2; // The default English facet has two plural forms.
5234
5235 public:
5236 typedef CharT char_type;
5237 typedef std::basic_string<CharT> string_type;
5238
5239 explicit duration_units_default(size_t refs = 0);
5240 ~duration_units_default();
5241
5242 bool match_n_d_valid_unit(const string_type* k) const;
5243 bool match_valid_unit(const string_type* k, rt_ratio& rt) const;
5244 const string_type* get_n_d_valid_units_start()const;
5245 const string_type* get_n_d_valid_units_end()const;
5246 string_type* get_valid_units_start() const;
5247 string_type* get_valid_units_end() const;
5248 string_type get_pattern() const;
5249 protected:
5250 bool do_is_named_unit(rt_ratio rt) const;
5251 string_type do_get_n_d_unit(duration_style style, rt_ratio, intmax_t v) const;
5252 string_type do_get_unit(duration_style style, rt_ratio rt, intmax_t v) const;
5253
5254 virtual std::size_t do_get_plural_forms() const;
5255 virtual std::size_t do_get_plural_form(int_least64_t value) const;
5256
5257 virtual string_type do_get_unit(duration_style style, ratio<1> u, std::size_t pf) const;
5258 virtual string_type do_get_unit(duration_style style, ratio<60> u, std::size_t pf) const;
5259 virtual string_type do_get_unit(duration_style style, ratio<3600> u, std::size_t pf) const;
5260 virtual string_type do_get_unit(duration_style style, atto u, std::size_t pf) const;
5261 virtual string_type do_get_unit(duration_style style, femto u, std::size_t pf) const;
5262 virtual string_type do_get_unit(duration_style style, pico u, std::size_t pf) const;
5263 virtual string_type do_get_unit(duration_style style, nano u, std::size_t pf) const;
5264 virtual string_type do_get_unit(duration_style style, micro u, std::size_t pf) const;
5265 virtual string_type do_get_unit(duration_style style, milli u, std::size_t pf) const;
5266 virtual string_type do_get_unit(duration_style style, centi u, std::size_t pf) const;
5267 virtual string_type do_get_unit(duration_style style, deci u, std::size_t pf) const;
5268 virtual string_type do_get_unit(duration_style style, deca u, std::size_t pf) const;
5269 virtual string_type do_get_unit(duration_style style, hecto u, std::size_t pf) const;
5270 virtual string_type do_get_unit(duration_style style, kilo u, std::size_t pf) const;
5271 virtual string_type do_get_unit(duration_style style, mega u, std::size_t pf) const;
5272 virtual string_type do_get_unit(duration_style style, giga u, std::size_t pf) const;
5273 virtual string_type do_get_unit(duration_style style, tera u, std::size_t pf) const;
5274 virtual string_type do_get_unit(duration_style style, peta u, std::size_t pf) const;
5275 virtual string_type do_get_unit(duration_style style, exa u, std::size_t pf) const;
5276
5277 virtual string_type do_get_ratio_prefix(duration_style style, atto u) const;
5278 virtual string_type do_get_ratio_prefix(duration_style style, femto u) const;
5279 virtual string_type do_get_ratio_prefix(duration_style style, pico u) const;
5280 virtual string_type do_get_ratio_prefix(duration_style style, nano u) const;
5281 virtual string_type do_get_ratio_prefix(duration_style style, micro u) const;
5282 virtual string_type do_get_ratio_prefix(duration_style style, milli u) const;
5283 virtual string_type do_get_ratio_prefix(duration_style style, centi u) const;
5284 virtual string_type do_get_ratio_prefix(duration_style style, deci u) const;
5285 virtual string_type do_get_ratio_prefix(duration_style style, deca u) const;
5286 virtual string_type do_get_ratio_prefix(duration_style style, hecto u) const;
5287 virtual string_type do_get_ratio_prefix(duration_style style, kilo u) const;
5288 virtual string_type do_get_ratio_prefix(duration_style style, mega u) const;
5289 virtual string_type do_get_ratio_prefix(duration_style style, giga u) const;
5290 virtual string_type do_get_ratio_prefix(duration_style style, tera u) const;
5291 virtual string_type do_get_ratio_prefix(duration_style style, peta u) const;
5292 virtual string_type do_get_ratio_prefix(duration_style style, exa u) const;
5293 };
5294
5295 This class is used to define the strings for the default English.
5296 This facet names the units associated to the following periods:
5297
5298 * __atto,
5299 * __femto,
5300 * __pico,
5301 * __nano,
5302 * __micro,
5303 * __milli,
5304 * __centi,
5305 * __deci,
5306 * ratio<1>,
5307 * __deca,
5308 * __hecto,
5309 * __kilo,
5310 * __mega,
5311 * __giga,
5312 * __tera,
5313 * __peta,
5314 * __exa,
5315 * ratio<60> and
5316 * ratio<3600>.
5317
5318
5319 [section:c Constructor `duration_units_default()`]
5320
5321 explicit duration_units_default(size_t refs = 0);
5322
5323 Construct a duration_units_default facet.
5324
5325 __params
5326
5327 * [param refs] references
5328
5329 __effects Construct a duration_units_default facet.
5330 If the `refs` argument is `0` then destruction of the object is
5331 delegated to the locale, or locales, containing it. This allows
5332 the user to ignore lifetime management issues. On the other had,
5333 if `refs` is `1` then the object must be explicitly deleted;
5334 the locale will not do so. In this case, the object can be
5335 maintained across the lifetime of multiple locales.
5336
5337 [endsect]
5338 [section:d Destructor `~duration_units_default()`]
5339
5340 virtual ~duration_units_default();
5341
5342 __effects Destroys the facet.
5343
5344 [endsect]
5345 [section:get_n_d_valid_units_start Member Function `get_n_d_valid_units_start()`]
5346
5347 virtual const string_type* get_n_d_valid_units_start() const;
5348
5349 __returns pointer to the start of valid [N/D] units.
5350
5351
5352 [endsect]
5353 [section:get_n_d_valid_units_end Member Function `get_n_d_valid_units_end()`]
5354
5355 virtual const string_type* get_n_d_valid_units_end() const;
5356
5357 __returns pointer to the end of valid [N/D] units.
5358
5359 [endsect]
5360 [section:get_valid_units_start Member Function `get_valid_units_start()`]
5361
5362 virtual const string_type* get_valid_units_start() const;
5363
5364 __returns pointer to the start of valid units, symbol or prefix with its different plural forms.
5365
5366 [endsect]
5367 [section:get_valid_units_end Member Function `get_valid_units_end()`]
5368
5369 virtual const string_type* get_valid_units_end() const;
5370
5371 __returns pointer to the end of valid units.
5372
5373 [endsect]
5374 [section:match_n_d_valid_unit Member Function `match_n_d_valid_unit(const string_type*)`]
5375
5376 virtual bool match_n_d_valid_unit(const string_type* k) const;
5377
5378 __params
5379
5380 * [param k] the found pointer to the [N/D] unit.
5381
5382 __returns `true` if `k` matches a valid unit.
5383
5384 [endsect]
5385 [section:match_valid_unit Member Function `match_valid_unit(const string_type*,rt_ratio&)`]
5386
5387 virtual bool match_valid_unit(const string_type* k, rt_ratio& rt) const;
5388
5389 __params
5390
5391 * [param k] the found pointer to the unit.
5392
5393 __effects `rt` is set to the valid Period when the `k` matches a valid unit.
5394 __returns `true` if `k` matches a valid unit.
5395
5396 [endsect]
5397 [section:get_pattern Member Function `get_pattern()`]
5398
5399 virtual string_type get_pattern() const;
5400
5401 __returns the pattern to be used by default.
5402
5403 [endsect]
5404
5405 [section:do_get_n_d_unit Protected Member Function `do_get_n_d_unit(duration_style,rt_ratio,intmax_t)`]
5406
5407 virtual string_type do_get_n_d_unit(duration_style style, rt_ratio rt, intmax_t v) const;
5408
5409 __returns the [N/D] suffix unit associated to this duration.
5410
5411 [endsect]
5412
5413 [section:do_get_unit Protected Member Function `do_get_unit(duration_style,rt_ratio,intmax_t)`]
5414
5415 virtual string_type do_get_unit(duration_style style,rt_ratio rt, intmax_t v) const;
5416
5417 __returns the unit associated to this duration.
5418
5419 [endsect]
5420
5421 [section:do_is_named_unit Protected Member Function `do_is_named_unit(rt_ratio)`]
5422
5423 virtual bool do_is_named_unit(rt_ratio rt) const;
5424
5425 __returns true if the unit associated to the given Period is named, false otherwise.
5426
5427 [endsect]
5428
5429 [section:do_get_plural_forms Protected Member Function `do_get_plural_forms()`]
5430
5431 virtual std::size_t do_get_plural_forms() const;
5432
5433 __returns the number of associated plural forms this facet manages.
5434
5435 [endsect]
5436
5437 [section:do_get_plural_form Protected Member Function `do_get_plural_form(int_least64_t)`]
5438
5439 virtual std::size_t do_get_plural_form(int_least64_t value) const;
5440
5441 Gets the associated plural form.
5442
5443 __params
5444
5445 [param value] the duration representation
5446
5447 __returns the plural form associated to the `value` parameter. In English there are 2 plural forms
5448
5449 * 0 singular (-1 or 1)
5450 * 1 plural for all others
5451
5452 [endsect]
5453
5454 [section:do_get_unit_seconds Protected Member Function `do_get_unit(duration_style,ratio<1>,std::size_t)`]
5455
5456 virtual string_type do_get_unit(duration_style style, ratio<1> u, std::size_t pf) const;
5457
5458 __params
5459
5460 * [param style] the duration style.
5461 * [param period] the period associated to the duration hours.
5462 * [param pf] the requested plural form.
5463
5464 __returns if style is symbol returns "s", otherwise if pf is 0 return "second", if pf is 1 "seconds"
5465
5466 [endsect]
5467
5468 [section:do_get_unit_minutes Protected Member Function `do_get_unit(duration_style style,ratio<60>,std::size_t)`]
5469
5470 virtual string_type do_get_unit(duration_style style, ratio<60> u, std::size_t pf) const;
5471
5472 __params
5473
5474 * [param style] the duration style.
5475 * [param period] the period associated to the duration hours.
5476 * [param pf] the requested plural form.
5477
5478 __returns if style is symbol returns "min", otherwise if pf is 0 return "minute", if pf is 1 "minutes"
5479
5480 [endsect]
5481
5482 [section:do_get_unit_hours Protected Member Function `do_get_unit(duration_style,ratio<3600>,std::size_t)`]
5483
5484 virtual string_type do_get_unit(duration_style style, ratio<3600> u, std::size_t pf) const;
5485
5486 __params
5487
5488 * [param style] the duration style.
5489 * [param period] the period associated to the duration hours.
5490 * [param pf] the requested plural form.
5491
5492 __returns if style is symbol returns "h", otherwise if pf is 0 return "hour", if pf is 1 "hours"
5493
5494 [endsect]
5495
5496 [section:do_get_unit_xxx Protected Member Function `do_get_unit(duration_style,Period,std::size_t)`]
5497
5498 virtual string_type do_get_unit(duration_style style, atto u, std::size_t pf) const;
5499 virtual string_type do_get_unit(duration_style style, femto u, std::size_t pf) const;
5500 virtual string_type do_get_unit(duration_style style, pico u, std::size_t pf) const;
5501 virtual string_type do_get_unit(duration_style style, nano u, std::size_t pf) const;
5502 virtual string_type do_get_unit(duration_style style, micro u, std::size_t pf) const;
5503 virtual string_type do_get_unit(duration_style style, milli u, std::size_t pf) const;
5504 virtual string_type do_get_unit(duration_style style, centi u, std::size_t pf) const;
5505 virtual string_type do_get_unit(duration_style style, deci u, std::size_t pf) const;
5506 virtual string_type do_get_unit(duration_style style, deca u, std::size_t pf) const;
5507 virtual string_type do_get_unit(duration_style style, hecto u, std::size_t pf) const;
5508 virtual string_type do_get_unit(duration_style style, kilo u, std::size_t pf) const;
5509 virtual string_type do_get_unit(duration_style style, mega u, std::size_t pf) const;
5510 virtual string_type do_get_unit(duration_style style, giga u, std::size_t pf) const;
5511 virtual string_type do_get_unit(duration_style style, tera u, std::size_t pf) const;
5512 virtual string_type do_get_unit(duration_style style, peta u, std::size_t pf) const;
5513 virtual string_type do_get_unit(duration_style style, exa u, std::size_t pf) const;
5514
5515 __params
5516
5517 * [param style] the duration style.
5518 * [param u] the period tag atto.
5519 * [param pf] the requested plural form.
5520
5521 __returns the concatenation of the prefix associated to period `u` + the one associated to seconds.
5522
5523 [endsect]
5524
5525 [section:do_get_ratio_prefix_xxx Protected Member Function `do_get_ratio_prefix(duration_style, Period)`]
5526
5527 virtual string_type do_get_ratio_prefix(duration_style style, atto u) const;
5528 virtual string_type do_get_ratio_prefix(duration_style style, femto u) const;
5529 virtual string_type do_get_ratio_prefix(duration_style style, pico u) const;
5530 virtual string_type do_get_ratio_prefix(duration_style style, nano u) const;
5531 virtual string_type do_get_ratio_prefix(duration_style style, micro u) const;
5532 virtual string_type do_get_ratio_prefix(duration_style style, milli u) const;
5533 virtual string_type do_get_ratio_prefix(duration_style style, centi u) const;
5534 virtual string_type do_get_ratio_prefix(duration_style style, deci u) const;
5535 virtual string_type do_get_ratio_prefix(duration_style style, deca u) const;
5536 virtual string_type do_get_ratio_prefix(duration_style style, hecto u) const;
5537 virtual string_type do_get_ratio_prefix(duration_style style, kilo u) const;
5538 virtual string_type do_get_ratio_prefix(duration_style style, mega u) const;
5539 virtual string_type do_get_ratio_prefix(duration_style style, giga u) const;
5540 virtual string_type do_get_ratio_prefix(duration_style style, tera u) const;
5541 virtual string_type do_get_ratio_prefix(duration_style style, peta u) const;
5542 virtual string_type do_get_ratio_prefix(duration_style style, exa u) const;
5543
5544 __params
5545
5546 * [param style] the duration style.
5547 * [param u] the period tag atto.
5548
5549 __returns depending on the value of `style` return the ratio_string symbol or prefix.
5550
5551 [endsect]
5552
5553
5554 [endsect] [/section:duration_units_default]
5555
5556 [endsect] [/section:duration_units_hpp]
5557
5558 [/==================================================================]
5559 [section:duration_io_hpp Header `<boost/chrono/io/duration_io.hpp>`]
5560 [/==================================================================]
5561
5562 namespace boost {
5563 namespace chrono {
5564
5565 // manipulators
5566
5567 std::ios_base& __symbol_format(ios_base& ios);
5568 std::ios_base& __name_format(ios_base& ios);
5569 class __duration_fmt;
5570 template<class CharT, class Traits>
5571 std::basic_ostream<CharT, Traits>&
5572 __duration_fmt__op_out(std::basic_ostream<CharT, Traits>& os, duration_fmt d);
5573
5574 template<class CharT, class Traits>
5575 std::basic_istream<CharT, Traits>&
5576 __duration_fmt__op_in(std::basic_istream<CharT, Traits>& is, duration_fmt d);
5577
5578
5579 // duration I/O
5580
5581 template <class CharT, class Traits, class Rep, class Period>
5582 std::basic_ostream<CharT, Traits>&
5583 __duration__op_out(std::basic_ostream<CharT, Traits>& os, const __duration<Rep, Period>& d);
5584
5585 template <class CharT, class Traits, class Rep, class Period>
5586 std::basic_istream<CharT, Traits>&
5587 __duration__op_in(std::basic_istream<CharT, Traits>& is, __duration<Rep, Period>& d)
5588
5589 }
5590 }
5591
5592
5593 [section:manipulators I/O Manipulators]
5594
5595 There is a parameterized manipulator that takes the duration_style as parameter.
5596 The symbol or name format can be easily chosen by streaming a `symbol_format` or `name_format` manipulators respectively.
5597
5598 [section:duration_fmt Template Class `duration_fmt`]
5599
5600 class duration_fmt
5601 {
5602 public:
5603
5604 explicit __duration_fmt__c1(__duration_style style) noexcept;
5605
5606 #ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
5607 explicit
5608 __duration_fmt__op_duration_style() const noexcept;
5609 #endif
5610 __duration_style __duration_fmt__get_duration_style() const noexcept;
5611 };
5612
5613 template<class CharT, class Traits>
5614 std::basic_ostream<CharT, Traits>&
5615 __duration_fmt__op_out(std::basic_ostream<CharT, Traits>& os, duration_fmt d);
5616
5617 template<class CharT, class Traits>
5618 std::basic_istream<CharT, Traits>&
5619 __duration_fmt__op_in(std::basic_istream<CharT, Traits>& is, duration_fmt d);
5620
5621
5622 [section:c1 Constructor `duration_fmt(duration_style)`]
5623
5624 explicit duration_fmt(duration_style f) noexcept;
5625
5626 __effects Constructs a __duration_fmt by storing `f`.
5627
5628 __postcondition `static_cast<duration_style>(*this) == f`.
5629
5630 [endsect]
5631 [section:op_duration_style Member Function `operator duration_style()`]
5632
5633 explicit operator duration_style() const noexcept;
5634 duration_style get_duration_style() const noexcept;
5635
5636 __returns: The stored __duration_fmt `f`.
5637
5638 [endsect]
5639 [section:op_out Member Function `operator <<(basic_ostream<>&, duration_fmt)`]
5640
5641 template<class CharT, class Traits>
5642 basic_ostream<CharT, Traits>&
5643 operator<<(basic_ostream<CharT, Traits>& s, duration_fmt d);
5644
5645 __effects: `__set_duration_style(s, static_cast<__duration_style>(d))))`.
5646
5647 __returns: `s`.
5648
5649 [endsect]
5650 [section:op_in Member Function `operator >>(basic_istream<>&, duration_fmt)`]
5651
5652 template<class CharT, class Traits>
5653 basic_istream<CharT, Traits>&
5654 operator>>(basic_istream<CharT, Traits>& s, duration_fmt d);
5655
5656 __effects: `__set_duration_style(s, static_cast<__duration_style>(d))))`.
5657
5658 __returns: `s`.
5659
5660 [endsect]
5661 [endsect]
5662
5663 [section:symbol_format Non Member Function `symbol_format(ios_base&)`]
5664
5665 std::ios_base& __symbol_format(ios_base& ios);
5666
5667 __effects: `__set_duration_style(s, __duration_style::symbol)`.
5668
5669 __returns `ios`
5670
5671 [endsect]
5672 [section:name_format Non Member Function `name_format(ios_base&)`]
5673
5674 std::ios_base& __name_format(ios_base& ios);
5675
5676 __effects: `__set_duration_style(s, __duration_style::prefix)`.
5677
5678 __returns `ios`
5679
5680
5681 [endsect]
5682 [endsect]
5683
5684
5685 [section:streams I/O Streams Operations]
5686
5687 [section:duration__op_out Member Function `operator <<(basic_ostream<>&, const duration<>& d)`]
5688
5689 Any __duration can be streamed out to a `basic_ostream`.
5690 The run-time value of the __duration is formatted according to the rules and current format settings for __duration`::rep` and the __duration_units facet.
5691
5692
5693 template <class CharT, class Traits, class Rep, class Period>
5694 std::basic_ostream<CharT, Traits>&
5695 operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep, Period>& d);
5696
5697 __effects Behaves as a formatted output function.
5698 After constructing a sentry object, if the sentry converts to true,
5699 calls to `facet.__duration_put_put(os,os,os.fill(),d)` where `facet` is the `__duration_put<CharT>`
5700 facet associated to `os` or a new created instance of the default `__duration_put<CharT>` facet.
5701
5702 __returns `os`.
5703
5704 [endsect]
5705 [section:duration__op_in Member Function `operator <<(basic_istream<>&, const duration<>& d)`]
5706
5707 template <class CharT, class Traits, class Rep, class Period>
5708 std::basic_istream<CharT, Traits>&
5709 operator>>(std::basic_istream<CharT, Traits>& is, duration<Rep, Period>& d)
5710
5711 __effects Behaves as a formatted input function. After constructing a `sentry` object, if the `sentry`
5712 converts to `true`, calls to `facet.__duration_get_get(is,std::istreambuf_iterator<CharT, Traits>(), is, err, d)` where `facet` is the `__duration_get<CharT>`
5713 facet associated to `is` or a new created instance of the default `__duration_get<CharT>` facet.
5714
5715 If any step fails, calls `os.setstate(std::ios_base::failbit | std::ios_base::badbit)`.
5716
5717 __returns `is`
5718 [endsect]
5719
5720 [endsect]
5721
5722
5723 [endsect] [/section:duration_io_hpp Header `<boost/chrono/io/duration_io.hpp>`]
5724
5725 [/==================================================================]
5726 [section:time_point_get_hpp Header `<boost/chrono/io/time_point_get.hpp>`]
5727 [/==================================================================]
5728
5729 namespace boost {
5730 namespace chrono {
5731 template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
5732 class time_point_get;
5733 }
5734 }
5735
5736 [section:time_point_get Template Class `time_point_get`]
5737
5738 template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
5739 class time_point_get: public std::locale::facet
5740 {
5741 public:
5742 typedef CharT char_type; // Type of character the facet is instantiated on.
5743 typedef InputIterator iter_type; // Type of iterator used to scan the character buffer.
5744
5745 explicit __time_point_get_c(size_t refs = 0);
5746
5747 template <class Clock, class Duration>
5748 iter_type __time_point_get_get(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
5749 time_point<Clock, Duration> &tp, const char_type *pattern, const char_type *pat_end) const;
5750
5751 template <class Clock, class Duration>
5752 iter_type __time_point_get_get2(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
5753 time_point<Clock, Duration> &tp) const;
5754
5755 template <typename Rep, typename Period>
5756 iter_type __time_point_get_get_duration(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
5757 duration<Rep, Period>& d) const;
5758
5759 template <class Clock>
5760 iter_type __time_point_get_get_epoch(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err) const;
5761
5762 static std::locale::id id; // Unique identifier for this type of facet.
5763
5764 __time_point_get_d();
5765 };
5766
5767
5768 `time_point_get` is used to parse a character sequence, extracting
5769 the duration and the epoch into a class `time_point`.
5770
5771 The pattern can contain the format specifiers `%d` and `%e` in any order.
5772
5773 User confirmation is required for reliable parsing of
5774 user-entered durations, but machine-generated formats can be parsed
5775 reliably. This allows parsers to be aggressive about interpreting user
5776 variations on standard formats.
5777
5778 If the end iterator is reached during parsing the member function sets `std::ios_base::eofbit` in `err`.
5779
5780 [section:c Constructor `time_point_get(size_t)`]
5781
5782 explicit time_point_get(size_t refs);
5783
5784 Constructs a __time_point_get facet.
5785
5786 __params
5787
5788 * [param refs] references
5789
5790 __effects Constructs a __duration_put facet.
5791 If the `refs` argument is `0` then destruction of the object is
5792 delegated to the locale, or locales, containing it. This allows
5793 the user to ignore lifetime management issues. On the other had,
5794 if `refs` is `1` then the object must be explicitly deleted;
5795 `locale` will not do so. In this case, the object can be
5796 maintained across the lifetime of multiple locales.
5797
5798 [endsect]
5799
5800 [section:d Destructor `~time_point_get()`]
5801
5802 ~time_point_get();
5803
5804 __effects Destroy the facet.
5805
5806 [endsect]
5807 [section:get Template Member Function `get(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,time_point<Clock, Duration>&,const CharT*,const CharT*)`]
5808
5809 template <class Clock, class Duration>
5810 iter_type get(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err,
5811 time_point<Clock, Duration> &tp, const char_type *pattern, const char_type *pat_end) const;
5812
5813 __params
5814
5815 * [param s] start input stream iterator
5816 * [param end] end input stream iterator
5817 * [param ios] a reference to a `ios_base`
5818 * [param err] the `ios_base::iostate`
5819 * [param tp] the __time_point
5820 * [param pattern] begin of the formatting pattern
5821 * [param pat_end] end of the formatting pattern
5822
5823 __requires `[pattern,pat_end)` must be a valid range.
5824
5825 __effects: The function starts by evaluating `err = std::ios_base::goodbit`.
5826 It then enters a loop, reading zero or more characters from `s` at
5827 each iteration. Unless otherwise specified below, the loop
5828 terminates when the first of the following conditions holds:
5829
5830 * The expression `pattern == pat_end` evaluates to `true`.
5831 * The expression `err == std::ios_base::goodbit` evaluates to `false`.
5832 * The expression `s == end` evaluates to `true`, in which case the
5833 function evaluates `err = std::ios_base::eofbit | std::ios_base::failbit`.
5834 * The next element of pattern is equal to `'%'`, followed by a conversion
5835 specifier character, the functions `get_duration` or `get_epoch` are called depending on
5836 whether the format is `'d'` or `'e'`.
5837 If the number of elements in the range `[pattern,pat_end)` is not
5838 sufficient to unambiguously determine whether the conversion
5839 specification is complete and valid, the function evaluates
5840 `err |= std::ios_base::failbit`. Otherwise, the function evaluates
5841 `s = do_get(s, end, ios, err, d)`. If `err == std::ios_base::goodbit` holds after
5842 the evaluation of the expression, the function increments pattern to
5843 point just past the end of the conversion specification and continues
5844 looping.
5845 * The expression `isspace(*pattern, ios.getloc())` evaluates to `true`, in
5846 which case the function first increments `pattern` until
5847 `pattern == pat_end || !isspace(*pattern, ios.getloc())` evaluates to `true`,
5848 then advances `s` until `s == end || !isspace(*s, ios.getloc())` is `true`,
5849 and finally resumes looping.
5850 * The next character read from `s` matches the element pointed to by
5851 pattern in a case-insensitive comparison, in which case the function
5852 evaluates `++pattern`, `++s` and continues looping. Otherwise, the function
5853 evaluates `err = std::ios_base::failbit`.
5854
5855 __returns An iterator pointing just beyond the last character that can be determined to be part of a valid time_point.
5856
5857
5858 [endsect]
5859 [section:get2 Template Member Function `get(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,time_point<Clock,Duration>&)`]
5860
5861 template <class Clock, class Duration>
5862 iter_type get(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err,
5863 time_point<Clock, Duration> &tp) const;
5864
5865 __params
5866
5867 * [param s] start input stream iterator
5868 * [param end] end input stream iterator
5869 * [param ios] a reference to a `ios_base`
5870 * [param err] the `ios_base::iostate`
5871 * [param tp] the __time_point
5872
5873 __effects Stores the duration pattern from the `duration_unit` facet in let say `str`. Last as if
5874
5875 return get(s, end, ios, err, ios, d, str.data(), str.data() + str.size());
5876
5877 __returns An iterator pointing just beyond the last character that can be determined to be part of a valid name.
5878
5879 [endsect]
5880 [section:get_duration Template Member Function `get_duration(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,duration<Rep,Period>&)`]
5881
5882 template <typename Rep, typename Period>
5883 iter_type get_duration(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err,
5884 duration<Rep, Period>& d) const;
5885
5886 __effects As if
5887
5888 return facet.get(s, end, ios, err, d);
5889
5890 where `facet` is either the `duration_get` facet associated to the `ios` or an instance of the default `duration_get` facet.
5891
5892 __returns An iterator pointing just beyond the last character that can be determined to be part of a valid duration.
5893
5894 [endsect]
5895 [section:get_epoch Template Member Function `get_epoch(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&)`]
5896
5897 template <class Clock>
5898 iter_type get_epoch(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err) const;
5899
5900 __effects Let `facet` be the __time_point_units facet associated to `ios` or a new instance of the default __time_point_units_default facet.
5901 Let `epoch` be the epoch string associated to the `Clock` using this facet.
5902 Scans `s` to match `epoch` or `end` is reached.
5903
5904 If not match before the `end` is reached `std::ios_base::failbit` is set in `err`.
5905 If `end` is reached `std::ios_base::failbit` is set in `err`.
5906
5907 __returns An iterator pointing just beyond the last character that can be determined to be part of a epoch.
5908
5909 [endsect]
5910
5911 [endsect] [/section:time_point_get]
5912
5913
5914 [endsect] [/section:time_point_get_hpp]
5915
5916 [/==================================================================]
5917 [section:time_point_put_hpp Header `<boost/chrono/io/time_point_put.hpp>`]
5918 [/==================================================================]
5919
5920 namespace boost {
5921 namespace chrono {
5922 template <class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
5923 class time_point_put;
5924 }
5925 }
5926
5927
5928 [section:time_point_put Template Class `time_point_put`]
5929
5930
5931 The __time_point_put facet provides facilities for formatted output of __time_point values.
5932 The member function of __time_point_put take a __time_point and format it into character string representation.
5933
5934 tparam ChatT a character type
5935 tparam OutputIterator a model of `OutputIterator`
5936
5937
5938 template <class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
5939 class time_point_put: public std::locale::facet
5940 {
5941 public:
5942 typedef CharT char_type; // Type of character the facet is instantiated on.
5943 typedef std::basic_string<CharT> string_type; // Type of character string passed to member functions.
5944 typedef OutputIterator iter_type; // Type of iterator used to write in the character buffer.
5945
5946 explicit time_point_put(size_t refs = 0);
5947 ~time_point_put();
5948
5949 template <class Clock, class Duration>
5950 iter_type put(iter_type i, std::ios_base& ios, char_type fill, time_point<Clock, Duration> const& tp, const CharT* pattern,
5951 const CharT* pat_end) const;
5952 template <class Clock, class Duration>
5953 iter_type put(iter_type i, std::ios_base& ios, char_type fill, time_point<Clock, Duration> const& tp) const;
5954 template <typename Rep, typename Period>
5955 iter_type put_duration(iter_type i, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
5956 template <typename Clock>
5957 iter_type put_epoch(iter_type i, std::ios_base& os) const;
5958
5959 static std::locale::id id; // Unique identifier for this type of facet.
5960
5961
5962 };
5963
5964
5965 [section:c Constructor `time_point_get(size_t)`]
5966
5967 explicit time_point_put(size_t refs = 0);
5968
5969
5970 Construct a time_point_put facet.
5971
5972 __effects Construct a time_point_put facet.
5973 If the `refs` argument is `0` then destruction of the object is
5974 delegated to the locale, or locales, containing it. This allows
5975 the user to ignore lifetime management issues. On the other had,
5976 if `refs` is `1` then the object must be explicitly deleted;
5977 the locale will not do so. In this case, the object can be
5978 maintained across the lifetime of multiple locales.
5979
5980 __params
5981
5982 * [param refs] references
5983
5984 [endsect]
5985
5986 [section:put1 Member Function `put()`]
5987
5988 template <class Clock, class Duration>
5989 iter_type put(iter_type i, std::ios_base& ios, char_type fill, time_point<Clock, Duration> const& tp, const CharT* pattern,
5990 const CharT* pat_end) const;
5991
5992
5993 __params
5994
5995 * [param i] an output stream iterator
5996 * [param ios] a reference to a ios_base
5997 * [param fill] the character used as filler
5998 * [param tp] the __time_point
5999 * [param pattern] begin of the formatting pattern
6000 * [param pat_end] end of the formatting pattern
6001
6002 __effects Steps through the sequence from `pattern` to `pat_end`,
6003 identifying characters that are part of a pattern sequence. Each character
6004 that is not part of a pattern sequence is written to `s` immediately, and
6005 each pattern sequence, as it is identified, results in a call to
6006 __put_duration or __put_epoch;
6007 thus, pattern elements and other characters are interleaved in the output
6008 in the order in which they appear in the pattern. Pattern sequences are
6009 identified by converting each character `c` to a `char` value as if by
6010 `ct.narrow(c,0)`, where `ct` is a reference to `ctype<charT>` obtained from
6011 `ios.getloc()`. The first character of each sequence is equal to `'%'`,
6012 followed by a pattern specifier character spec, which can be `'d'` for
6013 the duration value or `'e'` for the epoch.
6014 For each valid pattern sequence identified, calls
6015 `put_duration(s, ios, fill, tp.time_since_epoch())` or `put_epoch(s, ios)`.
6016
6017 __returns An iterator pointing immediately after the last character produced.
6018
6019 [endsect]
6020
6021 [section:put2 Member Function `put()`]
6022
6023 template <class Clock, class Duration>
6024 iter_type put(iter_type i, std::ios_base& ios, char_type fill, time_point<Clock, Duration> const& tp) const;
6025
6026 __params
6027
6028 * [param i] an output stream iterator
6029 * [param ios] a reference to a ios_base
6030 * [param fill] the character used as filler
6031 * [param tp] the __time_point
6032 * [param tern] begin of the formatting pattern
6033 * [param pat_end] end of the formatting pattern
6034
6035 __effects Stores the time_point pattern from the __time_point_unit facet in let say `str`. Last as if
6036
6037 return put(s, ios, fill, tp, str.data(), str.data() + str.size());
6038
6039 __returns An iterator pointing immediately after the last character produced.
6040
6041 [endsect]
6042
6043 [section:put_duration Member Function `put_duration()`]
6044
6045 template <typename Rep, typename Period>
6046 iter_type put_duration(iter_type i, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
6047
6048 __params
6049
6050 * [param i] an output stream iterator
6051 * [param ios] a reference to a ios_base
6052 * [param fill] the character used as filler
6053 * [param d] the __duration
6054
6055 __effects As if `facet.put(s, ios, fill, d)` where facet is the `__duration_put<CharT>` facet associated
6056 to the `ios` or a new instance of `__duration_put<CharT>`.
6057
6058 __returns An iterator pointing immediately after the last character produced.
6059
6060 [endsect]
6061
6062 [section:put_epoch Member Function `put_epoch()`]
6063
6064 template <typename Clock>
6065 iter_type put_epoch(iter_type i, std::ios_base& os) const;
6066
6067 __params
6068
6069 * [param i] an output stream iterator
6070 * [param ios] a reference to a ios_base
6071
6072 __effects As if
6073
6074 string_type str = facet.template get_epoch<Clock>();
6075 s=std::copy(str.begin(), str.end(), s);
6076
6077
6078 where facet is the `__time_point_units<CharT>` facet associated
6079 to the `ios` or a new instance of `__time_point_units_default<CharT>`.
6080
6081 __returns s, iterator pointing immediately after the last character produced.
6082
6083 [endsect]
6084
6085 [endsect]
6086
6087 [endsect] [/section:time_point_put_hpp]
6088
6089 [/==================================================================]
6090 [section:time_point_units_hpp Header `<boost/chrono/io/time_point_units.hpp>`]
6091 [/==================================================================]
6092
6093 namespace boost {
6094 namespace chrono {
6095 template <typename CharT, typename Clock, typename TPUFacet>
6096 std::basic_string<CharT> get_epoch_custom(Clock, TPUFacet& f);
6097 template <typename CharT=char>
6098 class time_point_units;
6099 template <typename CharT=char>
6100 class time_point_units_default,
6101 }
6102 }
6103
6104 [section:get_epoch_custom Template Function `get_epoch_custom`]
6105
6106 template <typename CharT, typename Clock, typename TPUFacet>
6107 std::basic_string<CharT> get_epoch_custom(Clock, TPUFacet& f);
6108
6109
6110 Customization point to the epoch associated to the clock `Clock`
6111 The default calls `f.do_get_epoch(Clock())`.
6112
6113 The user can overload this function.
6114
6115
6116 __returns Forwards the call to the facet as if
6117
6118 return f.do_get_epoch(Clock());
6119
6120
6121 [endsect]
6122 [//////////////////////////////////////////////////////////]
6123 [section:time_point_units Template Class `time_point_units`]
6124
6125
6126 __time_point_units facet gives useful information about the time_point pattern,
6127 the text associated to a time_point's epoch,
6128
6129 template <typename CharT=char>
6130 class time_point_units: public std::locale::facet
6131 {
6132 public:
6133 typedef CharT char_type; // Type of character the facet is instantiated on.
6134 typedef std::basic_string<char_type> string_type; // Type of character string used by member functions.
6135 static std::locale::id id; // Unique identifier for this type of facet.
6136
6137 explicit time_point_units(size_t refs = 0);
6138
6139 virtual string_type get_pattern() const =0;
6140 template <typename Clock>
6141 string_type get_epoch() const;
6142
6143 protected:
6144 virtual ~time_point_units();
6145 virtual string_type do_get_epoch(system_clock) const=0;
6146 virtual string_type do_get_epoch(steady_clock) const=0;
6147
6148 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
6149 virtual string_type do_get_epoch(process_real_cpu_clock) const=0;
6150 virtual string_type do_get_epoch(process_user_cpu_clock) const=0;
6151 virtual string_type do_get_epoch(process_system_cpu_clock) const=0;
6152 virtual string_type do_get_epoch(process_cpu_clock) const=0;
6153 #endif
6154 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
6155 virtual string_type do_get_epoch(thread_clock) const=0;
6156 #endif
6157
6158 };
6159
6160
6161 [section:c Constructor `time_point_units()`]
6162
6163 explicit time_point_units(size_t refs = 0);
6164
6165 Construct a __time_point_units facet.
6166
6167 __params
6168
6169 * [param refs] references
6170
6171 __effects Construct a __time_point_units facet.
6172 If the `refs` argument is `0` then destruction of the object is
6173 delegated to the locale, or locales, containing it. This allows
6174 the user to ignore lifetime management issues. On the other had,
6175 if `refsv is `1` then the object must be explicitly deleted;
6176 the locale will not do so. In this case, the object can be
6177 maintained across the lifetime of multiple locales.
6178
6179 [endsect]
6180
6181 [section:get_pattern Member Function `get_pattern()`]
6182
6183 virtual string_type get_pattern() const =0;
6184
6185 __returns the pattern to be used by default.
6186
6187 [endsect]
6188
6189 [section:get_epoch Member Function `get_epoch()`]
6190
6191 template <typename Clock>
6192 string_type get_epoch() const;
6193
6194 __returns the epoch associated to the clock `Clock` as if `return get_epoch_custom<CharT>(Clock(), *this);
6195 `
6196
6197 [endsect]
6198
6199 [section:d Destructor `time_point_units()`]
6200
6201 virtual ~time_point_units();
6202
6203 Destroy the facet.
6204
6205 [endsect]
6206
6207 [section:do_get_epoch_system_clock Member Function `do_get_epoch(system_clock)`]
6208
6209 virtual string_type do_get_epoch(system_clock) const=0;
6210
6211 __params
6212
6213 * [param c] a dummy instance of __system_clock.
6214
6215 __returns The epoch string associated to the __system_clock.
6216
6217 [endsect]
6218
6219 [section:do_get_epoch_steady_clock Member Function `do_get_epoch(steady_clock)`]
6220
6221 virtual string_type do_get_epoch(steady_clock) const=0;
6222
6223 __params
6224
6225 * [param c] a dummy instance of __steady_clock.
6226
6227 __returns The epoch string associated to the __steady_clock.
6228
6229 [endsect]
6230
6231 [section:do_get_epoch_process_real_cpu_clock Member Function `do_get_epoch(process_real_cpu_clock)`]
6232
6233 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
6234 virtual string_type do_get_epoch(process_real_cpu_clock) const=0;
6235 #endif
6236
6237 __params
6238
6239 * [param c] a dummy instance of __process_real_cpu_clock.
6240
6241 __returns The epoch string associated to the __process_real_cpu_clock.
6242
6243 [endsect]
6244
6245 [section:do_get_epoch_process_user_cpu_clock Member Function `do_get_epoch(process_user_cpu_clock)`]
6246
6247 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
6248 virtual string_type do_get_epoch(process_user_cpu_clock) const=0;
6249 #endif
6250
6251 __params
6252
6253 * [param c] a dummy instance of __process_real_cpu_clock.
6254
6255 __returns The epoch string associated to the process_user_cpu_clock.
6256
6257 [endsect]
6258
6259 [section:do_get_epoch_process_system_cpu_clock Member Function `do_get_epoch(process_system_cpu_clock)`]
6260
6261 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
6262 virtual string_type do_get_epoch(process_system_cpu_clock) const=0;
6263 #endif
6264
6265 __params
6266
6267 * [param c] a dummy instance of __process_system_cpu_clock.
6268
6269 __returns The epoch string associated to the process_user_cpu_clock.
6270
6271 [endsect]
6272
6273 [section:do_get_epoch_process_process_cpu_clock Member Function `do_get_epoch(process_cpu_clock)`]
6274
6275 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
6276 virtual string_type do_get_epoch(process_cpu_clock) const=0;
6277 #endif
6278
6279 __params
6280
6281 * [param c] a dummy instance of __process_cpu_clock.
6282
6283 __returns The epoch string associated to the process_cpu_clock.
6284
6285 [endsect]
6286
6287 [section:do_get_epoch_process_thread_clock Member Function `do_get_epoch(thread_clock)`]
6288
6289 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
6290 virtual string_type do_get_epoch(thread_clock) const=0;
6291 #endif
6292
6293 __params
6294
6295 * [param c] a dummy instance of __thread_clock.
6296
6297 __returns The epoch string associated to the __thread_clock.
6298
6299 [endsect]
6300
6301
6302 [endsect]
6303 [section:time_point_units_default Template Class `time_point_units_default`]
6304
6305 // This class is used to define the strings for the default English
6306 template <typename CharT=char>
6307 class time_point_units_default: public time_point_units<CharT>
6308 {
6309 public:
6310 typedef CharT char_type; // Type of character the facet is instantiated on.
6311 typedef std::basic_string<char_type> string_type; // Type of character string used by member functions.
6312
6313 explicit time_point_units_default(size_t refs = 0);
6314 ~time_point_units_default();
6315
6316 /**
6317 * __returns the default pattern "%d%e".
6318 */
6319 string_type get_pattern() const;
6320
6321 protected:
6322 /**
6323 * [param c a dummy instance of __system_clock.
6324 * __returns The epoch string returned by `clock_string<system_clock,CharT>::since()`.
6325 */
6326 string_type do_get_epoch(system_clock ) const;
6327 /**
6328 * [param c a dummy instance of __steady_clock.
6329 * __returns The epoch string returned by `clock_string<steady_clock,CharT>::since()`.
6330 */
6331 string_type do_get_epoch(steady_clock ) const;
6332 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
6333 /**
6334 * [param c a dummy instance of __process_real_cpu_clock.
6335 * __returns The epoch string returned by `clock_string<process_real_cpu_clock,CharT>::since()`.
6336 */
6337 string_type do_get_epoch(process_real_cpu_clock ) const;
6338 /**
6339 * [param c a dummy instance of __process_user_cpu_clock.
6340 * __returns The epoch string returned by `clock_string<process_user_cpu_clock,CharT>::since()`.
6341 */
6342 string_type do_get_epoch(process_user_cpu_clock ) const;
6343 /**
6344 * [param c a dummy instance of __process_system_cpu_clock.
6345 * __returns The epoch string returned by `clock_string<process_system_cpu_clock,CharT>::since()`.
6346 */
6347 string_type do_get_epoch(process_system_cpu_clock ) const;
6348 /**
6349 * [param c a dummy instance of __process_cpu_clock.
6350 * __returns The epoch string returned by `clock_string<process_cpu_clock,CharT>::since()`.
6351 */
6352 string_type do_get_epoch(process_cpu_clock ) const;
6353
6354 #endif
6355 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
6356 /**
6357 * [param c a dummy instance of __thread_clock.
6358 * __returns The epoch string returned by `clock_string<thread_clock,CharT>::since()`.
6359 */
6360 string_type do_get_epoch(thread_clock ) const;
6361 #endif
6362
6363 };
6364
6365 [endsect]
6366 [endsect] [/section:time_point_units_hpp]
6367
6368
6369 [/==================================================================]
6370 [section:time_point_io_hpp Header `<boost/chrono/io/time_point_io.hpp>`]
6371 [/==================================================================]
6372
6373
6374 namespace boost {
6375 namespace chrono {
6376
6377
6378 // manipulators
6379
6380 unspecified __time_fmt1(timezone tz);
6381 template<class CharT>
6382 unspecified __time_fmt2(timezone tz, basic_string<CharT> f);
6383 template<class CharT>
6384 unspecified __time_fmt2(timezone tz, const CharT* f);
6385
6386 // i/o state savers
6387
6388 template<typename CharT = char, typename Traits = std::char_traits<CharT> >
6389 struct __timezone_io_saver
6390 {
6391 typedef std::basic_ios<CharT, Traits> state_type;
6392 typedef timezone aspect_type;
6393
6394 explicit __timezone_io_saver__c1(state_type &s);
6395 __timezone_io_saver__c2(state_type &s, aspect_type new_value);
6396 __timezone_io_saver__d();
6397 void timezone_io_saver__restore();
6398 };
6399
6400 template<typename CharT = char, typename Traits = std::char_traits<CharT> >
6401 struct __time_fmt_io_saver
6402 {
6403 typedef std::basic_ios<CharT, Traits> state_type;
6404
6405 explicit time_fmt_io_saver(state_type &s);
6406 time_fmt_io_saver(state_type &s, basic_string<CharT> const& new_value);
6407 ~ time_fmt_io_saver();
6408 void restore();
6409 };
6410
6411 // system_clock I/O
6412
6413 template <class CharT, class Traits, class __Duration>
6414 basic_ostream<CharT, Traits>&
6415 operator<<(basic_ostream<CharT, Traits>& os,
6416 const time_point<system_clock, __Duration>& tp);
6417
6418 template <class CharT, class Traits, class __Duration>
6419 basic_istream<CharT, Traits>&
6420 operator>>(basic_istream<CharT, Traits>& is,
6421 time_point<system_clock, __Duration>& tp);
6422
6423 // Other Clocks I/O
6424
6425 template <class CharT, class Traits, class __Clock, class __Duration>
6426 std::basic_ostream<CharT, Traits>&
6427 operator<<(std::basic_ostream<CharT, Traits>& os,
6428 const time_point<__Clock, __Duration>& tp);
6429
6430 template <class CharT, class Traits, class __Clock, class __Duration>
6431 std::basic_istream<CharT, Traits>&
6432 operator>>(std::basic_istream<CharT, Traits>& is,
6433 time_point<__Clock, __Duration>& tp);
6434
6435 }
6436 }
6437
6438
6439
6440 [section:manip I/O Manipulators]
6441 [section:time_fmt1 Non Member Function `time_fmt(__timezone)` ]
6442
6443 unspecified time_fmt(__timezone tz);
6444
6445 __returns: An unspecified object that when streamed to a `basic_ostream<CharT, Traits>` or `basic_istream<CharT, Traits>` `s` will have the effects of:
6446
6447 __set_timezone(s, tz);
6448
6449 [endsect]
6450
6451 [section:time_fmt2 Non Member Function `time_fmt(__timezone, string)` ]
6452
6453 template<class CharT>
6454 unspecified time_fmt(timezone tz, basic_string<CharT> f);
6455 template<class CharT>
6456 unspecified time_fmt(timezone tz, const CharT* f);
6457
6458 __returns: An unspecified object that when streamed to a `basic_ostream<CharT, Traits>` or `basic_istream<CharT, Traits>` `s` will have the effects of:
6459
6460 __set_timezone(s, tz);
6461 __set_time_fmt<CharT>(s, f);
6462
6463 [endsect]
6464 [endsect]
6465
6466
6467
6468 [section:streams I/O Streams Operations]
6469
6470 [section:system_clock `system_clock`]
6471
6472 [/warning
6473
6474 The time_point<system_clock,D> formatter/parser specializations don't work yet. It has been disable defining `BOOST_CHRONO_DONT_PROVIDE_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT` until a fix for the following ticket is found:
6475
6476 - [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile
6477
6478 - [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile
6479
6480 In this case the io operators behave like any time_point as if the specialization was removed.
6481
6482 In order to enable this features on compilers working with, you will need to define `BOOST_CHRONO_PROVIDES_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT`.
6483
6484 ]
6485
6486 [section:op_out Non Member Function `operator<<()`]
6487
6488 template <class CharT, class Traits, class __Duration>
6489 std::basic_ostream<CharT, Traits>&
6490 operator<<(std::basic_ostream<CharT, Traits>& os,
6491 const time_point<system_clock, __Duration>& tp);
6492
6493 __effects Behaves as a formatted output function. After constructing a `sentry` object, if the `sentry` converts to
6494 `true`, sets a local variable `tz` of type __timezone to `get_timezone(os)`.
6495 Additionally the format string obtained with `__get_time_fmt()` is recorded as a pair of `const CharT*`.
6496 If the stream has no time_punct facet, then this pair of `const CharT*` that represent an empty range.
6497
6498 Next `tp` is converted to a `time_t`, and this `time_t` is converted to a `tm`.
6499 The conversion to `tm` use `gmtime` (when available) if the timezone is __utc, else it use localtime (if available).
6500
6501 Using the `std::time_put` facet stored in `os`, this inserter writes characters to the stream using the `tm` and the
6502 formatting string stored in the `time_punct` facet, unless that facet was missing, or unless it provided an empty string.
6503
6504 If the formatting string is empty, then output as follows:
6505
6506 First output `tm` using `"%F %H:%M:"`
6507
6508 Next output a `double` representing the number of seconds stored in the `tm` plus the fractional seconds represented
6509 in `tp`. The format shall be `ios::fixed` and the precision shall be sufficient to represent `system_clock::duration`
6510 exactly (e.g. if `system_clock::period` is micro, the precision should be sufficient to output six digits following
6511 the decimal point). If the number of seconds is less than `10`, the output shall be prefixed by `'0'`.
6512
6513 Finally if `tz` is __local, output the `tm` using the pattern " %z". Else append the sequence " +0000" to the stream.
6514
6515 If any step fails, calls `os.setstate(ios_base::failbit | ios_base::badbit)`.
6516
6517 __returns `os`
6518
6519 [endsect]
6520 [section:op_in Non Member Function `operator>>()`]
6521
6522 template <class CharT, class Traits, class __Duration>
6523 std::basic_istream<CharT, Traits>&
6524 operator>>(std::basic_istream<CharT, Traits>& is,
6525 time_point<system_clock, __Duration>& tp);
6526
6527 __effects Behaves as a formatted input function. After constructing a sentry object, if the sentry converts to true,
6528 obtains a `std::time_get` facet from `is`, and obtains a formatting string in the same manner as described for
6529 insertion operator. Extract a `tm` using the supplied formatting string, or if empty, defaulted as described for the
6530 insertion operator. Note that extraction does not use the __timezone data stored in the `is` for the
6531 defaulted string as the __timezone information is stored in the stream.
6532
6533 Any `time_point<system_clock, __Duration>` inserted, and then extracted should result in an equal
6534 `time_point<system_clock, __Duration>`, excepting any precision that did not get inserted.
6535
6536 __example
6537
6538 void test(std::chrono::system_clock::time_point tp)
6539 {
6540 std::stringstream s;
6541 s << tp;
6542 boost::chrono::system_clock::time_point tp2;
6543 s >> tp2;
6544 assert(tp == tp2);
6545 }
6546
6547 __returns is
6548
6549 [endsect]
6550
6551 [endsect]
6552
6553
6554 [section:other_clocks Other Clocks]
6555 [section:op_out Non Member Function `operator<<()`]
6556
6557
6558 template <class CharT, class Traits, class __Clock, class __Duration>
6559 std::basic_ostream<CharT, Traits>&
6560 operator<<(std::basic_ostream<CharT, Traits>& os,
6561 const time_point<__Clock, __Duration>& tp);
6562
6563 __effects Behaves as a formatted output function. After constructing a `sentry` object, if the `sentry`
6564 converts to `true`, calls to `facet.put(os,os,os.fill(),tp)` where `facet` is the `time_point_put<CharT>`
6565 facet associated to `os` or a new created instance of the default `time_point_put<CharT>` facet.
6566
6567 __returns `os`.
6568
6569 __example
6570
6571 22644271279698 nanoseconds since boot
6572
6573
6574 [endsect]
6575 [section:op_in Non Member Function `operator>>()`]
6576
6577 template <class CharT, class Traits, class __Clock, class __Duration>
6578 std::basic_istream<CharT, Traits>&
6579 operator>>(std::basic_istream<CharT, Traits>& is,
6580 time_point<__Clock, __Duration>& tp);
6581
6582 Extracts `tp` from the stream `is`.
6583
6584 __effects Behaves as a formatted input function. After constructing a `sentry` object, if the `sentry`
6585 converts to `true`, calls to `facet.get(is,std::istreambuf_iterator<CharT, Traits>(), is, err, tp)` where `facet` is the `time_point_get<CharT>`
6586 facet associated to `is` or a new created instance of the default `time_point_get<CharT>` facet.
6587
6588 If any step fails, calls `os.setstate(std::ios_base::failbit | std::ios_base::badbit)`.
6589
6590 __returns `is`.
6591
6592 [endsect]
6593
6594 [endsect]
6595 [endsect]
6596
6597
6598
6599 [endsect] [/section:time_point_io_hpp Header `<boost/chrono/io/time_point_io.hpp>`]
6600
6601
6602
6603 [/
6604 [/==================================================================]
6605 [section:duration_unit_string_hpp Header `<boost/chrono/io/duration_unit_string.hpp>`]
6606 [/==================================================================]
6607
6608 namespace boost { namespace chrono {
6609
6610 template <class Period, class CharT>
6611 struct duration_period_strings
6612 {
6613 static std::basic_string<CharT> plural();
6614 static std::basic_string<CharT> singular();
6615 static std::basic_string<CharT> symbol();
6616 };
6617
6618 template <class Period, class CharT>
6619 struct duration_period
6620 {
6621 static std::basic_string<CharT> prefix(std::basic_string<CharT> const& translation);
6622 static std::basic_string<CharT> symbol();
6623 };
6624
6625 template <class CharT, class Rep, class Period>
6626 std::basic_string<CharT> duration_unit_string(
6627 bool is_prefix,
6628 duration<Rep,Period> const& d);
6629
6630 } }
6631
6632 [section:duration_period_suffix Template Class `duration_period_suffix<>`]
6633
6634 [endsect]
6635
6636 [section: duration_unit_string Non Member Function `duration_unit_string()`]
6637
6638 template <class CharT, class Rep, class Period>
6639 std::basic_string<CharT> duration_unit_string(
6640 bool is_prefix,
6641 duration<Rep,Period> const& d);
6642
6643 First units are obtained from `Period::type` and stored in two `basic_string<CharT>` (e.g. singular/plural) according to the following rules:
6644
6645 * If `is_prefix` is `true`
6646
6647 * If `Period::type` is `ratio<3600>`, `singular` is set to `"hour"` and `plural` is set to `"hours"`.
6648 * Else if `Period::type` is `ratio<60>`, `singular` is set to `"minute"` and `plural ` is set to `"minutes"`.
6649 * Else if `Period::type` is `ratio<1>` `singular` is set to `"second"` and `plural ` is set to `"seconds"`.
6650 * Else `singular ` is set to `ratio_string<Period, CharT>::prefix() + "second"` and `plural ` is set to `ratio_string<Period, CharT>::prefix() + "seconds"`.
6651
6652 Finally the intermediary unit string obtained by calling __duration_prefix_translate function with the `singular`, `plural` and the duration `d` as parameters.
6653
6654 * If `is_prefix` is `true`
6655
6656 * If `Period::type` is `ratio<3600>` `symbol` is set to `"h"`.
6657 * Else if `Period::type` is `ratio<60>` `symbol` is set to `"min"`.
6658 * Else if `Period::type` is `ratio<1>` `symbol` is set to `"s"`.
6659 * Else `symbol` is set to `ratio_string<Period, CharT>::symbol() + "s"`.
6660
6661 Finally the intermediary unit string is obtained by calling duration_symbol_translate function
6662
6663 Note: The string literals above need to be converted to the correct literal type to be assigned to a `basic_string<CharT>`.
6664
6665 [endsect]
6666
6667 [endsect] [/section:duration_units_string_hpp Header `<boost/chrono/io/duration_uinit_string.hpp>`]
6668
6669 [/==================================================================]
6670 [section:translate_hpp Header `<boost/chrono/io/translate.hpp>`]
6671 [/==================================================================]
6672
6673 namespace boost { namespace chrono {
6674
6675 #if !defined BOOST_CHRONO_SPECIFIC_TRANSLATE
6676 template <class CharT, class Rep>
6677 std::basic_string<CharT> duration_prefix_translate(
6678 std::basic_string<CharT> const &singular,
6679 std::basic_string<CharT> const &plural,
6680 Rep v);
6681
6682 template <class CharT>
6683 std::basic_string<CharT> duration_symbol_translate(
6684 std::basic_string<CharT> const &symbol);
6685
6686 template <class CharT>
6687 std::basic_string<CharT> epoch_translate(
6688 std::basic_string<CharT> const &epoch);
6689
6690 #endif
6691
6692
6693 } }
6694
6695 The library provides a default implementation of these translation function if BOOST_CHRONO_SPECIFIC_TRANSLATE is not defined.
6696
6697 The user can provide its single specific implementation by ensuring that equivalent prototypes are provided before their use is needed and BOOST_CHRONO_SPECIFIC_TRANSLATE is defined.
6698
6699 Next follow the behavior of the default implementation.
6700
6701 [section:duration_prefix_translate Non Member Function `duration_prefix_translate()`]
6702
6703 template <class CharT, class Rep>
6704 std::basic_string<CharT> duration_prefix_translate(
6705 std::basic_string<CharT> const &singular,
6706 std::basic_string<CharT> const &plural,
6707 Rep r);
6708
6709 __returns If `r` is `-1` or `1` returns `singular`, else `plural`.
6710
6711 [endsect]
6712
6713 [section:duration_symbol_translate Non Member Function `duration_symbol_translate()`]
6714
6715 template <class CharT>
6716 std::basic_string<CharT> duration_symbol_translate(
6717 std::basic_string<CharT> const &symbol);
6718
6719 __returns `symbol`.
6720
6721 [endsect]
6722 [section:epoch_translate Non Member Function `epoch_translate()`]
6723
6724 template <class CharT>
6725 std::basic_string<CharT> epoch_translate(
6726 std::basic_string<CharT> const &epoch);
6727
6728 __returns `epoch`.
6729
6730 [endsect]
6731
6732 [endsect] [/section:translate_hpp Header `<boost/chrono/io/translate.hpp>`]
6733 ]
6734
6735 [endsect] [/section:io Chrono I/O]
6736
6737
6738 [section:round Chrono Rounding Utilities]
6739 [/==================================================================]
6740 [section:floor_hpp Header `<boost/chrono/floor.hpp>`]
6741 [/==================================================================]
6742
6743 namespace boost { namespace chrono {
6744 template <class To, class Rep, class Period>
6745 To floor(const duration<Rep, Period>& d);
6746 } }
6747
6748 This function round down the given parameter.
6749
6750 [endsect]
6751 [/==================================================================]
6752 [section:round_hpp Header `<boost/chrono/round.hpp>`]
6753 [/==================================================================]
6754
6755 namespace boost { namespace chrono {
6756 template <class To, class Rep, class Period>
6757 To round(const duration<Rep, Period>& d);
6758 } }
6759
6760 This function round to nearest, to even on tie the given parameter.
6761
6762
6763 [endsect]
6764 [/==================================================================]
6765 [section:ceil_hpp Header `<boost/chrono/ceil.hpp>`]
6766 [/==================================================================]
6767
6768 namespace boost { namespace chrono {
6769 template <class To, class Rep, class Period>
6770 To ceil(const duration<Rep, Period>& d);
6771 } }
6772
6773 This function round up the given parameter.
6774
6775 [endsect]
6776 [endsect]
6777
6778
6779 [section:other_clocks Other Clocks]
6780
6781 [/==================================================================]
6782 [section:process_cpu_clocks_hpp Header `<boost/chrono/process_cpu_clocks.hpp>`]
6783 [/==================================================================]
6784
6785 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.
6786
6787 Process clocks don't include the time spent by the child process.
6788
6789 #define BOOST_CHRONO_HAS_PROCESS_CLOCKS
6790
6791 namespace boost { namespace chrono {
6792
6793 class process_real_cpu_clock;
6794 class process_user_cpu_clock;
6795 class process_system_cpu_clock;
6796 class process_cpu_clock;
6797
6798 template <typename Rep>
6799 struct process_times;
6800 template <class CharT, class Traits, class Rep>
6801 std::basic_ostream<CharT, Traits>&
6802 operator<<(std::basic_ostream<CharT, Traits>& os,
6803 process_times<Rep> const& rhs);
6804
6805 template <class CharT, class Traits, class Rep>
6806 std::basic_istream<CharT, Traits>&
6807 operator>>(std::basic_istream<CharT, Traits>& is,
6808 process_times<Rep> const& rhs);
6809
6810 template <class Rep>
6811 struct duration_values<process_times<Rep> >;
6812
6813 template <class CharT>
6814 struct clock_string<process_real_cpu_clock, CharT>;
6815 struct clock_string<process_user_cpu_clock, CharT>;
6816 struct clock_string<process_system_cpu_clock, CharT>;
6817 struct clock_string<process_cpu_clock, CharT>;
6818
6819 } }
6820 namespace std {
6821 template <class Rep>
6822 class numeric_limits<boost::chrono::process_times<Rep> >;
6823 }
6824
6825 [section: BOOST_CHRONO_HAS_PROCESS_CLOCKS Macro `BOOST_CHRONO_HAS_PROCESS_CLOCKS `]
6826
6827 This macro is defined if the platform supports process clocks.
6828
6829 [endsect]
6830
6831 [section:process_real_cpu_clock Class `process_real_cpu_clock`]
6832
6833 __process_real_cpu_clock satisfy the __clock_req.
6834
6835 __process_real_cpu_clock class provides access to the real process wall-clock steady 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()`.
6836
6837 class process_real_cpu_clock {
6838 public:
6839 typedef __nanoseconds duration;
6840 typedef duration::rep rep;
6841 typedef duration::period period;
6842 typedef chrono::__time_point<process_real_cpu_clock> time_point;
6843 static constexpr bool is_steady = true;
6844
6845 static time_point now( ) noexcept;
6846 static time_point now( system::error_code & ec );
6847 };
6848
6849
6850 [endsect]
6851 [section:process_user_cpu_clock Class `process_user_cpu_clock`]
6852
6853 __process_user_cpu_clock satisfy the __clock_req.
6854
6855 __process_user_cpu_clock class provides access to the user CPU-time steady clock of the calling process. The process relative user current time can be obtained by calling `process_user_cpu_clock::now()`.
6856
6857 class process_user_cpu_clock {
6858 public:
6859 typedef __nanoseconds duration;
6860 typedef duration::rep rep;
6861 typedef duration::period period;
6862 typedef chrono::__time_point<process_user_cpu_clock> time_point;
6863 static constexpr bool is_steady = true;
6864
6865 static time_point now( ) noexcept;
6866 static time_point now( system::error_code & ec );
6867 };
6868
6869
6870 [endsect]
6871
6872 [section:process_system_cpu_clock Class `process_system_cpu_clock`]
6873
6874 __process_system_cpu_clock satisfy the __clock_req.
6875
6876 __process_system_cpu_clock class provides access to the system CPU-time steady clock of the calling process. The process relative system current time can be obtained by calling `process_system_cpu_clock::now()`.
6877
6878 class process_system_cpu_clock {
6879 public:
6880 typedef __nanoseconds duration;
6881 typedef duration::rep rep;
6882 typedef duration::period period;
6883 typedef chrono::__time_point<process_system_cpu_clock> time_point;
6884 static constexpr bool is_steady = true;
6885
6886 static time_point now( ) noexcept;
6887 static time_point now( system::error_code & ec );
6888 };
6889
6890
6891 [endsect]
6892
6893 [section:process_cpu_clock Class `process_cpu_clock`]
6894
6895 `process_cpu_clock` can be considered as a `tuple<process_real_cpu_clock, process_user_cpu_clock, process_system_cpu_clock>`.
6896
6897 `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.
6898
6899 The process relative real, user and system current time can be obtained at once by calling `process_clocks::now()`.
6900
6901 class process_cpu_clock
6902 {
6903 public:
6904 typedef process_times<nanoseconds::rep> times ;
6905
6906 typedef __duration<times, nano> duration;
6907 typedef duration::rep rep;
6908 typedef duration::period period;
6909 typedef chrono::__time_point<process_cpu_clock> time_point;
6910 static constexpr bool is_steady = true;
6911
6912 static time_point now( ) noexcept;
6913 static time_point now( system::error_code & ec );
6914 };
6915
6916 [endsect]
6917
6918 [section:times Template Class `process_times`]
6919
6920 This class is the representation of the `process_cpu_clock::duration` class. As such it needs to implements the arithmetic operators.
6921
6922 template <typename Rep>
6923 struct process_times : arithmetic<process_times<Rep>,
6924 multiplicative<process_times<Rep>, Rep,
6925 less_than_comparable<process_times<Rep> > > >
6926 {
6927 Rep real; // real (i.e wall clock) time
6928 Rep user; // user cpu time
6929 Rep system; // system cpu time
6930
6931 times();
6932 times(
6933 process_real_cpu_clock::rep r,
6934 process_user_cpu_clock::rep u,
6935 process_system_cpu_clock::rep s);
6936
6937 template <typename Rep2>
6938 explicit process_times(
6939 Rep2 r);
6940 template <typename Rep2>
6941 explicit process_times(
6942 process_times<Rep2> const& rhs);
6943 operator rep() const;
6944
6945 bool operator==(process_times const& rhs);
6946 template <typename Rep2>
6947 bool operator==(process_times<Rep2> const& rhs);
6948
6949 times operator+=(process_times const& rhs);
6950 times operator-=(process_times const& rhs);
6951 times operator*=(process_times const& rhs);
6952 times operator/=(process_times const& rhs);
6953 bool operator<(process_times const & rhs) const;
6954 };
6955
6956 [endsect]
6957
6958 [section:times_io `process_times` Input/Output]
6959
6960 template <class CharT, class Traits, class Rep>
6961 std::basic_ostream<CharT, Traits>&
6962 operator<<(std::basic_ostream<CharT, Traits>& os,
6963 process_times<Rep> const& rhs);
6964
6965 __effects Output each part separated by ';' and surrounded by '{', '}'.
6966
6967 __throws None.
6968
6969 template <class CharT, class Traits, class Rep>
6970 std::basic_istream<CharT, Traits>&
6971 operator>>(std::basic_istream<CharT, Traits>& is,
6972 process_times<Rep> const& rhs);
6973
6974 __effects overrides the value of rhs if the input stream has the format "{r;u;s}". Otherwise, set the input stream state as failbit | eofbit.
6975
6976 __throws None.
6977
6978
6979 [endsect]
6980
6981 [section:times_duration_values `duration_values` Specialization for `process_times<>`]
6982
6983 template <class Rep>
6984 struct __duration_values<process_times<Rep> >
6985 {
6986 static process_times<Rep> zero();
6987 static process_times<Rep> max();
6988 static process_times<Rep> min();
6989 };
6990
6991 The `times` specific functions `zero()`, `max()` and `min()` uses the relative functions on the representation of each component.
6992
6993 [endsect]
6994
6995 [section:clock_string_process_real_cpu_clock `clock_string<process_real_cpu_clock>` Specialization]
6996
6997 template <class CharT>
6998 struct clock_string<process_real_cpu_clock, CharT>
6999 {
7000 static std::basic_string<CharT> name();
7001 static std::basic_string<CharT> since();
7002 };
7003
7004 `clock_string<>::name()` returns "process_real_cpu_clock".
7005
7006 `clock_string<>::since()` returns " since process start-up"
7007
7008 [endsect]
7009
7010 [section:clock_string_process_user_cpu_clock `clock_string<process_user_cpu_clock>` Specialization]
7011
7012 template <class CharT>
7013 struct clock_string<process_user_cpu_clock, CharT>
7014 {
7015 static std::basic_string<CharT> name();
7016 static std::basic_string<CharT> since();
7017 };
7018
7019 `clock_string<>::name()` returns "process_user_cpu_clock".
7020
7021 `clock_string<>::since()` returns " since process start-up"
7022
7023
7024 [endsect]
7025
7026 [section:clock_string_process_system_cpu_clock `clock_string<process_system_cpu_clock>` Specialization]
7027
7028 template <class CharT>
7029 struct clock_string<process_system_cpu_clock, CharT>
7030 {
7031 static std::basic_string<CharT> name();
7032 static std::basic_string<CharT> since();
7033 };
7034
7035 `clock_string<>::name()` returns "process_system_cpu_clock".
7036
7037 `clock_string<>::since()` returns " since process start-up"
7038
7039
7040 [endsect]
7041
7042 [section:clock_string_process_cpu_clock `clock_string<process_cpu_clock>` Specialization]
7043
7044 template <class CharT>
7045 struct clock_string<process_cpu_clock, CharT>
7046 {
7047 static std::basic_string<CharT> name();
7048 static std::basic_string<CharT> since();
7049 };
7050
7051 `clock_string<>::name()` returns "process_cpu_clock".
7052
7053 `clock_string<>::since()` returns " since process start-up"
7054
7055 [endsect]
7056
7057 [section:times_numeric_limits `numeric_limits` Specialization for `process_times<>`]
7058
7059 namespace std {
7060 template <>
7061 class numeric_limits<boost::chrono::process_times<Rep>> {
7062 typedef boost::chrono::process_times<Rep> Res;
7063
7064 public:
7065 static const bool is_specialized = true;
7066 static Res min();
7067 static Res max();
7068 static Res lowest();
7069 static const int digits;
7070 static const int digits10;
7071 static const bool is_signed = false;
7072 static const bool is_integer = true;
7073 static const bool is_exact = true;
7074 static const int radix = 0;
7075 };
7076 }
7077
7078 The `process_times<Rep>` specialization functions `min()`, `max()` and `lowest()` uses the relative functions on the representation of each component.
7079
7080 Notes
7081
7082 * `min()` returns the tuple of mins.
7083 * `max()` returns the tuple of maxs.
7084 * `lowest()` returns the tuple of lowests.
7085 * `digits` is the sum of (binary) digits.
7086 * `digits10` is the sum of digits10s.
7087
7088 [endsect]
7089
7090 [endsect]
7091
7092 [/==================================================================]
7093 [section:thread_clock_hpp Header `<boost/chrono/thread_clock.hpp>`]
7094 [/==================================================================]
7095
7096 Knowing the time a thread takes to execute is useful in both test and production environments.
7097
7098 #define BOOST_CHRONO_HAS_THREAD_CLOCK
7099 #define BOOST_CHRONO_THREAD_CLOCK_IS_STEADY
7100 namespace boost { namespace chrono {
7101
7102 class thread_clock;
7103 template <class CharT>
7104 struct clock_string<thread_clock, CharT>;
7105
7106 } }
7107
7108 [section:BOOST_CHRONO_HAS_THREAD_CLOCK Macro `BOOST_CHRONO_HAS_THREAD_CLOCK`]
7109
7110 This macro is defined if the platform supports thread clocks.
7111
7112 [endsect]
7113
7114 [section:BOOST_CHRONO_THREAD_CLOCK_IS_STEADY Macro `BOOST_CHRONO_THREAD_CLOCK_IS_STEADY`]
7115
7116 This macro is defined if the platform has a thread clock. Its value is true if it is steady and false otherwise.
7117
7118 [endsect]
7119
7120 [section:thread_clock Class `thread_clock`]
7121
7122 __thread_clock satisfy the __clock_req.
7123
7124 __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()`.
7125
7126 class thread_clock {
7127 public:
7128 typedef __nanoseconds duration;
7129 typedef duration::rep rep;
7130 typedef duration::period period;
7131 typedef chrono::__time_point<thread_clock> time_point;
7132 static constexpr bool is_steady = BOOST_CHRONO_THREAD_CLOCK_IS_STEADY;
7133
7134 static time_point now( ) noexcept;
7135 static time_point now( system::error_code & ec );
7136 };
7137
7138
7139 [endsect]
7140
7141
7142 [section:clock_string_thread_clock `clock_string<thread_clock>` Specialization]
7143
7144 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
7145 template <class CharT>
7146 struct clock_string<thread_clock, CharT>
7147 {
7148 static std::basic_string<CharT> name();
7149 static std::basic_string<CharT> since();
7150 };
7151 #endif
7152
7153 `clock_string<>::name()` returns "thread_clock".
7154
7155 `clock_string<>::since()` returns " since thread start-up"
7156
7157
7158 [endsect]
7159
7160 [endsect]
7161
7162 [endsect]
7163
7164 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7165
7166 [/include stopwatches/reference.qbk]
7167 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7168
7169
7170 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7171 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7172 [/
7173 [section:deprecated Deprecated Headers]
7174
7175 See Boost.Stopwatches for similar functionality.
7176
7177 [/==================================================]
7178 [section:timer_hpp Deprecated Header `<boost/chrono/timer.hpp>`]
7179 [/==================================================]
7180
7181 This header has been deprecated, use instead <boost/chrono/stopwatch.hpp>.
7182
7183 namespace boost { namespace chrono {
7184 template <class __Clock=high_resolution_clock> class timer;
7185 typedef <see above> system_timer;
7186 #ifdef __BOOST_CHRONO_HAS_CLOCK_STEADY
7187 typedef <see above> steady_timer;
7188 #endif
7189 typedef <see above> high_resolution_timer;
7190 }}
7191
7192 [/
7193 typedef <see above> process_real_cpu_timer;
7194 typedef <see above> process_user_cpu_timer;
7195 typedef <see above> process_system_cpu_timer;
7196 ]
7197 [section:timer Template Class `timer<>`]
7198
7199 Knowing how long a part of a program takes to execute is useful in both test and production environments.
7200 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.
7201
7202 The maximum measurable elapsed time depends on the __Clock parameter. The accuracy of timings depends on the
7203 accuracy of timing information provided the __Clock, and this could varies a great deal from one clock to another.
7204
7205 template <class __Clock> class timer {
7206 public:
7207 typedef __Clock clock;
7208 typedef typename __Clock::duration duration;
7209 typedef typename __Clock::time_point time_point;
7210
7211 explicit timer( system::error_code & ec = system::throws );
7212
7213 ~timer();
7214
7215 void start( system::error_code & ec = system::throws );
7216 duration elapsed( system::error_code & ec = system::throws );
7217
7218 };
7219
7220 [endsect]
7221
7222 [section:timer_typedefs `timer` useful typedefs]
7223
7224 typedef boost::chrono::timer< boost::chrono::system_clock >
7225 system_timer;
7226 #ifdef __BOOST_CHRONO_HAS_CLOCK_STEADY
7227 typedef boost::chrono::timer< boost::chrono::steady_clock >
7228 steady_timer;
7229 #endif
7230 typedef boost::chrono::timer< boost::chrono::high_resolution_clock >
7231 high_resolution_timer;
7232
7233 [/
7234 typedef boost::chrono::timer< boost::chrono::process_real_cpu_clock > process_real_cpu_timer;
7235 typedef boost::chrono::timer< boost::chrono::process_user_cpu_clock > process_user_cpu_timer;
7236 typedef boost::chrono::timer< boost::chrono::process_system_cpu_clock > process_system_cpu_timer;
7237 ]
7238 [endsect]
7239 [endsect]
7240
7241
7242 [/==================================================================]
7243 [section:process_times_hpp Deprecated Header `<boost/chrono/process_times.hpp>`]
7244 [/==================================================================]
7245
7246 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.
7247
7248 namespace boost { namespace chrono {
7249
7250 class process_clock;
7251 typedef <see below> process_times;
7252 class process_timer;
7253 class run_timer;
7254
7255 } }
7256
7257 [section:process_clock Class `process_clock`]
7258
7259 `process_clock` doesn't satisfy the __Clock Requirements as the function now do not follows the __Clock prototype.
7260
7261 `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.
7262
7263 The process relative real, user and system current time can be obtained at once by calling `process_clock::now()`.
7264
7265
7266 class process_clock {
7267 public:
7268 typedef __nanoseconds duration;
7269 typedef duration::rep rep;
7270 typedef duration::period period;
7271 typedef chrono::__time_point<process_clock> time_point;
7272 static constexpr bool is_steady = true;
7273
7274 struct process_times;
7275 static void now( process_times & times,
7276 system::error_code & ec = system::throws );
7277 };
7278
7279 [section:process_times Class `process_times`]
7280
7281 struct process_times {
7282 process_clock::duration real; // real (i.e wall clock) time
7283 process_clock::duration user; // user cpu time
7284 process_clock::duration system; // system cpu time
7285 };
7286
7287 [endsect]
7288
7289 [endsect]
7290 [section:process_times Typedef `process_times`]
7291
7292 typedef process_clock::process_times process_times;
7293
7294 This is a synonym of process_clock::process_times included for backward compatibility.
7295
7296 [endsect]
7297
7298 [section:process_timer Class `process_timer`]
7299
7300 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.
7301
7302 `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.
7303
7304 class process_timer {
7305 public:
7306 typedef process_clock clock;
7307 typedef process_clock::duration duration;
7308 typedef process_clock::time_point time_point;
7309
7310 explicit process_timer( system::error_code & ec = system::throws );
7311
7312 ~process_timer();
7313 void start( system::error_code & ec = system::throws );
7314 void elapsed( process_times & times, system::error_code & ec = system::throws );
7315 };
7316
7317 [endsect]
7318 [section:run_timer Class `run_timer`]
7319
7320 class `run_timer` provides a complete run-time reporting package that can be invoked in a single line of code. The reporting is controlled by two parameters:
7321
7322 * format : The output format
7323 * places(precision): the number of decimal places used.
7324
7325 The default places is given by default_places and is 3.
7326
7327 The default format is "nreal %rs, cpu %cs (%p%), user %us, system %ss\\n", where
7328
7329 * `%r` : real process clock
7330 * `%u` : user process clock
7331 * `%s` : system process clock
7332 * `%c` : user+system process clock
7333 * `%p` : percentage (user+system)/real process clock
7334
7335 All the units are given using the suffix "s" following the System International d'Unites Std.
7336
7337 class run_timer : public process_timer {
7338 public:
7339 explicit run_timer( system::error_code & ec = system::throws );
7340 explicit run_timer( std::ostream & os,
7341 system::error_code & ec = system::throws );
7342
7343 explicit run_timer( const std::string & format,
7344 system::error_code & ec = system::throws );
7345 explicit run_timer( std::ostream & os, const std::string & format,
7346 system::error_code & ec = system::throws );
7347
7348 explicit run_timer( const std::string & format, int places,
7349 system::error_code & ec = system::throws );
7350 explicit run_timer( std::ostream & os, const std::string & format, int places,
7351 system::error_code & ec = system::throws );
7352
7353 explicit run_timer( int places,
7354 system::error_code & ec = system::throws );
7355 explicit run_timer( std::ostream & os, int places,
7356 system::error_code & ec = system::throws );
7357
7358 explicit run_timer( int places, const std::string & format,
7359 system::error_code & ec = system::throws );
7360 explicit run_timer( std::ostream & os, int places, const std::string & format,
7361 system::error_code & ec = system::throws );
7362
7363 ~run_timer();
7364
7365 void start( system::error_code & ec = system::throws );
7366
7367 void report( system::error_code & ec = system::throws );
7368
7369 void test_report( duration real_, duration user_, duration system_ );
7370 bool reported() const;
7371 static int default_places();
7372 };
7373
7374
7375 [endsect]
7376
7377 [endsect]
7378
7379 [endsect]
7380 ]
7381 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7382 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7383
7384 [endsect]
7385
7386
7387 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7388 [/=================]
7389 [section Appendices]
7390 [/=================]
7391
7392 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7393 [/==================================]
7394 [section:history Appendix: History]
7395 [/==================================]
7396
7397 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7398 [section [*Version 2.0.7, August 18, 2016 - 1.62] ]
7399
7400 [*Fixes:]
7401
7402 * [@http://svn.boost.org/trac/boost/ticket/11630 #11630] boost chrono documentation about boost chrono version & io API is wrong.
7403 * [@http://svn.boost.org/trac/boost/ticket/12176 #12176] Chrono without linking to Boost.System
7404 * [@http://svn.boost.org/trac/boost/ticket/12260 #12260] Bug: time_fmt does not support for wchar_t on windows
7405
7406 [endsect] [/section [*Version 2.0.7] ]
7407 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7408 [section [*Version 2.0.6, December 18, 2015 - 1.60] ]
7409
7410 [*Fixes:]
7411
7412 * [@http://svn.boost.org/trac/boost/ticket/11330 #11330] boost::chrono::duration default constructor doesn't initialize rep_
7413 * [@http://svn.boost.org/trac/boost/ticket/11618 #11618] Chrono IO V2 doc ios_state.hpp does not exist
7414 * [@http://svn.boost.org/trac/boost/ticket/11631 #11631] boost chrono io v2 does not let you support custom clocks
7415
7416 [endsect] [/section [*Version 2.0.6] ]
7417 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7418 [section [*Version 2.0.5, February 18, 2015 - 1.58] ]
7419
7420 [*Fixes:]
7421
7422 * [@http://svn.boost.org/trac/boost/ticket/10778 #10778] VC14 CTP4 Atomic don't compile with boost::chrono durations which are not TriviallyCopyable
7423 * [@http://svn.boost.org/trac/boost/ticket/10840 #10840] Missing std:: qualifier for puts call in test_7868.cpp
7424 * [@http://svn.boost.org/trac/boost/ticket/10851 #10851] Missing std:: qualifier for puts call in time_point_output.cpp
7425 * [@http://svn.boost.org/trac/boost/ticket/10893 #10893] Minor doc typo in Boost.Chrono
7426 * [@http://svn.boost.org/trac/boost/ticket/10992 #10992] Chrono IO state savers inconsistent with Boost.IO state savers
7427 * [@http://svn.boost.org/trac/boost/ticket/10995 #10995] duration_put::put_value truncates fractional part
7428 * [@http://svn.boost.org/trac/boost/ticket/11006 #11006] Impossible to instantiate time_fmt_io_saver due to several errors.
7429 * [@http://svn.boost.org/trac/boost/ticket/11012 #11012] chrono_io v2 fail to compile with boost::chrono::duration< boost::rational<int> >
7430
7431 [endsect] [/section [*Version 2.0.5] ]
7432 [section [*Version 2.0.4, July 12, 2014 - 1.56] ]
7433
7434 [*Fixes:]
7435
7436 * [@http://svn.boost.org/trac/boost/ticket/6918 #6918] Boost Chrono compilation failure on HP uX due to undefined pthread_getcpuclockid
7437 * [@http://svn.boost.org/trac/boost/ticket/8006 #8006] Boost::Chrono Assertion at startup - steady_clock::now() - Windows
7438
7439 * [@http://svn.boost.org/trac/boost/ticket/9337 #9337] chrono::process_cpu_clock time points wrong by factor 1000 on Linux
7440 * [@http://svn.boost.org/trac/boost/ticket/9342 #9342] Regression on process_cpu_clock::timepoint io on V2
7441 * [@http://svn.boost.org/trac/boost/ticket/9419 #9419] boost::chrono::floor()/round() and negative durations is wrong
7442 * [@http://svn.boost.org/trac/boost/ticket/9698 #9698] boost::chrono::thread_clock not declared in OSX
7443 * [@http://svn.boost.org/trac/boost/ticket/9720 #9720] boost::this_thread::sleep_for() sometimes returns immediately on win32
7444 * [@http://svn.boost.org/trac/boost/ticket/9859 #9859] Remove references to gcc-mingw
7445 * [@http://svn.boost.org/trac/boost/ticket/9918 #9918] chrono compilation error on Solaris, function timegm
7446 * [@http://svn.boost.org/trac/boost/ticket/9811 #9811] boost/boost/chrono/duration.hpp:355:56: error: call to non-constexpr function 'static std::numeric_limits<float>::_Ty std::numeric_limits<float>::max()' /home/zosun/input_service/inputservices-core-service/other/boost/boost/chrono/duration.hpp: In static member function 'static constexpr double boost::chrono::detail::chrono_numeric_limits<double, true>::lowest()':
7447 * [@http://svn.boost.org/trac/boost/ticket/10069 #10069] Overflow in chrono clocks on 32bit
7448 * [@http://svn.boost.org/trac/boost/ticket/10151 #10151] timegm function not available on QNX
7449
7450 [endsect] [/section [*Version 2.0.4] ]
7451
7452 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7453 [section [*Version 2.0.3, September 29, 2013 - 1.55] ]
7454
7455 [*Fixes:]
7456
7457 * [@http://svn.boost.org/trac/boost/ticket/7868 #7868] chrono_io parses time incorrectly (1.53 and 1.52)
7458 * [@http://svn.boost.org/trac/boost/ticket/9028 #9028] Typo in boost/chrono/stopwatches/formatters/base_formatter.hpp
7459 * [@http://svn.boost.org/trac/boost/ticket/9147 #9147] uninitialized std::tm
7460 * [@http://svn.boost.org/trac/boost/ticket/9274 #9274] lost of precision on system_clock input.
7461 * [@http://svn.boost.org/trac/boost/ticket/9276 #9276] output from a system_clock::time_point get a time_point that is one day later than expected.
7462
7463 [endsect] [/section [*Version 2.0.3] ]
7464
7465 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7466 [section [*Version 2.0.2, June 15, 2013 - 1.54] ]
7467
7468
7469 [*Fixes:]
7470
7471 * [@http://svn.boost.org/trac/boost/ticket/8079 #8079] Chrono memory leak
7472 * [@http://svn.boost.org/trac/boost/ticket/8318 #8318] BOOST_FORCEINLINE constructors of time_point and duration
7473 * [@http://svn.boost.org/trac/boost/ticket/8367 #8367] chrono does not compile with clang from XCode 4.5.2 with -std=c++11 -stdlib=libc++ and -arch armv7
7474 * [@http://svn.boost.org/trac/boost/ticket/8370 #8370] typo in chrono reference
7475 * [@http://svn.boost.org/trac/boost/ticket/8435 #8435] Can't compile Chrono on HP-UX due to no CLOCK_REALTIME macro.
7476 * [@http://svn.boost.org/trac/boost/ticket/8690 #8690] duration_units_default - lost return types constness in overridden methods.
7477 * [@http://svn.boost.org/trac/boost/ticket/8691 #8691] iostate is not checked after scan_keyword call.
7478 * [@http://svn.boost.org/trac/boost/ticket/8696 #8696] chrono compilation error on Solaris/gcc.
7479
7480 [endsect] [/section [*Version 2.0.2] ]
7481
7482 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7483 [section [*Version 2.0.1, January 18, 2013 - 1.53] ]
7484
7485 [*Deprecated:]
7486
7487 * The chrono i/o version included in Boost.Chrono 1.2.x has been completly refactored in version 2.0.0
7488 * chrono I/O: The manipulators __duration_short, __duration_long are deprecated. You should use the parameterized form __duration_fmt or the renamed manipulators __duration_symbol and __duration_prefix instead.
7489 * chrono I/O: The __duration_punct<> facet is deprecated. You should use the __get_duration_style free function to get the informations and use the __duration_units facet for localization purposes.
7490
7491 When BOOST_CHRONO_VERSION==2 the preceding deprecated functions are not available.
7492
7493 [*Fixes:]
7494
7495 * [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile assigned viboes Bugs Boost 1.53.0 --
7496 * [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile assigned viboes Bugs Boost 1.53.0 --
7497 * [@http://svn.boost.org/trac/boost/ticket/7868 #7868] chrono_io parses time incorrectly (1.53 and 1.52)
7498
7499
7500 [endsect] [/section [*Version 2.0.1] ]
7501
7502 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7503 [section [*Version 2.0.0, October 23, 2012 - 1.52] ]
7504
7505 [*New Features:]
7506
7507 * Enhance chrono I/O
7508 * [@http://svn.boost.org/trac/boost/ticket/5980 #5980] Enhance chrono I/O with H. Hinnant proposal [@http://home.roadrunner.com/~hinnant/bloomington/chrono_io.html proposal] which has the advantage to provide I/O for system clocks using the Gregorian Calendar.
7509 * [@http://svn.boost.org/trac/boost/ticket/5981 #5981] Add i/o state savers for duration and time_point formatting state.
7510 * [@http://svn.boost.org/trac/boost/ticket/7059 #7059] Add low level i/o facilities.
7511
7512 [*Deprecated:]
7513
7514 * The chrono i/o version included in Boost.Chrono 1.2.x has been completly refactored in version 2.0.0
7515 * chrono I/O: The manipulators __duration_short, __duration_long are deprecated. You should use the parameterized form __duration_fmt or the renamed manipulators __duration_symbol and __duration_prefix instead.
7516 * chrono I/O: The __duration_punct<> facet is deprecated. You should use the __get_duration_style free function to get the informations and use the __duration_units facet for localization purposes.
7517
7518 When BOOST_CHRONO_VERSION==2 the preceding deprecated functions are not available.
7519
7520 [*Fixes:]
7521
7522 * [@http://svn.boost.org/trac/boost/ticket/7381 #7381] C++11 compliance: unresolved symbol when assigning a constexpr duration to a non-const local variable.
7523 * [@http://svn.boost.org/trac/boost/ticket/7479 #7479] Compiles fails with compilers supporting constexpr fails if the standard library doesn't provides the constexpr interface
7524 * [@http://svn.boost.org/trac/boost/ticket/7493 #7493] compile fail on intel-linux-12.1.3.0x because of bug on explicit bool conversion
7525 * [@http://svn.boost.org/trac/boost/ticket/7542 #7542] Missing -lpthread in chrono/io tester Sandia-clang-trunk
7526
7527 [*Would not fix:]
7528
7529 * [@http://svn.boost.org/trac/boost/ticket/6871 #6871] chrono_io.hpp: operator<<(ostream& os, ...) modifies the state of os.
7530
7531 * The new io interface provided in version 2 solves this issue. You should move to the new version.
7532
7533 [*Known bugs not fixed yet:]
7534
7535 * [@http://svn.boost.org/trac/boost/ticket/7525 #7525] Wrong clock_string<system_clock>::since() on Windows
7536
7537 [/warning
7538
7539 The time_point<system_clock,D> formatter/parser specializations don't work yet. It has been disable defining `BOOST_CHRONO_DONT_PROVIDE_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT` until a fix for the following ticket is found:
7540
7541 - [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile
7542
7543 - [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile
7544
7545 In this case the io operators behave like any time_point as if the specialization was removed.
7546
7547 In order to enable this features on compilers working with, you will need to define `BOOST_CHRONO_PROVIDES_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT`.
7548
7549 ]
7550
7551 [endsect] [/section [*Version 2.0.0] ]
7552
7553 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7554 [section [*Version 1.2.3, August 1, 2012 - 1.51] ]
7555
7556 [*Fixes:]
7557
7558 * [@http://svn.boost.org/trac/boost/ticket/6918 #6918] Boost Chrono compilation failure on HP uX due to undefined pthread_getcpuclockid.
7559 * [@http://svn.boost.org/trac/boost/ticket/6241 #6241] boost::chrono compilation problems without std::wstring support.
7560 * [@http://svn.boost.org/trac/boost/ticket/6987 #6987] Documentation & C++11.
7561 * [@http://svn.boost.org/trac/boost/ticket/7041 #7041] time_point.hpp depends on Boost.System.
7562 * [@http://svn.boost.org/trac/boost/ticket/7042 #7042] Avoiding time_point and duration dependency on time.h and CLOCK_REALTIME.
7563 * [@http://svn.boost.org/trac/boost/ticket/7058 #7058] Make it work when BOOST_NO_EXCEPTIONS is defined.
7564 * [@http://svn.boost.org/trac/boost/ticket/7069 #7069] Misspellings in clock_string<thread_clock>.
7565 * [@http://svn.boost.org/trac/boost/ticket/7081 #7081] WinError.h capitalization in boost/detail/win/basic_types.hpp.
7566
7567 [endsect] [/section [*Version 1.2.3] ]
7568
7569 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7570 [section [*Version 1.2.2, April 1, 2012 - 1.50] ]
7571
7572 [*Fixes:]
7573
7574 * [@http://svn.boost.org/trac/boost/ticket/6361 #6361] integer overflow in boost::chrono::process_real_cpu_clock::now() under Windows 32bits.
7575 * [@http://svn.boost.org/trac/boost/ticket/6628 #6628] compiler warning in process_cpu_clocks.hpp.
7576 * [@http://svn.boost.org/trac/boost/ticket/6666 #6666] thread_clock.hpp needs pthread.h.
7577
7578 [endsect] [/section [*Version 1.2.2] ]
7579
7580 [section [*Version 1.2.1, February 1, 2012 - 1.49] ]
7581
7582 [*Fixes:]
7583
7584 * [@http://svn.boost.org/trac/boost/ticket/6092 #6092] Input from non integral durations makes the compiler fail.
7585 * [@http://svn.boost.org/trac/boost/ticket/6093 #6093] [1/3]second fails as valid duration input.
7586 * [@http://svn.boost.org/trac/boost/ticket/6113 #6113] duplicate symbol when BOOST_CHRONO_HEADER_ONLY is defined.
7587 * [@http://svn.boost.org/trac/boost/ticket/6243 #6243] Sandia-pgi-11.9: more than one instance of overloaded function "min" matches.
7588 * [@http://svn.boost.org/trac/boost/ticket/6257 #6257] process_cpu_clock::now() on linux gives time_points 1/1000 times.
7589
7590 [endsect] [/section [*Version 1.2.1] ]
7591
7592
7593 [section [*Version 1.2.0, October 17, 2011] ]
7594 [*New Features:]
7595
7596 * [@http://svn.boost.org/trac/boost/ticket/5979 #5979] Added chrono rounding utilities as defined By Howard Hinnant [@http://home.roadrunner.com/~hinnant/duration_io/chrono_util.html here].
7597 * [@http://svn.boost.org/trac/boost/ticket/5978 #5978] Added BOOST_CHRONO_HAS_PROCESS_CLOCKS to know if process clocks are available.
7598 * [@http://svn.boost.org/trac/boost/ticket/5998 #5998] Make possible to don't provide hybrid error handling.
7599 * [@http://svn.boost.org/trac/boost/ticket/5906 #5906] Take in account the constexpr as defined in the standard.
7600 * [@http://svn.boost.org/trac/boost/ticket/5907 #5907] Take in account noexcept for compilers supporting it.
7601
7602 [*Fixes:]
7603
7604 * [@http://svn.boost.org/trac/boost/ticket/2114 #2114] Enable visibility support (Boost.Chorno part)
7605 * [@http://svn.boost.org/trac/boost/ticket/5669 #5669] Intel compiler failure to compile duration.hpp
7606 * [@http://svn.boost.org/trac/boost/ticket/5909 #5909] process_cpu_clock::now() on MAC gives time_points 1/1000 times.
7607 * [@http://svn.boost.org/trac/boost/ticket/5946 #5946] Process real cpu clock returns the system steady clock (windows).
7608 * [@http://svn.boost.org/trac/boost/ticket/5974 #5974] Process real cpu clock should use clock() instead of times() in MAC which is twice faster and have better resolution.
7609
7610 [*Cleanup:]
7611
7612 * [@http://svn.boost.org/trac/boost/ticket/5975 #5975] Reduce the combinations of header-only, shared, static link to reduce test time by 50%.
7613 * [@http://svn.boost.org/trac/boost/ticket/5976 #5976] chrono_accuracy_test is not deterministic and should be removed from the regression tests
7614 * [@http://svn.boost.org/trac/boost/ticket/5977 #5977] Remove old files from Beman's version. Some old files included in the Beman's version and not documented in the reviewed version that have been definitely removed from the repository as
7615 * boost/chrono/timer.hpp,
7616 * boost/chrono/process_times.hpp
7617 * boost/chrono/detail/process_clock.hpp,
7618 * boost/chrono/detail/mac/process_clock.hpp,
7619 * boost/chrono/detail/posix/process_clock.hpp,
7620 * boost/chrono/detail/win/process_clock.hpp,
7621 * boost/chrono/detail/run_timer.hpp,
7622 * boost/chrono/detail/run_timer_static.hpp,
7623
7624
7625
7626 [endsect] [/section [*Version 1.2.0] ]
7627
7628
7629 [section [*Version 1.1.0, Mars 17, 2011] ]
7630
7631 [*New Features:]
7632
7633 * [@http://svn.boost.org/trac/boost/ticket/???? #????] Added time_point unary operators +,-,++,-- and binary operators +=,-= with Rep al RHS.
7634 * [@http://svn.boost.org/trac/boost/ticket/5323 #5323] Add Associated type difference_type for chrono::time_point.
7635
7636 [*Fixes:]
7637
7638 * [@http://svn.boost.org/trac/boost/ticket/5322 #5322] Explicit default constructed chrono::durations are uninitialized
7639
7640
7641 [endsect] [/section [*Version 1.1.0] ]
7642
7643 [section [*Version 1.0.0, January 6, 2011] ]
7644
7645 * Moved chrono to trunk taking in account the review remarks.
7646 * Documentation revision.
7647
7648 [*Features:]
7649
7650 * Boost_Chrono is now a configurable header-only library version (that also allows the user to choose if the `windows.h` file is included or not).
7651 * Added clock_string<> traits.
7652 * Define chrono-io for all the clocks.
7653 * Add input of process_times representation.
7654
7655 [*Implementation:]
7656
7657 * Use of detail/win files to avoid the use of windows.h file.
7658 * Completed the error_code handling.
7659 * Works now with BOOST_SYSTEM_NO_DEPRECATED.
7660
7661 [*Fixes:]
7662
7663 * Fix some warnings.
7664 * Fix original errors on Mac
7665 * Don't fix the link with boost_system to static.
7666
7667 [*Test:]
7668
7669 * Added test on process and thread clocks.
7670 * Moved to lightweight_test.hpp.
7671 * Able to test multiple configurations.
7672
7673 [*Doc:]
7674
7675 * Removed some not useful parts as the test and the tickets.
7676
7677 [endsect] [/section [*Version 1.0.0] ]
7678
7679 [/
7680 [section [*Version 0.6.0, September 22, 2010] ]
7681
7682 [*Features:]
7683
7684 * Added experimental chrono_io.
7685
7686 [*Fixes:]
7687
7688 * Fix duration values min implementation.
7689 * Fix some warnings
7690
7691 [*Test:]
7692
7693 * Adapted test from libc++/chrono
7694
7695 [endsect]
7696
7697 [section [*Version 0.5.0, September 10, 2010] ]
7698
7699 [*Features:]
7700
7701 * Stopwatches, Ratio and CommonType have been moved to separated libraries: Boost.Stopwatches, Boost.Ratio and Boost.TypeTraits.
7702
7703 [endsect]
7704
7705 [section [*Version 0.4.7, September 1, 2010] ]
7706
7707 [*New Features:]
7708
7709 * Added __lightweight_stopwatch__.
7710
7711 [endsect]
7712
7713 [section [*Version 0.4.6, August 28, 2010] ]
7714
7715 [*New Features:]
7716
7717 * Implementation of __common_type without using Boost.TypeOf.
7718 * Added __stopwatch_accumulator_time_formatter__ class.
7719
7720 [*Old Features:]
7721
7722 * Type reporter removed from Stopwatches as well as the get_reporter metafunction.
7723
7724 [*Bug Fixes]
7725
7726 * __process_cpu_clock is now a valid model of __Clock that can be used with __stopclocks_accumulator__.
7727 * eliminate or suppress a lot of warnings appearing with warnings=all -Wextra
7728 * improve the error code handling
7729
7730 [endsect]
7731
7732 [section [*Version 0.4.5, July 6, 2010] ['Documentation update]]
7733
7734 [*Documentation]
7735
7736 * Overview rewriting
7737 * Added missing __thread_clock reference.
7738 * How to implement a __thread_clock tutorial removed.
7739 * References section renamed to External Resources.
7740 * Added links to source examples.
7741 * Added links between Models and Concepts.
7742 * Added macros descriptions.
7743 * Cleanup.
7744
7745 [*Bug Fixes]
7746
7747 * Valgrind fixes: "Conditional jump or move depends on uninitialised value(s)"
7748 * Take care of Boost.System break on version 1.44
7749 * gcc.4.4 "warning: suggest parentheses around '&&' within '||' " removal.
7750
7751 [endsect]
7752
7753 [section [*Version 0.4.4, February 22, 2010] [' Warning fixes]]
7754
7755 [*Bug Fixes]
7756
7757 * `scoped_suspend` warning removal
7758 * `error_code` management completed
7759
7760 [endsect]
7761
7762 [section [*Version 0.4.3, June 18, 2010] ['Missing file fixe]]
7763
7764 [*Bug Fixes]
7765
7766 * boost/thread/detail/cv_status.hpp file was not committed.
7767
7768 [endsect]
7769
7770 [section [*Version 0.4.2, June 18, 2010] ['Packaging fixe]]
7771
7772 * Boost.Conversion library, used by Boost.Thread porting to Boost.Chrono was not packaged.
7773
7774 [endsect]
7775
7776 [section [*Version 0.4.1, June 17, 2010] ['Added thread clock implementation on Windows]]
7777
7778 [*New Features:]
7779
7780 * Added __thread_clock implementation on Windows.
7781 * Added *Boost.Thread* using *Boost.Chrono*.
7782
7783 [endsect]
7784
7785 [section [*Version 0.4, February 28, 2010] ['New thread clock and Suspendible clock ]]
7786
7787 [*New Features:]
7788
7789 * __SuspendibleClock__ concept + template class _suspendible_clock__.
7790 * Added `scope_suspend` which do `suspend`/`resume` if the __Clock is a model of __SuspendibleClock__ concept, and nothing otherwise.
7791 * __thread_clock support on platforms providing it natively.
7792 * Added support for wide character for __stopwatch_reporter, `stopclock`, and `stopclock_accumulator`.
7793 * `digital_time` renamed `t24_hours`.
7794
7795 [*Perf]
7796
7797 Added performances measures.
7798
7799 [*Bug Fixes]
7800
7801 * Bug on timeval_demo.
7802
7803 time_point t(duration(xtime(0))); // this was taken as a function declaration
7804 gettimeofday((timeval*)&t, 0);
7805 return t;
7806 by
7807
7808 timeval tv;
7809 gettimeofday(&tv, 0);
7810 xtime xt( tv.tv_sec, tv.tv_usec);
7811 return time_point(duration(xt));
7812
7813 * Bug on run_timer_test (add a global variable to avoid optimization that removes completely the code to be measured
7814
7815 [endsect]
7816
7817 [section [*Version 0.3.2, January 25, 2010] ['New frequency, lifetime and percentage stopwatch_accumulator features]]
7818 [*Features:]
7819
7820 * Added overloading for `operator/(Integer/Duration)`
7821 * Added frequency, lifetime and percentage to the default `stopwatch_accumulator_formatter`.
7822
7823 [*Bug Fixes]
7824 * Specific formatters didn't work completely.
7825 * Replace `duration(0)` by `duration::zero()` on template classes.
7826 * `suspend` doesn't works: `partial_` not initialized neither taken in account by the elapsed function.
7827
7828 [endsect]
7829
7830 [section [*Version 0.3.1, January 20, 2010] ['New support for wide characters]]
7831 [*Features:]
7832
7833 * Support for wide characters on formatters and stopclocks
7834 * added `chrono.hpp` and `stopwatches.hpp` at the boost level
7835
7836
7837 [endsect]
7838
7839 [section [*Version 0.3.0, January 17, 2010] ['New stopwatch/stopclock feature + Bug fixes]]
7840 [*Features:]
7841
7842 * Added independent process cpu clocks for real, user, system process CPU time
7843 * Added global process cpu clock for real, user, system process CPU time
7844 * Added `digital_time` (looking for a better name)
7845 * Added new __Stopwatch__ concept measuring elapsed time between different points in time associated to the operations `start`, `stop`, `suspend` and `resume`.
7846 * Added __stopwatch__ is a model __Stopwatch__ measuring the elapsed time between the `start` and the `stop` operations.
7847 * Added __laps_stopwatch is a model __Stopwatch__ allowing to accumulate several time samples and gives the average, ...
7848 * Added scoped helper classes allowing to pairwise `start`/`stop` operations, `suspend`/`resume` and `resume`/`suspend` a __Stopwatch__.
7849 * Added new stopwatch __Formatter__ concept
7850 * Added stopwatch formatter "%ds\\n"
7851 * Added stopwatch accumulator formatter "%c times, sum=%ss, min=%ms, max=%Ms, mean=%as\\n"
7852 * Added time formatter "real %rs, cpu %cs (%p%), user %us, system %ss\\n"
7853 * Added digital_time formatter "%d days(s) %h:%m:%s.%n\\n"
7854 * __stopwatch_reporter is a convenient generic class reporting elapsed time for the Stopwatch concept.
7855 * Added `stopclock<__Clock>` shortcut `stopwatch_reporter<stopwatch<__Clock>>`
7856 * Added __scoped_stopclock__ which trace at the constructor and destructor.
7857 * Added `typeof` registration for classes __duration and __time_point
7858
7859 * The old classes `process_times`, `process_clock`, `process_timer`, `timer` and `run_timer` are deprecated as the preceding additions are more generic. However for backward compatibility they preserved until inclusion of the library in Boost. Next follows the equivalences:
7860 * `timer<>` ~ `stopwatch<>`
7861 * `process_timer` ~ `stopwatch<process_cpu_clock>`
7862 * `run_timer` ~ `stopclock<>`
7863
7864 [*Bug Fixes]
7865
7866 * Try to correct warning "C4251: 'boost::chrono::run_timer::m_format' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'boost::chrono::run_timer'", by don't including inline functions using the std::string `m_format`.
7867
7868 [endsect]
7869
7870 [section [*Version 0.2.1, December 13, 2009] ['Bug fixes]]
7871
7872 [*Bug Fixes]
7873
7874 * Replace `INTMAX_C` by `BOOST_INTMAX_C` until `boost/cstdint.hpp` ensures `INTMAX_C` is always defined.
7875 * Define __BOOST_CHRONO_HAS_CLOCK_STEADY__ when `BOOST_CHRONO_WINDOWS_API`
7876 * Commenting invalid operator declarations
7877 * Take care of Boost `min`/`max` recommendations
7878 * Complete qualification when defining nested typedef duration on clocks to avoid the following compile error:
7879
7880 ./boost/chrono/chrono.hpp:945: error: declaration of 'typedef class boost::chrono::duration<long long int, boost::__ratio<1ll, 10000000ll> > boost::chrono::system_clock::duration'
7881 ./boost/chrono/chrono.hpp:458: error: changes meaning of 'duration' from 'class boost::chrono::duration<long long int, boost::__ratio<1ll, 10000000ll> >'
7882
7883 * cleanup of simulated...
7884 * warning removal on `posix/process_clock.cpp`.
7885 * disable VC++ foolishness.
7886 * Update Jamfiles to manage with dll.
7887 * removal of conversion warning in test_duration.
7888 * manage with MSVC reporting a warning instead of an error when there is an integral constant overflow.
7889 * Use `STATIC_ASSERT` specific macro to solve the compile failing issue.
7890 * Qualify with `boost::detail` `boost::chrono::detail` to avoid ambiguities with MSVC.
7891
7892
7893 [*Documentation:]
7894
7895 More updated documentation.
7896
7897 [endsect]
7898
7899 [section [*Version 0.2.0, December 8, 2009] ['+ Features + Bug fixes + Updated documentation]]
7900
7901 [*Features:]
7902
7903 * Added __ratio construction and assignment from an equivalent __ratio ([@http://home.roadrunner.com/~hinnant/issue_review/lwg-active.html#1281 [*LWG 1281. CopyConstruction and Assignment between ratios having the same normalized form]])
7904 * Added nested __ratio typedef type ([@http://home.roadrunner.com/~hinnant/issue_review/lwg-active.html#1281 [*LWG 1281. CopyConstruction and Assignment between ratios having the same normalized form]])
7905 * Added __BOOST_CHRONO_HAS_CLOCK_STEADY__ macro to state if __steady_clock is provided on this platform.
7906 * Added __duration `operator%` ([@http://home.roadrunner.com/~hinnant/issue_review/lwg-defects.html#934 [*LGW 934. duration is missing operator%]])
7907 * Added constexpr when constexpr should be used.
7908 * Complete __duration `operator*` and `operator/`.
7909
7910
7911 [*Implementation:]
7912
7913 * Use `INTMAC_C` to name `intmax_t` constants instead of `LL`.
7914 * Separate `chrono.cpp` on # files `win/chrono.cpp`, `mac/chrono.cpp` and `posix/chrono.cpp` to make easier the maintenance on different platforms.
7915 * Separate `process_clock.cpp` on # files `win/process_clock.cpp`, `mac/process_clock.cpp` and `posix/process_clock.cpp` to make easier the maintenance on different platforms.
7916 * Added the `error_code` prototype for `steady_clock::now` for `mac/chrono.cpp`.
7917 * Fully implement `mac/chrono.cpp` with error handling.
7918 * Take care on POSIX systems when `CLOCK_STEADY` is not defined.
7919
7920 [*Documentation:]
7921
7922 * The documentation is written now using quick-book using as base [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]] .
7923
7924 [*Bug Fixes]
7925
7926 * `operator/` was ambiguous: Disambiguate duration `operator/`.
7927 * `CLOCK_STEADY` is not defined with cygwin/gcc 3.4: Disable code when __BOOST_CHRONO_HAS_CLOCK_STEADY__ is not defined.
7928 * result of metafunctions `ratio_multiply` and `ratio_divide` were not normalized ratios: Use of the nested __ratio typedef type on __ratio arithmetic operations.
7929 * Copy constructor from similar __duration masked the defaulted operations: Added duration defaulted implementations
7930
7931
7932 [endsect]
7933 [section [*Version 0.1.0, April 29, 2009] ['Beman's boostified version Chrono]]
7934
7935 [*Features:]
7936
7937 * The C++11 Standard Library's __common_type.
7938 * The C++11 Standard Library's compile-time rational arithmetic.
7939 * The C++11 Standard Library's time utilities, including:
7940 * Class template __duration
7941 * Class template __time_point
7942 * Clocks:
7943 * __system_clock
7944 * __steady_clock
7945 * `high_resolution_clock`
7946
7947 * Class template timer, with typedefs:
7948 * `system_timer`
7949 * `steady_timer`
7950 * `high_resolution_timer`
7951
7952 * Process clocks and timers:
7953 * `process_clock`, capturing real, user-CPU, and system-CPU times.
7954 * `process_timer`, capturing elapsed real, user-CPU, and system-CPU times.
7955 * `run_timer`, convenient reporting of process_timer results.
7956
7957
7958 [endsect]
7959 ]
7960 [endsect]
7961
7962 [/======================================]
7963 [section:rationale Appendix: Rationale]
7964
7965 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. This section contains some extracts from this document.
7966
7967 [heading Why duration needs operator%]
7968
7969 This operator is convenient for computing where in a time frame a given duration lies. A motivating example is converting a duration into a "broken-down" time duration such as hours::minutes::seconds:
7970
7971 class ClockTime
7972 {
7973 typedef boost::chrono::hours hours;
7974 typedef boost::chrono::minutes minutes;
7975 typedef boost::chrono::seconds seconds;
7976 public:
7977 hours hours_;
7978 minutes minutes_;
7979 seconds seconds_;
7980
7981 template <class Rep, class Period>
7982 explicit ClockTime(const boost::chrono::duration<Rep, Period>& d)
7983 : hours_ (boost::chrono::duration_cast<hours> (d)),
7984 minutes_(boost::chrono::duration_cast<minutes>(d % hours(1))),
7985 seconds_(boost::chrono::duration_cast<seconds>(d % minutes(1)))
7986 {}
7987 };
7988
7989 [endsect]
7990
7991
7992 [/======================================================]
7993 [section:implementation Appendix: Implementation Notes]
7994
7995 [heading Which APIs have been chosen to implement each clock on each platform?]
7996
7997 The following table presents a resume of which API is used for each clock on each platform
7998 [table Clock API correspondence
7999 [[Clock] [Windows Platform] [Posix Platform] [Mac Platform] ]
8000 [[__system_clock] [GetSystemTimeAsFileTime] [clock_gettime( CLOCK_REALTIME)] [gettimeofday] ]
8001 [[__steady_clock] [QueryPerformanceCounter and QueryPerformanceFrequency]
8002 [clock_gettime( CLOCK_STEADY)] [mach_timebase_info,mach_absolute_time] ]
8003 [[__process_real_cpu_clock] [GetProcessTimes] [times] [times] ]
8004 [[__process_system_cpu_clock] [GetProcessTimes] [times] [times] ]
8005 [[__process_user_cpu_clock] [GetProcessTimes] [times] [times] ]
8006 [[__process_cpu_clock] [GetProcessTimes] [times] [times] ]
8007 [[__thread_clock] [GetThreadTimes] [clock_gettime(pthread_getcpuclockid)] [clock_gettime(pthread_getcpuclockid)] ]
8008 ]
8009
8010 [endsect]
8011
8012 [/======================================================]
8013 [section:faq Appendix: FAQ]
8014
8015 [heading Why does process_cpu_clock sometimes give more cpu seconds than real seconds?]
8016
8017 Ask your operating system supplier. The results have been inspected with a debugger, and both for Windows and Linux, that's what the OS appears to be reporting at times.
8018
8019
8020 [heading Are integer overflows in the duration arithmetic detected and reported?]
8021
8022 [*Boost.Ratio] avoids all kind of overflow that could result of arithmetic operation and that can be simplified. The typedefs durations don't detect overflow. You will need a duration representation that handles overflow.
8023
8024 [heading Which clocks should be used to benchmarking?]
8025
8026 Each clock has his own features. It depends on what do you need to benchmark. Most of the time, you could be interested in using a thread clock, but if you need to measure code subject to synchronization a process clock would be better. If you have a multi-process application, a system-wide clock could be needed.
8027
8028 [heading Which clocks should be used for watching?]
8029
8030 For trace purposes, it is probably best to use a system-wide clock.
8031
8032 [endsect] [/section:faq Appendix: FAQ]
8033
8034 [/====================================================]
8035 [section:acknowledgements Appendix: Acknowledgements]
8036
8037 The library's code was derived from Howard Hinnant's time2_demo prototype. Many thanks to Howard for making his code available under the Boost license. The original code was modified by Beman Dawes to conform to Boost conventions.
8038
8039 time2_demo contained this comment:
8040
8041 Much thanks to Andrei Alexandrescu, Walter Brown, Peter Dimov, Jeff Garland, Terry Golubiewski, Daniel Krugler, Anthony Williams.
8042
8043 The file <boost/chrono_io.hpp> has been adapted from the experimental header `<chrono_io>` from Howard Hinnant. Thanks for all Howard.
8044
8045 Howard Hinnant, who is the real author of the library, has provided valuable feedback and suggestions during the development of the library. In particular, The chrono_io_io.hpp source has been adapted from the experimental header `<chrono_io>` from Howard Hinnant.
8046
8047 The acceptance review of Boost.Ratio took place between November 5th and 15th 2010. Many thanks to Anthony Williams, the review manager, and to all the reviewers: David Deakins, John Bytheway, Roland Bock and Paul A. Bristow.
8048
8049 Thanks to Ronald Bock, Andrew Chinoff, Paul A. Bristow and John Bytheway for his help polishing the documentation.
8050
8051 Thanks to Tom Tan for reporting some compiler issues with MSVC V10 beta and MinGW-gcc-4.4.0 and for the many pushing for an homogeneous `process_cpu_clock` clock.
8052
8053 Thanks to Ronald Bock for reporting Valgind issues and for the many suggestions he made concerning the documentation.
8054
8055 [endsect]
8056
8057 [/=====================================]
8058 [section:todo Appendix: Future plans]
8059 [/=====================================]
8060
8061 [heading For later releases]
8062
8063 * Include Stopwatches.
8064 * Add User defined literals for some durations.
8065 * Include chrono::date as defined by Howard Hinnant [@http://home.roadrunner.com/~hinnant/bloomington/date.html here].
8066
8067 [endsect]
8068
8069 [endsect]