2 / Copyright (c) 2008 Howard Hinnant
3 / Copyright (c) 2006, 2008 Beman Dawes
4 / Copyright (c) 2009-2015 Vicente J. Botet Escriba
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)
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]
23 Useful time utilities.
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])
33 [def __Boost_Chrono__ [*Boost.Chrono]]
34 [def __Boost_Chrono [*Boost.Chrono]]
36 [def __see_bellow__ ['see bellow]]
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:]]
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]:]]
60 [template mu[]'''μ'''] [/ Greek small letter mu]
61 [template plusminus[]'''±'''] [/ ? plus or minus sign]
65 [/===============================================]
66 [def __common_type `common_type`]
69 [/===============================================]
72 [def __ratio_add `ratio_add`]
73 [def __ratio_subtract `ratio_subtract`]
74 [def __ratio_multiply `ratio_multiply`]
75 [def __ratio_divide `ratio_divide`]
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`]
85 [def __failbit `failbit`]
106 [/==================]
109 [template chrono_conf[link_text] [link chrono.reference.cpp0x.chrono_chrono_hpp.conf [link_text]]]
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`]
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`]]
118 [def __BOOST_CHRONO_HAS_CLOCK_STEADY [link chrono.reference.cpp0x.system_clocks_hpp.BOOST_CHRONO_HAS_CLOCK_STEADY `BOOST_CHRONO_HAS_CLOCK_STEADY`]]
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`]]
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`]]
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]
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>=`]]
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]
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>=`]]
215 [def __time_point_units [link chrono.reference.io.time_point_units_hpp.time_point_units `time_point_units`]]
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`]]
227 [/==================]
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`]]
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`]]
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`]]
247 [def __common_type_spe [link chrono.reference.cpp0x.duration_hpp.common_type_spe `common_type`]]
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`]]
258 [/==================]
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`]]
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`]]
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`]]
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 <<`]]
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`]]
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`]]
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 <<`]]
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`]]
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`]]
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`]]
336 [/==================]
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`]]
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`]]
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`]]
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`]]
358 [/==================]
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`]]
364 [/==================]
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`]]
371 [def __strict_stopclock [link boost_chrono.reference.stopclocks.strict_stopclock_hpp.strict_stopclock `strict_stopclock`]]
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`]]
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`]]
384 [def __stopwatch_reporter `stopwatch_reporter `]
385 [def __stopclock `stopclock `]
386 [def __Formatter `Formatter`]
387 [def __Formatters `Formatter`s]
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 ]]]
398 [/====================================]
399 [heading How to Use This Documentation]
400 [/====================================]
402 This documentation makes use of the following naming and formatting conventions.
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.
412 [note In addition, notes such as this one specify non-essential information that provides additional background or rationale.]
414 Finally, you can mentally add the following to any code fragments in this document:
416 // Include all of Chrono files
417 #include <boost/chrono.hpp>
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.
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.
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.
434 In addition to the clocks provided by the standard proposal, __Boost_Chrono__ provides specific process and thread clocks.
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.
441 [heading Wall clock versus system and user time]
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()`.)
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.
450 3 concrete process clocks:
452 # __process_real_cpu_clock,
453 # __process_user_cpu_clock,
454 # __process_system_cpu_clock
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.
463 [/These clocks capture the specific time unitarily. __Boost_Chrono__ provides also a clock __process_cpu_clock that captures the three times at once.
466 [/include stopwatches/motivation.qbk]
470 [/==================]
471 [section Description]
472 [/==================]
474 The __Boost_Chrono__ library provides:
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].
482 [heading Other clocks]
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,
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).
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.
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.
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>.
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.
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.
514 [heading Rounding utilities]
516 A few simple rounding utility functions for working with durations.
518 [/include stopwatches/description.qbk]
520 [heading Caveat Emptor]
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.
529 [/==============================]
530 [section:users_guide User's Guide]
531 [/==============================]
533 [/======================================]
534 [section:getting_started Getting Started]
535 [/======================================]
537 [/======================================]
538 [section:install Installing Chrono]
539 [/======================================]
541 [/=================================]
542 [heading Getting __Boost_Chrono__ ]
543 [/=================================]
545 __Boost_Chrono__ is in the latest Boost release in the folder `/boost/chrono`. Documentation, tests and examples folder are at `boost/libs/chrono/`.
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.
550 [/==========================================]
551 [heading Where to install Boost.Chrono? ]
552 [/==========================================]
554 The simple way is to decompress (or checkout from SVN) the files in your BOOST_ROOT directory.
557 [/=================================]
558 [heading Building Boost.Chrono ]
559 [/=================================]
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.
564 Boost.System has an undocumented feature (use of macro BOOST_ERROR_CODE_HEADER_ONLY) to make it header only.
566 If __BOOST_CHRONO_HEADER_ONLY is not defined you need to compile it and build the library before use, for example using:
568 bjam libs/chrono/build
570 [/===================]
571 [heading Requirements]
572 [/===================]
574 In particular, __Boost_Chrono__ depends on:
578 [[@http://www.boost.org/libs/config [*Boost.Config]]] [for configuration purposes, ...]
581 [[@http://www.boost.org/libs/exception [*Boost.Exception]]] [for throw_exception, ...]
584 [[@http://www.boost.org/libs/integer [*Boost.Integer]]] [for cstdint conformance, ...]
587 [[@http://www.boost.org/libs/mpl [*Boost.MPL]]] [for MPL Assert and bool, logical ...]
590 [[@http://www.boost.org/libs/operators [*Boost.Operators]]] [for operators, ...]
593 [[@http://www.boost.org/libs/ratio [*Boost.Ratio]]] [for ratio, milli, micro, ...]
596 [[@http://www.boost.org/libs/system [*Boost.System]]] [for error_code, ...]
599 [[@http://www.boost.org/libs/type_traits [*Boost.TypeTraits]]] [for is_base, is_convertible, common_type, ...]
602 [[@http://www.boost.org/libs/utility [*Boost.Utility/EnableIf]]] [for enable_if, ...]
607 [/=========================================================]
608 [heading Building an Executable that Uses Boost.Chrono ]
609 [/=========================================================]
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.
615 [/=========================]
616 [heading Exception safety ]
617 [/=========================]
619 All functions in the library are exception-neutral and provide strong guarantee of exception safety as long as the underlying parameters provide it.
622 [/=====================]
623 [heading Thread safety ]
624 [/=====================]
626 All functions in the library are thread-unsafe except when noted explicitly.
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.
631 [/========================]
632 [heading Tested compilers ]
633 [/========================]
635 The implementation will eventually work with most C++03 conforming compilers.
636 Currently I use to test with on:
645 * GCC 4.5.0 -std=c++0x
647 * GCC 4.5.2 -std=c++0x
649 * GCC 4.6.0 -std=c++0x
651 * GCC 4.8.0 -std=c++0x
655 * GCC 4.4.6 -std=c++0x
657 * GCC 4.5.4 -std=c++0x
659 * GCC 4.6.1 -std=c++0x
661 * Intel 12.1.3 -std=c++0x
667 * GCC 4.6.2 -std=c++0x
669 * GCC 4.7.0 -std=c++0x
671 * GCC 4.7.1 -std=c++0x
673 * GCC 4.7.2 -std=c++0x
675 * GCC 4.8.0 -std=c++0x
677 * GCC 4.8.1 -std=c++0x
679 * clang 3.1 -std=c++0x -stdlib=libc++
681 * clang 3.2 -std=c++11 -stdlib=libc++
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.
687 [note Please let us know how this works on other platforms/compilers.]
689 [note Please send any questions, comments and bug reports to boost <at> lists <dot> boost <dot> org.]
692 [/====================]
693 [section Hello World! ]
694 [/====================]
696 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
697 If all you want to do is to time a program's execution, here is a complete program:
699 #include <boost/chrono.hpp>
704 boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now();
706 for ( long i = 0; i < 10000000; ++i )
707 std::sqrt( 123.456L ); // burn some time
709 boost::chrono::__duration<double> sec = boost::chrono::system_clock::now() - start;
710 std::cout << "took " << sec.count() << " seconds\n";
718 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
719 [/include stopwatches/hello.qbk]
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.
732 The library consists of six units of time __duration:
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.
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.
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.
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.
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.
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.
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.
756 [section So What Exactly is a `duration` and How Do I Use One?]
758 A __duration has a representation and a tick period (precision).
760 template <class Rep, class Period = __ratio<1> > class duration;
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.
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
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
776 microseconds us4 = m3 + us3; // us4 stores 300000005
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.
780 If you need to access the tick count within a __duration, there is a member `count()` which simply returns the stored tick count.
782 long long tc = us4.count(); // tc is 300000005
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).
788 [section What Happens if I Assign `m3 + us3` to `minutes` Instead of `microseconds`?]
790 minutes m4 = m3 + us3;
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.
795 [section But What if the Truncation Behavior is What I Want to Do?]
797 There is a __duration_cast facility to explicitly ask for this behavior:
799 minutes m4 = boost::chrono::__duration_cast<minutes>(m3 + us3); // m4.count() == 5
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.
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:
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);
810 // d now holds the number of milliseconds from start to end.
812 std::cout << ms.count() << "ms\n";
814 We can convert to __nanoseconds, or some integral-based duration which __nanoseconds will always exactly convert to, then __duration_cast`<>` is unnecessary:
816 typedef boost::chrono::__nanoseconds ns;
818 std::cout << ns.count() << "ns\n";
820 If you need seconds with a floating-point representation you can also eliminate the __duration_cast`<>`:
822 typedef boost::chrono::__duration<double> sec; // seconds, stored with a double
824 std::cout << sec.count() << "s\n";
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.
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__:
831 template <class __ToDuration, class Rep, class Period>
833 round_up(boost::chrono::__duration<Rep, Period> d)
836 ToDuration result = boost::chrono::__duration_cast<ToDuration>(d);
837 if (result < d) // comparisons are *always* exact
838 ++result; // increment by one tick period
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";
849 [section:round Rounding functions]
852 __Boost_Chrono__ provides few simple rounding utility functions for working with durations.
856 template <class __To, class Rep, class Period>
858 floor(const duration<Rep, Period>& d)
860 return duration_cast<To>(d);
863 // round to nearest, to even on tie
864 template <class __To, class Rep, class Period>
866 round(const duration<Rep, Period>& d)
868 To t0 = duration_cast<To>(d);
871 BOOST_AUTO(diff0, d - t0);
872 BOOST_AUTO(diff1, t1 - d);
879 else if (diff0 < diff1)
884 template <class __To, class Rep, class Period>
886 ceil(const duration<Rep, Period>& d)
888 To t = duration_cast<To>(d);
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).
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
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>
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';
922 The output of this program should be
933 [section Trafficking in floating-point Durations]
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.
937 Not a problem. When the destination of a conversion has floating-point representation, all conversions are allowed to happen implicitly.
939 typedef boost::chrono::__duration<double, __ratio<60> > dminutes;
940 dminutes dm4 = m3 + us3; // dm4.count() == 5.000000083333333
944 [section How Expensive is All of this?]
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.
950 [section How Complicated is it to Build a Function Taking a `duration` Parameter?]
952 There are several options open to the user:
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:
956 void f(boost::chrono::duration<double> d) // accept floating-point seconds
958 // d.count() == 3.e-6 when passed boost::chrono::microseconds(3)
961 f(boost::chrono::microseconds(3));
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:
965 void f(boost::chrono::nanoseconds d)
967 // d.count() == 3000 when passed boost::chrono::microseconds(3)
970 f(boost::chrono::microseconds(3));
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.
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
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:
979 f(s); // does not compile
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:
983 template <class Rep, class Period>
984 void f(boost::chrono::__duration<Rep, Period> d)
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);
990 // ns.count() == 333333334 when passed 1/3 of a floating-point second
993 f(boost::chrono::__duration<double>(1./3));
995 * If the author in the example does not want to accept floating-point based __durations, he can enforce that behavior like so:
997 template <class Period>
998 void f(boost::chrono::__duration<long long, Period> d)
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);
1004 // ns.count() == 333333334 when passed 333333333333 picoseconds
1006 // About 1/3 of a second worth of picoseconds
1007 f(boost::chrono::__duration<long long, boost::pico>(333333333333));
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.
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.
1014 [section Is it possible for the user to pass a __duration to a function with the units being ambiguous?]
1016 No. No matter which option the author of `f` chooses above, the following client code will not compile:
1018 f(3); // Will not compile, 3 is not implicitly convertible to any __duration
1022 [section Can Durations Overflow?]
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.
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.
1033 A clock is a concept which bundles 3 things:
1035 # A concrete __duration type.
1036 # A concrete __time_point type.
1037 # A function called now() which returns the concrete __time_point.
1039 The standard defines three system-wide clocks that are associated to the computer time.
1041 * __system_clock represents system-wide realtime clock that can be synchronized with an external clock.
1043 * __steady_clock can not be changed explicitly and the time since the initial epoch increase in a steady way.
1045 * __high_resolution_clock intend to use the system-wide clock provided by the platform with the highest resolution.
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.
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.
1052 The user is also able to easily create more clocks.
1054 Given a clock named Clock, it will have:
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;
1064 static time_point now();
1067 One can get the current time from Clock with:
1069 Clock::time_point t1 = Clock::now();
1071 And one can get the time __duration between two __time_points associated with Clock with:
1073 Clock::duration d = Clock::now() - t1;
1075 And one can specify a past or future __time_point with:
1077 Clock::time_point t2 = Clock::now() + d;
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.
1085 [section Time Point]
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:
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.
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.
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.
1097 [section So What Exactly is a `time_point` and How Do I Use One?]
1099 A __time_point has a clock and a __duration.
1101 template <class __Clock, class __Duration = typename Clock::duration> class __time_point;
1103 The __time_point's clock is not stored. It is simply embedded into the __time_point's type and serves two purposes:
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.
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.
1114 boost::chrono::steady_clock::time_point start = boost::chrono::steady_clock::now();
1117 __duration<double> sec = boost::chrono::steady_clock::now() - start;
1118 cout << "f() took " << sec.count() << " seconds\n";
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.
1123 A delay loop example:
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)
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.
1138 [section How to Define a Thread Clock]
1140 On posix systems for which the macro _POSIX_THREAD_CPUTIME is defined we can get the time associated to a specific thread.
1142 class thread_clock {
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;
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
1155 pthread_getcpuclockid(pth, clock_id);
1156 // get the timespec associated to the thread clock
1158 if ( ::clock_gettime( clock_id, &ts ) )
1160 boost::throw_exception(
1161 system::system_error( errno, system::system_category, "chrono::thread_clock" ));
1164 // transform to nanoseconds
1165 return time_point(duration(
1166 static_cast<thread_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
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
1174 pthread_getcpuclockid(pth, clock_id);
1175 // get the timespec associated to the thread clock
1177 if ( ::clock_gettime( clock_id, &ts ) )
1179 ec.assign( errno, system::system_category );
1180 return time_point();
1183 // transform to nanoseconds
1184 return time_point(duration(
1185 static_cast<thread_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
1195 [section Specific Clocks]
1196 [section system_clock]
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.
1202 [section steady_clock]
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.
1206 Here is a polling solution, but it will probably be too inefficient:
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) {}
1214 [section high_resolution_clock]
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.
1220 [section process_cpu_clock]
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).
1226 [section thread_clock]
1228 You can use __thread_clock whenever you want to measure the time spent by the current thread. For example:
1230 boost::chrono::__thread_clock::time_point start=boost::chrono::__thread_clock::now();
1231 // ... do something ...
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";
1238 If you need seconds with a floating-point representation you can do:
1240 typedef boost::chrono::__duration<double> sec; // seconds, stored with a double.
1241 sec d = end - start;
1242 std::cout << sec.count() << "s\n";
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`.
1251 [section:duration_io duration]
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.
1255 the format is either
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.
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)`.
1274 #include <boost/chrono/chrono_io.hpp>
1278 using namespace std;
1279 using namespace boost;
1281 cout << "milliseconds(1) = "
1282 << boost::chrono::milliseconds(1) << '\n';
1284 cout << "milliseconds(3) + microseconds(10) = "
1285 << boost::chrono::milliseconds(3) + boost::chrono::microseconds(10) << '\n';
1287 cout << "hours(3) + minutes(10) = "
1288 << boost::chrono::hours(3) + boost::chrono::minutes(10) << '\n';
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';
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
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
1310 system_clock::now() = 129387415616250000 [1/10000000]s since Jan 1, 1970
1311 monotonic_clock::now() = 37297387636417 ns since boot
1313 Set cout to use long names:
1314 high_resolution_clock::now() = 37297387655134 nanoseconds since boot
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.
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]:
1320 cout << "\nSet cout to use short names:\n";
1321 cout << boost::chrono::symbol_format;
1323 cout << "milliseconds(3) + microseconds(10) = "
1324 << boost::chrono::milliseconds(3) + boost::chrono::microseconds(10) << '\n';
1326 cout << "hours(3) + minutes(10) = "
1327 << boost::chrono::hours(3) + boost::chrono::minutes(10) << '\n';
1329 cout << "ClockTick(3) + nanoseconds(10) = "
1330 << ClockTick(3) + boost::chrono::nanoseconds(10) << '\n';
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
1340 system_clock::now() = 129387415616250000 [1/10000000]s since Jan 1, 1970
1341 monotonic_clock::now() = 37297387636417 ns since boot
1343 Set cout to use long names:
1344 high_resolution_clock::now() = 37297387655134 nanoseconds since boot
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.
1348 When the format decision is taken at runtime, it could be better to use the parameterized manipulator __duration_fmt as in
1350 duration_style style;
1352 cout << duration_fmt(style);
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.
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.
1362 #include <boost/chrono/chrono_io.hpp>
1368 using namespace std;
1370 istringstream in("5000 milliseconds 4000 ms 3001 ms");
1371 boost::chrono::seconds d(0);
1374 assert(d == seconds(5));
1377 assert(d == seconds(4));
1380 assert(d == seconds(4));
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.
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:
1390 // round to nearest, to even on tie
1391 template <class __To, class Rep, class Period>
1393 round(const duration<Rep, Period>& d)
1395 To t0 = duration_cast<To>(d);
1398 auto diff0 = d - t0;
1399 cout << "diff0 = " << diff0 << '\n';
1400 auto diff1 = t1 - d;
1401 cout << "diff1 = " << diff1 << '\n';
1408 else if (diff0 < diff1)
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:
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
1420 This simple I/O will make duration so much more accessible to programmers.
1424 [section:system_clock_time_point_io `system_clock::time_point`]
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:
1430 - [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile
1432 - [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile
1434 In this case the io operators behave like any time_point as defined in next section.
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`.
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].
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`.
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.
1446 cout << system_clock::now() << '\n';
1450 2011-09-15 18:36:59.325132 +0000
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.
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.
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:
1458 cout << time_fmt(local) << system_clock::now() << '\n';
1460 that could result in
1462 2011-09-15 14:36:59.325132 -0400
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`:
1466 tm* gmtime(const time_t* timer) -> UTC
1467 tm* localtime(const time_t* timer) -> local time
1469 This proposal simply extends the C/POSIX `time_t` functionality to C++ syntax and `system_clock::time_point`.
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:
1473 cout << time_fmt(utc);
1475 And the formatting can be further customized by using the time format sequences. For example:
1477 cout << time_fmt(local, "%A %B %e, %Y %r");
1478 cout << system_clock::now() << '\n'; // Sunday April 24, 2011 02:36:59 PM
1480 When specifying formatting manipulators for wide streams, use wide strings.
1482 You can use the same manipulators with istreams to specify parsing sequences.
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()`.
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).
1489 [section:other_clocks_time_point_io Other clocks time_point]
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).
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.
1495 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
1496 cout << "steady_clock::now() = " << boost::chrono::steady_clock::now() << '\n';
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';
1505 steady_clock::now() = 37297387636417 ns since boot
1507 Set cout to use long names:
1508 high_resolution_clock::now() = 37297387655134 nanoseconds since boot
1513 cout << "\nsystem_clock::now() = " << boost::chrono::system_clock::now() << '\n';
1516 system_clock::now() = 129387415616250000 [1/10000000]s since Jan 1, 1970
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.
1524 #include <boost/chrono/chrono_io.hpp>
1531 using namespace std;
1533 boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now();
1536 boost::chrono::high_resolution_clock::time_point t1;
1539 cout << io.str() << '\n';
1542 boost::chrono::high_resolution_clock::time_point t = boost::chrono::high_resolution_clock::now();
1545 cout << "That took " << t - t0 << '\n';
1546 cout << "That took " << t - t1 << '\n';
1551 The output could be:
1553 50908679121461 nanoseconds since boot
1554 That took 649630 nanoseconds
1556 Here's a simple example to find out how many hours the computer has been up (on this platform):
1558 #include <boost/chrono/chrono_io.hpp>
1563 using namespace std;
1564 using namespace boost;
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';
1572 The output could be:
1574 17.8666 hours since boot
1578 [section Low level I/O]
1579 [/====================]
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:
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.
1585 The use of this facet is similar to the time_put facet.
1587 [endsect] [/ Low level I/O]
1591 [/include stopwatches/tutorial.qbk]
1603 [section How you Override the Duration's Default Constructor]
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
1607 namespace I_dont_like_the_default_duration_behavior {
1618 zero_default(rep i = 0) : rep_(i) {}
1619 operator rep() const {return rep_;}
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;}
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_--);}
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;}
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);}
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;
1656 using namespace I_dont_like_the_default_duration_behavior;
1659 std::cout << ms.count() << '\n';
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]]
1665 [/=========================]
1666 [section runtime_resolution]
1668 This example shows how to handle duration with resolution not known until run-time
1673 typedef long long rep;
1677 static const double ticks_per_nanosecond;
1680 typedef boost::chrono::duration<double, boost::nano> tonanosec;
1682 duration() {} // = default;
1683 explicit duration(const rep& r) : rep_(r) {}
1686 explicit duration(const tonanosec& d)
1687 : rep_(static_cast<rep>(d.count() * ticks_per_nanosecond)) {}
1690 operator tonanosec() const {return tonanosec(rep_/ticks_per_nanosecond);}
1694 rep count() const {return rep_;}
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;}
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_--);}
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;}
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);}
1724 ['See the source file [@boost:libs/chrono/example/runtime_resolution.cpp here]]
1729 [section Saturating]
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.
1733 ['See the source file [@boost:libs/chrono/example/saturating.cpp example/saturating.cpp]]
1739 [/==================]
1740 [section xtime Conversions]
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!
1745 #include <boost/chrono.hpp>
1746 #include <boost/type_traits.hpp>
1750 template <class To, class Rep, class Period>
1752 round_up(boost::chrono::duration<Rep, Period> d)
1754 To result = boost::chrono::duration_cast<To>(d);
1760 To demonstrate interaction with an xtime-like facility:
1769 template <class Rep, class Period>
1771 to_xtime_truncate(boost::chrono::__duration<Rep, Period> d)
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());
1779 template <class Rep, class Period>
1781 to_xtime_round_up(boost::chrono::__duration<Rep, Period> d)
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());
1790 from_xtime(xtime xt)
1792 return boost::chrono::__seconds(xt.sec) + boost::chrono::__microseconds(xt.usec);
1795 void print(xtime xt)
1797 std::cout << '{' << xt.sec << ',' << xt.usec << "}\n";
1802 xtime xt = to_xtime_truncate(seconds(3) + boost::chrono::__milliseconds(251));
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);
1808 xt = to_xtime_truncate(boost::chrono::seconds(3) + __nanoseconds(999));
1810 xt = to_xtime_round_up(boost::chrono::seconds(3) + __nanoseconds(999));
1814 ['See the source file [@boost:libs/chrono/example/xtime.cpp xtime.cpp]]
1822 [/==================]
1823 [section Cycle count]
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.
1828 #include <boost/chrono.hpp>
1829 #include <boost/type_traits.hpp>
1832 template <long long speed>
1835 typedef typename boost::__ratio_multiply__<boost::__ratio<speed>, boost::__mega>::type
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;
1842 static time_point now()
1844 static long long tick = 0;
1845 // return exact cycle count
1846 return time_point(duration(++tick)); // fake access to clock cycle count
1850 template <long long speed>
1851 struct approx_cycle_count
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;
1860 static time_point now()
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));
1869 ['See the source file [@boost:libs/chrono/example/cycle_count.cpp cycle_count.cpp]]
1873 [/==================]
1874 [section xtime_clock]
1876 This example demonstrates the use of a timeval-like struct to be used as the representation type for both __duration and __time_point.
1891 explicit xtime(long sec, long usec) {
1894 if (tv_usec < 0 || tv_usec >= 1000000) {
1895 tv_sec += tv_usec / 1000000;
1901 explicit xtime(long long usec) {
1902 tv_usec = static_cast<long>(usec % 1000000);
1903 tv_sec = static_cast<long>(usec / 1000000);
1908 operator long long() const {return static_cast<long long>(tv_sec) * 1000000 + tv_usec;}
1910 xtime& operator += (xtime rhs) {
1911 tv_sec += rhs.tv_sec;
1912 tv_usec += rhs.tv_usec;
1913 if (tv_usec >= 1000000) {
1920 xtime& operator -= (xtime rhs) {
1921 tv_sec -= rhs.tv_sec;
1922 tv_usec -= rhs.tv_usec;
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;
1931 tv_sec = static_cast<long>(t / 1000000);
1932 tv_usec = static_cast<long>(t % 1000000);
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;}
1941 friend bool operator==(xtime x, xtime y)
1942 { return (x.tv_sec == y.tv_sec && x.tv_usec == y.tv_usec); }
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);
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); }
1955 friend std::ostream& operator<<(std::ostream& os, xtime x)
1956 {return os << '{' << x.tv_sec << ',' << x.tv_usec << '}';}
1959 Clock based on timeval-like struct.
1965 typedef boost::micro period;
1966 typedef boost::chrono::duration<rep, period> duration;
1967 typedef boost::chrono::time_point<xtime_clock> time_point;
1969 static time_point now()
1971 #if defined(BOOST_CHRONO_WINDOWS_API)
1972 time_point t(duration(xtime(0)));
1973 gettimeofday((timeval*)&t, 0);
1976 #elif defined(BOOST_CHRONO_MAC_API)
1978 time_point t(duration(xtime(0)));
1979 gettimeofday((timeval*)&t, 0);
1982 #elif defined(BOOST_CHRONO_POSIX_API)
1983 //time_point t(0,0);
1986 ::clock_gettime( CLOCK_REALTIME, &ts );
1988 xtime xt( ts.tv_sec, ts.tv_nsec/1000);
1989 return time_point(duration(xt));
1995 Usage of xtime_clock
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";
2008 ['See the source file [@boost:libs/chrono/example/timeval_demo.cpp example/timeval_demo.cpp]]
2016 [/======================================================]
2017 [section Howard Hinnant's original demonstration program]
2019 ['See the source file [@boost:libs/chrono/example/time2_demo.cpp example/time2_demo.cpp]]
2023 [section Time Point]
2025 [/==================]
2026 [section min Utility]
2028 The user can define a function returning the earliest __time_point as follows:
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)
2035 return t2 < t1 ? t2 : t1;
2038 Being able to *easily* write this function is a major feature!
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));
2044 ['See the source file [@boost:libs/chrono/example/min_time_point.cpp example/min_time_point.cpp]]
2049 [/===============================================================]
2050 [section A Tiny Program that Times How Long Until a Key is Struck]
2052 #include <boost/chrono.hpp>
2056 using namespace boost::chrono;
2058 template< class __Clock >
2061 typename __Clock::time_point start;
2063 timer() : start( __Clock::now() ) {}
2064 typename __Clock::duration elapsed() const
2066 return __Clock::now() - start;
2068 double seconds() const
2070 return elapsed().count() * ((double)Clock::period::num/Clock::period::den);
2076 timer<__system_clock> t1;
2077 timer<__steady_clock> t2;
2078 timer<__high_resolution_clock> t3;
2080 std::cout << "Type the Enter key: ";
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";
2091 __system_clock::time_point d4 = __system_clock::now();
2092 __system_clock::time_point d5 = __system_clock::now();
2094 std::cout << "\nsystem_clock latency-----------: " << (d5 - d4).count() << std::endl;
2096 __steady_clock::time_point d6 = __steady_clock::now();
2097 __steady_clock::time_point d7 = __steady_clock::now();
2099 std::cout << "steady_clock latency--------: " << (d7 - d6).count() << std::endl;
2101 __high_resolution_clock::time_point d8 = __high_resolution_clock::now();
2102 __high_resolution_clock::time_point d9 = __high_resolution_clock::now();
2104 std::cout << "high_resolution_clock latency--: " << (d9 - d8).count() << std::endl;
2106 std::time_t now = __system_clock::to_time_t(__system_clock::now());
2108 std::cout << "\nsystem_clock::now() reports UTC is "
2109 << std::asctime(std::gmtime(&now)) << "\n";
2114 The output of this program run looks like this:
2119 ['See the source file [@boost:libs/chrono/example/await_keystroke.cpp example/await_keystroke.cpp]]
2124 [/===============================================================]
2125 [section Time Command]
2127 #include <boost/chrono/stopclock.hpp>
2132 int main( int argc, char * argv[] )
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";
2144 bool verbose = false;
2145 if ( argc > 1 && *argv[1] == '-' && *(argv[1]+1) == 'v' )
2152 for ( int i = 1; i < argc; ++i )
2154 if ( i > 1 ) s += ' ';
2159 { std::cout << "command: \"" << s.c_str() << "\"\n"; }
2161 boost::chrono::__stopclock<> t;
2163 return std::system( s.c_str() );
2166 ['See the source file [@boost:libs/chrono/example/timex.cpp example/timex.cpp]]
2171 [section 24 Hours Display]
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>>`.
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.
2177 As an example, the function below streams arbitrary __durations to arbitrary `basic_ostreams` using the format:
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
2188 #include <boost/chrono/chrono_io.hpp>
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)
2198 using namespace std;
2199 using namespace boost;
2201 typedef boost::chrono::duration<long long, boost::ratio<86400> > days;
2202 typedef boost::chrono::duration<long long, boost:centi> centiseconds;
2204 // if negative, print negative sign and negate
2205 if (d < boost::chrono::duration<Rep, Period>(0))
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))
2215 // separate seconds from centiseconds
2216 boost::chrono::seconds s = boost::chrono::duration_cast<boost::chrono::seconds>(cs);
2218 // separate minutes from seconds
2219 boost::chrono::minutes m = boost::chrono::duration_cast<boost::chrono::minutes>(s);
2221 // separate hours from minutes
2222 boost::chrono::hours h = boost::chrono::duration_cast<boost::chrono::hours>(m);
2224 // separate days from hours
2225 days dy = boost::chrono::duration_cast<days>(h);
2227 // print d/hh:mm:ss.cc
2228 os << dy.count() << '/';
2229 if (h < boost::chrono::hours(10))
2231 os << h.count() << ':';
2232 if (m < boost::chrono::minutes(10))
2234 os << m.count() << ':';
2235 if (s < boost::chrono::seconds(10))
2237 os << s.count() << '.';
2238 if (cs < boost::chrono::centiseconds(10))
2246 using namespace std;
2247 using namespace boost;
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';
2256 The output could be:
2266 [/=======================================================]
2267 [section Simulated Thread Interface Demonstration Program]
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.
2271 The non-member sleep functions can be emulated as follows:
2273 namespace boost { namespace this_thread {
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);
2280 if (t > chrono::__microseconds(0))
2281 std::cout << "sleep_for " << t.count() << " microseconds\n";
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);
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";
2306 Next is the `boost::thread::timed_mutex` modified functions
2309 struct timed_mutex {
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))
2317 std::cout << "try_lock_for " << t.count() << " microseconds\n";
2321 template <class __Clock, class __Duration>
2322 bool try_lock_until(const chrono::__time_point<__Clock, __Duration>& t)
2324 using namespace chrono;
2325 typedef __time_point<__Clock, __Duration> Time;
2326 typedef __system_clock::time_point SysTime;
2327 if (t <= __Clock::now())
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";
2343 `boost::thread::condition_variable` time related function are modified as follows:
2346 struct condition_variable
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";
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())
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";
2378 Next follows how simple is the usage of this functions:
2381 boost::timed_mutex mut;
2382 boost::condition_variable cv;
2384 using namespace boost;
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);
2391 mut.try_lock_for(chrono::__milliseconds(30));
2392 mut.try_lock_until(time_limit);
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
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));
2402 ['See the source file [@boost:libs/chrono/example/simulated_thread_interface_demo.cpp example/simulated_thread_interface_demo.cpp]]
2408 [/=======================================================]
2409 [section:french French Output]
2411 Example use of output in French
2413 #include <boost/chrono/chrono_io.hpp>
2419 using namespace std;
2420 using namespace boost;
2421 using namespace boost::chrono;
2423 cout.imbue(locale(locale(), new duration_punct<char>
2425 duration_punct<char>::use_long,
2426 "secondes", "minutes", "heures",
2432 milliseconds ms(763);
2433 cout << h << ", " << m << ", " << s << " et " << ms << '\n';
2438 5 heures, 45 minutes, 15 secondes et 763 millisecondes
2440 ['See the source file [@boost:libs/chrono/example/french.cpp example/french.cpp]]
2442 [endsect] [/section:french French Output]
2443 [endsect] [/section IO]
2445 [endsect] [/section Examples]
2448 [/================================]
2449 [section:ext_references External Resources]
2450 [/================================]
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"]
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]
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]
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.]
2481 [/=================]
2482 [section:reference Reference ]
2483 [/=================]
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.
2487 The documentation doesn't use these macros.
2489 [/=============================================]
2490 [section:chrono_include_hpp Header `<boost/chrono/include.hpp>`]
2491 [/=============================================]
2493 Include all the chrono header files.
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>
2503 [/ /////////////////////////////////////////////////////
2504 #include <boost/chrono/stopwatches.hpp>
2505 ] [////////////////////////////////////////////////////]
2508 [section:cpp0x Included on the C++11 Recommendation]
2510 [/=============================================]
2511 [section:chrono_hpp Header `<boost/chrono.hpp>`]
2512 [/=============================================]
2514 Include only the standard files.
2516 #include <boost/chrono/chrono.hpp>
2520 [/=============================================]
2521 [section:chrono_chrono_hpp Header `<boost/chrono/chrono.hpp>`]
2522 [/=============================================]
2524 Include only the standard files.
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>
2531 [section:limitations Limitations and Extensions]
2533 At present, there is no know limitation respect to the C++11 standard.
2535 The current implementation provides in addition:
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.
2541 [endsect] [/section:limitations Limitations and Extensions]
2543 [section:conf Configuration Macros]
2545 [section:assert How Assert Behaves?]
2547 When `BOOST_NO_CXX11_STATIC_ASSERT` is defined, the user can select the way static assertions are reported. Define
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.
2553 The default behavior is as `BOOST_CHRONO_USES_ARRAY_ASSERT` was defined.
2555 When `BOOST_CHRONO_USES_MPL_ASSERT` is not defined the following symbols are defined as
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"
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.
2570 [section:no_hybrid Don't provide Hybrid Error Handling]
2572 When `BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING` is defined the lib don't provides the hybrid error handling prototypes:
2574 Clock::time_point Clock::now(system::error_code&ec=boost::throws());
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.
2578 By default `BOOST_CHRONO_PROVIDE_HYBRID_ERROR_HANDLING` is defined.
2580 [endsect] [/section:header_only How to Build Boost.Chrono as a Header Only Library?]
2582 [section:header_only How to Build Boost.Chrono as a Header Only Library?]
2584 When `BOOST_CHRONO_HEADER_ONLY` is defined the lib is header-only.
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>`.
2588 However, you will either need to define `BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING` or link with Boost.System.
2590 [endsect] [/section:header_only How to Build Boost.Chrono as a Header Only Library?]
2592 [section:deprecated_io Deprecated IO]
2594 Version 2.0.0 deprecates the preceding IO features.
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`.
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.
2609 [section:system_clock_time_point time_point<system_clock,D> specialization limitation]
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:
2615 - [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile
2617 - [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile
2619 In this case the io operators behave like any time_point as if the specialization was removed.
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`.
2627 [section:version Version]
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:
2632 * `BOOST_CHRONO_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0`
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:
2636 * Breaking change `BOOST_CHRONO_DONT_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0 `
2638 The default value for `BOOST_CHRONO_VERSION` will be changed to 2 since Boost 1.55.
2643 [endsect] [/section:conf Configuration Macros]
2645 [endsect] [/section:chrono_hpp Header `<boost/chrono.hpp>`]
2648 [/=============================================]
2649 [section:duration_hpp Header `<boost/chrono/duration.hpp>`]
2650 [/=============================================]
2652 This file contains duration specific classes and non-member functions.
2657 template <class Rep, class Period = __ratio<1> > class __duration;
2660 template <class Rep1, class Period1, class Rep2, class Period2>
2661 struct __common_type_spe<duration<Rep1, Period1>,
2662 duration<Rep2, Period2> >;
2666 // customization traits
2667 template <class Rep> struct __treat_as_floating_point;
2668 template <class Rep> struct __duration_values;
2670 // duration arithmetic
2671 template <class Rep1, class Period1, class Rep2, class Period2>
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);
2678 template <class Rep1, class Period1, class Rep2, class Period2>
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);
2685 template <class Rep1, class Period, class Rep2>
2687 duration<typename common_type<Rep1, Rep2>::type, Period>
2688 __duration__op_mult_1(
2689 const duration<Rep1, Period>& d,
2692 template <class Rep1, class Period, class Rep2>
2694 duration<typename common_type<Rep1, Rep2>::type, Period>
2695 __duration__op_mult_2(
2697 const duration<Rep2, Period>& d);
2699 template <class Rep1, class Period, class Rep2>
2701 duration<typename common_type<Rep1, Rep2>::type, Period>
2702 __duration__op_div_2(
2703 const duration<Rep1, Period>& d,
2706 template <class Rep1, class Period1, class Rep2, class Period2>
2708 typename common_type<Rep1, Rep2>::type
2709 __duration__op_div_3(
2710 const duration<Rep1, Period1>& lhs,
2711 const duration<Rep2, Period2>& rhs);
2713 #ifdef BOOST_CHRONO_EXTENSIONS
2714 // Used to get frequency of events
2715 template <class Rep1, class Rep2, class Period>
2717 double __duration__op_div_1(
2719 const duration<Rep2, Period>& d);
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);
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);
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);
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);
2753 template <class ToDuration, class Rep, class Period>
2755 ToDuration __duration_cast(const duration<Rep, Period>& d);
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
2769 [section:traits Time-related Traits]
2771 [section:treat_as_floating_point Metafunction `treat_as_floating_point<>`]
2773 template <class Rep> struct treat_as_floating_point
2774 : boost::is_floating_point<Rep> {};
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.
2780 [section:duration_values Class Template `duration_values`]
2782 template <class Rep>
2783 struct duration_values
2786 static constexpr Rep __zero();
2787 static constexpr Rep __max();
2788 static constexpr Rep __min();
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.
2793 [section:zero Static Member Function `zero()`]
2795 static constexpr Rep zero();
2797 __returns `Rep(0)`. [*Note:] `Rep(0)` is specified instead of `Rep()` since `Rep()` may have some other meaning, such as an uninitialized value.
2799 __remarks The value returned corresponds to the additive identity.
2802 [section:max Static Member Function `max()`]
2804 static constexpr Rep max();
2806 __returns `numeric_limits<Rep>::max()`.
2808 __remarks The value returned compares greater than zero().
2811 [section:min Static Member Function `min()`]
2813 static constexpr Rep min();
2815 __returns `numeric_limits<Rep>::lowest()`.
2817 __remarks The value returned compares less than or equal to `zero()`.
2825 [section:common_type_spe `common_type` Specialization]
2827 template <class Rep1, class Period1, class Rep2, class Period2>
2828 struct __common_type<chrono::__duration<Rep1, Period1>, chrono::__duration<Rep2, Period2> >
2830 typedef chrono::__duration<typename __common_type<Rep1, Rep2>::type, __see_bellow__> type;
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`.
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).
2840 [section:duration Class Template `duration<>`]
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.
2844 namespace boost { namespace chrono {
2846 template <class Rep, class Period>
2850 typedef Period period;
2852 rep rep_; // exposition only
2854 constexpr __duration__c_0();
2855 template <class Rep2>
2856 constexpr explicit __duration__c_1(const Rep2& r);
2858 template <class Rep2, class Period2>
2859 constexpr __duration__c_2(const duration<Rep2, Period2>& d);
2861 duration& operator=(const duration&) = default;
2863 constexpr rep __duration__count() const;
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);
2872 duration& __duration__op_plus_eq(const duration& d);
2873 duration& __duration__op_minus_eq(const duration& d);
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);
2880 static constexpr duration __duration__zero();
2881 static constexpr duration __duration__min();
2882 static constexpr duration __duration__max();
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.
2889 `Period` must be an instantiation of `ratio`, compile diagnostic otherwise.
2891 `Period::num` must be positive, compile diagnostic otherwise.
2895 * `__duration<long, __ratio<60> >` holds a count of minutes using a long.
2897 * `__duration<long long, milli>` holds a count of milliseconds using a long long.
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).
2901 The following members of __duration do not throw an exception unless the indicated operations on the representations throw an exception.
2903 [section:duration_c_0 Constructor `duration()`]
2905 constexpr duration();
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.
2911 [section:duration_c_1 Constructor `duration(const Rep2&)`]
2913 template <class Rep2>
2914 constexpr explicit duration(const Rep2& r);
2916 __remarks `Rep2` is implicitly convertible to `rep`, and
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`.
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.
2925 __duration<int, milli> d(3.5); // do not compile
2926 __duration<int, milli> d(3); // ok
2928 __effects Constructs an object of type __duration.
2930 __post_conditions `count() == static_cast<rep>(r)`.
2933 [section:duration_c_2 Constructor `duration(const duration&)`]
2935 template <class Rep2, class Period2>
2936 constexpr __duration(const __duration<Rep2, Period2>& d);
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.
2942 __duration<int, milli> ms(3);
2943 __duration<int, micro> us = ms; // ok
2944 __duration<int, milli> ms2 = us; // do not compile
2946 __effects Constructs an object of type __duration, constructing `rep_` from `duration_cast<__duration>(d).count()`.
2949 [section:count Member Function `count() const`]
2951 constexpr rep count() const;
2956 [section:op_unary_plus Member Function `operator+() const`]
2958 constexpr __duration operator+() const;
2963 [section:op_unary_minus Member Function `operator-() const`]
2965 constexpr __duration operator-() const;
2967 __returns `__duration(-rep_)`.
2970 [section:op_pre_inc Member Function `operator++()`]
2972 __duration& operator++();
2979 [section:op_post_inc Member Function `operator++(int)`]
2981 __duration operator++(int);
2983 __returns `__duration(rep_++)`.
2986 [section:op_pre_dec Member Function `operator--()`]
2988 __duration& operator--();
2995 [section:op_post_dec Member Function `operator--(int)`]
2997 __duration operator--(int);
2999 __returns `__duration(rep_--)`.
3002 [section:op_plus_eq Member Function `operator+=(const duration&)`]
3004 __duration& operator+=(const __duration& d);
3006 __effects `rep_ += d.count()`.
3011 [section:op_minus_eq Member Function `operator-=(const duration&)`]
3013 __duration& operator-=(const __duration& d);
3015 __effects `rep_ -= d.count()`.
3020 [section:op_mod_eq Member Function `operator%=(const duration&)`]
3022 __duration& operator%=(const __duration& d);
3024 __effects `rep_ %= d.count()`.
3029 [section:op_mult_eq Member Function `operator*=(const rep&)`]
3031 __duration& operator*=(const rep& rhs);
3033 __effects `rep_ *= rhs`.
3038 [section:op_div_eq Member Function `operator/=(const rep&)`]
3040 __duration& operator/=(const rep& rhs);
3042 __effects `rep_ /= rhs`.
3047 [section:op_mod_eq2 Member Function `operator%=(const rep&)`]
3049 __duration& operator%=(const rep& rhs);
3051 __effects `rep_ %= rhs`.
3058 [section:zero Static Member Function `zero()`]
3060 static constexpr __duration zero();
3062 __returns `__duration(__duration_values<rep>::zero())`.
3065 [section:min Static Member Function `min()`]
3067 static constexpr __duration min();
3069 __returns `__duration(__duration_values<rep>::min()).`
3072 [section:max Static Member Function `max()`]
3074 static constexpr __duration max();
3076 __returns `__duration(__duration_values<rep>::max())`.
3083 [section:arith `duration` Non-Member Arithmetic]
3085 [section:duration__op_plus_1 Non-Member Function `operator+(duration,duration)`]
3087 template <class Rep1, class Period1, class Rep2, class Period2>
3089 typename __common_type<__duration<Rep1, Period1>, __duration<Rep2, Period2> >::type
3090 operator+(const __duration<Rep1, Period1>& lhs, const __duration<Rep2, Period2>& rhs);
3092 __returns `CD(CD(lhs).count() + CD(rhs).count())` where `CD` is the type of the return value.
3095 [section:duration__op_minus_1 Non-Member Function `operator-(duration,duration)`]
3097 template <class Rep1, class Period1, class Rep2, class Period2>
3099 typename __common_type<__duration<Rep1, Period1>, __duration<Rep2, Period2> >::type
3100 operator-(const __duration<Rep1, Period1>& lhs, const __duration<Rep2, Period2>& rhs);
3102 __returns `CD(CD(lhs).count() - CD(rhs).count())` where `CD` is the type of the return value.
3105 [section:duration__op_mult_1 Non-Member Function `operator*(duration,Rep1)`]
3107 template <class Rep1, class Period, class Rep2>
3109 __duration<typename __common_type<Rep1, Rep2>::type, Period>
3110 operator*(const __duration<Rep1, Period>& d, const Rep2& s);
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`.
3114 __returns `CD(CD(d).count() * s)` where `CD` is the type of the return value.
3117 [section:duration__op_mult_2 Non-Member Function `operator*(Rep1,duration)`]
3119 template <class Rep1, class Period, class Rep2>
3121 __duration<typename __common_type<Rep1, Rep2>::type, Period>
3122 operator*(const Rep1& s, const __duration<Rep2, Period>& d);
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`.
3131 [section:duration__op_div_1 Non-Member Function `operator/(duration,Rep2)`]
3133 template <class Rep1, class Period, class Rep2>
3135 __duration<typename __common_type<Rep1, Rep2>::type, Period>
3136 operator/(const __duration<Rep1, Period>& d, const Rep2& s);
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.
3140 __returns `CD(CD(d).count() / s)` where `CD` is the type of the return value.
3143 [section:duration__op_div_2 Non-Member Function `operator/(duration,duration)`]
3145 template <class Rep1, class Period1, class Rep2, class Period2>
3147 typename __common_type<Rep1, Rep2>::type
3148 operator/(const __duration<Rep1, Period1>& lhs, const __duration<Rep2, Period2>& rhs);
3150 __remarks Let `CD` represent the __common_type of the two __duration arguments.
3151 __returns Returns `CD(lhs).count() / CD(rhs).count()`.
3155 [section:duration__op_div_3 Non-Member Function `operator/(Rep1,duration)`]
3157 Included only if BOOST_CHRONO_EXTENSIONS is defined.
3159 This overloading could be used to get the frequency of an event counted by `Rep1`.
3161 template <class Rep1, class Rep2, class Period>
3163 double operator/(const Rep1& s, const __duration<Rep2, Period>& d);
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>.
3167 __returns `CR(s)/CD(d).count()` where `CD` is the type of the return value.
3173 [section:duration__op_mod_1 Non-Member Function `operator%(duration,Rep2)`]
3175 template <class Rep1, class Period, class Rep2>
3177 __duration<typename __common_type<Rep1, Rep2>::type, Period>
3178 operator%(const __duration<Rep1, Period>& d, const Rep2& s);
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.
3182 __returns CD(CD(d).count() % s) where `CD` is the type of the return value.
3186 [section:duration__op_mod_2 Non-Member Function `operator%(duration,duration)`]
3188 template <class Rep1, class Period1, class Rep2, class Period2>
3190 typename __common_type<__duration<Rep1, Period1>, __duration<Rep2, Period2> >::type
3191 operator%(const __duration<Rep1, Period1>& lhs,
3192 const __duration<Rep2, Period2>& rhs);
3194 __remarks This function will not participate in overload resolution unless
3196 __returns CD(CD(lhs).count() % CD(rhs).count()) where `CD` is the type of the return value.
3201 [section:cmp `duration` Non-Member Comparaisons]
3203 [section:duration__op_eq_1 Non-Member Function `operator==(duration,duration)`]
3205 template <class Rep1, class Period1, class Rep2, class Period2>
3206 bool operator==(const __duration<Rep1, Period1>& lhs,
3207 const __duration<Rep2, Period2>& rhs);
3209 __returns Let `CD` represent the __common_type of the two __duration arguments.
3211 __returns Returns `CD(lhs).count() == CD(rhs).count()`
3214 [section:duration__op_neq_1 Non-Member Function `operator!=(duration,duration)`]
3216 template <class Rep1, class Period1, class Rep2, class Period2>
3217 bool operator!=(const __duration<Rep1, Period1>& lhs,
3218 const __duration<Rep2, Period2>& rhs);
3220 __returns `!(lhs == rhs)`.
3223 [section:duration__op_lt_1 Non-Member Function `operator<(duration,duration)`]
3225 template <class Rep1, class Period1, class Rep2, class Period2>
3226 bool operator< (const __duration<Rep1, Period1>& lhs,
3227 const __duration<Rep2, Period2>& rhs);
3229 __returns Let `CD` represent the __common_type of the two __duration arguments. Returns `CD(lhs).count() < CD(rhs).count()`
3232 [section:duration__op_leq_1 Non-Member Function `operator<=(duration,duration)`]
3234 template <class Rep1, class Period1, class Rep2, class Period2>
3235 bool operator<=(const __duration<Rep1, Period1>& lhs,
3236 const __duration<Rep2, Period2>& rhs);
3238 __returns `!(rhs < lhs)`.
3241 [section:duration__op_gt_1 Non-Member Function `operator>(duration,duration)`]
3243 template <class Rep1, class Period1, class Rep2, class Period2>
3244 bool operator> (const __duration<Rep1, Period1>& lhs,
3245 const __duration<Rep2, Period2>& rhs);
3247 __returns `rhs < lhs`.
3250 [section:duration__op_geq_1 Non-Member Function `operator>=(duration,duration)`]
3252 template <class Rep1, class Period1, class Rep2, class Period2>
3253 bool operator>=(const __duration<Rep1, Period1>& lhs,
3254 const __duration<Rep2, Period2>& rhs);
3256 __returns `!(lhs < rhs)`.
3260 [section:duration_cast Non-Member Function `duration_cast(duration)`]
3262 template <class __ToDuration, class Rep, class Period>
3263 __ToDuration duration_cast(const __duration<Rep, Period>& d);
3265 __requires This function will not participate in overload resolution unless `ToDuration` is an instantiation of __duration.
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`.
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)))`
3277 `ToDuration(static_cast<typename ToDuration::rep>(static_cast<CR>(d.count()) *
3278 static_cast<CR>(CF::num) /
3279 static_cast<CR>(CF::den)))`
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.
3287 [section:duration_typedefs `duration` typedefs]
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
3301 [section:clock `Clock` Requirements]
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.
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.).
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.]]
3322 * __high_resolution_clock
3323 * __process_real_cpu_clock
3324 * __process_user_cpu_clock
3325 * __process_system_cpu_clock
3326 * __process_cpu_clock
3331 [section:trivial_clock `TrivialClock` Requirements]
3333 A type `TC` meets the `TrivialClock` requirements if:
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.
3338 [note This means, in particular, that operations on these types will not throw exceptions.]
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.
3344 Models of __TrivialClock:
3348 * __high_resolution_clock
3349 * __process_real_cpu_clock
3350 * __process_user_cpu_clock
3351 * __process_system_cpu_clock
3356 [section:ecclock `EcClock` Requirements]
3358 A type `EcC` meets the `EcClock` requirements if
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.
3364 In this table `C1` denotes a `EcClock` type and `ec` is an instance of a `boost::system::error_code`.
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.]]
3377 * __high_resolution_clock
3378 * __process_real_cpu_clock
3379 * __process_user_cpu_clock
3380 * __process_system_cpu_clock
3381 * __process_cpu_clock
3387 [/=============================================]
3388 [section:time_point_hpp Header `<boost/chrono/time_point.hpp>`]
3389 [/=============================================]
3391 This file contains __time_point specific classes and non-member functions.
3396 template <class __Clock, class __Duration = typename Clock::duration>
3400 template <class __Clock, class __Duration1, class __Duration2>
3401 struct __common_type_spe<time_point<Clock, Duration1>,
3402 time_point<Clock, Duration2> >;
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);
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);
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);
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);
3427 // time_point comparisons
3428 template <class __Clock, class __Duration1, class __Duration2>
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>
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>
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>
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>
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>
3450 __time_point__op_geq(const time_point<Clock, Duration1>& lhs,
3451 const time_point<Clock, Duration2>& rhs);
3454 template <class __ToDuration, class __Clock, class __Duration>
3455 constexpr time_point<Clock, ToDuration>
3456 __time_point_cast(const time_point<Clock, Duration>& t);
3462 [section:common_type_spe2 `common_type` specialization]
3464 template <class __Clock, class __Duration1, class __Duration2>
3465 struct __common_type<chrono::__time_point<__Clock, __Duration1>, chrono::__time_point<__Clock, __Duration2> >
3467 typedef chrono::__time_point<__Clock, typename __common_type<Duration1, __Duration2>::type> type;
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.
3474 [section:time_point Class template `time_point<>`]
3476 A __time_point represents a point in time with respect to a specific clock.
3478 template <class __Clock, class __Duration>
3481 typedef Clock clock;
3482 typedef Duration duration;
3483 typedef typename duration::rep rep;
3484 typedef typename duration::period period;
3486 duration d_; // exposition only
3488 constexpr __time_point__c_1();
3490 constexpr explicit __time_point__c_2(const duration& d);
3493 template <class __Duration2>
3495 __time_point__c_3(const time_point<clock, __Duration2>& t);
3498 constexpr duration __time_point__time_since_epoch() const;
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);
3510 time_point& __time_point__op_plus_eq_1(const rep& d);
3511 time_point& __time_point__op_minus_eq_1(const rep& d);
3514 time_point& __time_point__op_plus_eq_2(const duration& d);
3515 time_point& __time_point__op_minus_eq_2(const duration& d);
3519 static constexpr time_point __time_point__min();
3520 static constexpr time_point __time_point__max();
3523 Clock must meet the __clock_req.
3525 Duration must be an instantiation of __duration, compile diagnostic otherwise.
3527 [section:time_point_c_1 Constructor `time_point()`]
3529 constexpr time_point();
3531 __effects Constructs an object of __time_point, initializing `d_` with `duration::zero()`. This __time_point represents the epoch.
3534 [section:time_point_c_2 Constructor `time_point(const duration&)`]
3536 constexpr time_point(const duration& d);
3538 __effects Constructs an object of __time_point, initializing `d_` with `d`. This __time_point represents the epoch `+ d`.
3541 [section:time_point_c_3 Copy Constructor `time_point(const time_point&)`]
3543 template <class __Duration2>
3545 time_point(const __time_point<clock, __Duration2>& t);
3547 __requires This function will not participate in overload resolution unless `Duration2` is implicitly convertible to __duration.
3549 __effects Constructs an object of __time_point, initializing `d_` with `t.time_since_epoch()`.
3553 [section:time_since_epoch Member Function `time_since_epoch() const`]
3555 constexpr duration time_since_epoch() const;
3561 [section:op_unary_plus Member Function `operator+() const`]
3563 constexpr __time_point operator+() const;
3568 [section:op_unary_minus Member Function `operator-() const`]
3570 constexpr __time_point operator-() const;
3572 __returns `__time_point(-d_)`.
3575 [section:op_pre_inc Member Function `operator++()`]
3577 __time_point& operator++();
3584 [section:op_post_inc Member Function `operator++(int)`]
3586 __time_point operator++(int);
3588 __returns `__time_point(d_++)`.
3591 [section:op_pre_dec Member Function `operator--()`]
3593 __time_point& operator--();
3600 [section:op_post_dec Member Function `operator--(int)`]
3602 __time_point operator--(int);
3604 __returns `__time_point(d_--)`.
3608 [section:op_plus_eq_1 Member Function `operator+=(const rep&)`]
3610 __time_point& operator+=(const rep& r);
3612 __effects `d_ += duration(r)`.
3617 [section:op_minus_eq_1 Member Function `operator-=(const rep&)`]
3619 __time_point& operator-=(const rep& r);
3621 __effects `d_ -= duration(r)`
3628 [section:op_plus_eq_2 Member Function `operator+=`]
3630 time_point& operator+=(const duration& d);
3632 __effects `d_ += d`.
3637 [section:op_minus_eq_2 Member Function `operator-=`]
3639 time_point& operator-=(const duration& d);
3646 [section:min Static Member Function `min`]
3648 static constexpr time_point min();
3650 __returns `time_point(duration::min())`.
3653 [section:max Static Member Function `max`]
3655 static constexpr time_point max();
3657 __returns `time_point(duration::max())`.
3663 [section:arith `time_point` non-member arithmetic]
3666 [section:time_point__op_plus_1 Non-Member Function `operator+(time_point,duration)`]
3668 template <class __Clock, class __Duration1, class Rep2, class Period2>
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);
3674 __returns `CT(lhs.time_since_epoch() + rhs)` where `CT` is the type of the return value.
3677 [section:time_point__op_plus_2 Non-Member Function `operator+(duration,time_point)`]
3679 template <class Rep1, class Period1, class __Clock, class __Duration2>
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);
3685 __returns `rhs + lhs`.
3688 [section:time_point__op_minus_1 Non-Member Function `operator-(time_point,duration)`]
3690 template <class __Clock, class __Duration1, class Rep2, class Period2>
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);
3696 __returns `lhs + (-rhs)`.
3699 [section:time_point__op_minus_2 Non-Member Function `operator-(time_point,time_point)`]
3701 template <class __Clock, class __Duration1, class __Duration2>
3703 typename __common_type<Duration1, __Duration2>::type
3704 operator-(const __time_point<__Clock, __Duration1>& lhs,
3705 const __time_point<__Clock, __Duration2>& rhs);
3707 __returns `lhs.time_since_epoch() - rhs.time_since_epoch()`.
3712 [section:cmp `time_point` non-member comparisons]
3713 [section:time_point__op_eq Non-Member Function `operator==(time_point,time_point)`]
3715 template <class __Clock, class __Duration1, class __Duration2>
3717 bool operator==(const __time_point<__Clock, __Duration1>& lhs,
3718 const __time_point<__Clock, __Duration2>& rhs);
3720 __returns `lhs.time_since_epoch() == rhs.time_since_epoch()`.
3723 [section:time_point__op_neq Non-Member Function `operator!=(time_point,time_point)`]
3725 template <class __Clock, class __Duration1, class __Duration2>
3727 bool operator!=(const __time_point<__Clock, __Duration1>& lhs,
3728 const __time_point<__Clock, __Duration2>& rhs);
3730 __returns `!(lhs == rhs)`.
3733 [section:time_point__op_lt Non-Member Function `operator<(time_point,time_point)`]
3735 template <class __Clock, class __Duration1, class __Duration2>
3737 bool operator< (const __time_point<__Clock, __Duration1>& lhs,
3738 const __time_point<__Clock, __Duration2>& rhs);
3740 __returns lhs.time_since_epoch() < rhs.time_since_epoch().
3743 [section:time_point__op_leq Non-Member Function `operator<=(time_point,time_point)`]
3745 template <class __Clock, class __Duration1, class __Duration2>
3747 bool operator<=(const __time_point<__Clock, __Duration1>& lhs,
3748 const __time_point<__Clock, __Duration2>& rhs);
3750 __returns `!(rhs < lhs)`.
3753 [section:time_point__op_gt Non-Member Function `operator>(time_point,time_point)`]
3755 template <class __Clock, class __Duration1, class __Duration2>
3757 bool operator>(const __time_point<__Clock, __Duration1>& lhs,
3758 const __time_point<__Clock, __Duration2>& rhs);
3760 __returns `rhs < lhs`.
3763 [section:time_point__op_geq Non-Member Function `operator>=(time_point,time_point)`]
3765 template <class __Clock, class __Duration1, class __Duration2>
3767 bool operator>=(const __time_point<__Clock, __Duration1>& lhs,
3768 const __time_point<__Clock, __Duration2>& rhs);
3770 __returns `!(lhs < rhs)`.
3776 [section:time_point_cast Non-Member Function `time_point_cast(time_point)`]
3778 template <class __ToDuration, class __Clock, class __Duration>
3780 __time_point<__Clock, ToDuration> __time_point_cast(const __time_point<__Clock, __Duration>& t);
3782 __requires This function will not participate in overload resolution unless `ToDuration` is an instantiation of __duration.
3784 __returns `__time_point<__Clock, ToDuration>(__duration_cast<ToDuration>(t.time_since_epoch()))`.
3790 [/=============================================]
3791 [section:system_clocks_hpp Header `<boost/chrono/system_clocks.hpp>`]
3792 [/=============================================]
3794 This file contains the standard clock classes. The types defined in this section satisfy the __TrivialClock requirements
3800 class __system_clock;
3801 class __steady_clock;
3802 class __high_resolution_clock;
3804 template <class CharT>
3805 struct clock_string<system_clock, CharT>;
3806 template <class CharT>
3807 struct clock_string<steady_clock, CharT>;
3813 [section:system_clock Class `system_clock`]
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).
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
3819 std::time_t to_time_t(const time_point& t);
3821 which returns a `time_t` type that is based on midnight UTC of January 1, 1970.
3823 class system_clock {
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;
3832 static time_point now() noexcept;
3833 static time_point now(system::error_code & ec);
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;
3840 __system_clock satisfy the __clock_req:
3842 * `system_clock::duration::min() < system_clock::duration::zero()` is `true`.
3844 * The nested `duration` typedef has a resolution that depends on the one provided by the platform.
3846 [section:to_time_t Static Member Function `to_time_t(time_point)`]
3848 time_t to_time_t(const time_point& t) noexcept;
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`.
3853 [section:from_time_t Static Member Function `from_time_t(time_t)`]
3855 time_point from_time_t(time_t t) noexcept;
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`.
3862 [section:BOOST_CHRONO_HAS_CLOCK_STEADY Macro `BOOST_CHRONO_HAS_CLOCK_STEADY`]
3864 Defined if the platform support steady clocks.
3868 [section:steady_clock Class `steady_clock`]
3870 __steady_clock satisfy the __clock_req.
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.
3874 #ifdef BOOST_HAS_CLOCK_STEADY
3875 class steady_clock {
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;
3883 static time_point now() noexcept;
3884 static time_point now(system::error_code & ec);
3890 [section:high_resolution_clock Class `high_resolution_clock`]
3892 __high_resolution_clock satisfy the __clock_req.
3894 #ifdef __BOOST_CHRONO_HAS_CLOCK_STEADY
3895 typedef __steady_clock high_resolution_clock; // as permitted by [time.clock.hires]
3897 typedef __system_clock high_resolution_clock; // as permitted by [time.clock.hires]
3902 [section:clock_string_system_clock `clock_string<system_clock>` Specialization]
3904 template <class CharT>
3905 struct clock_string<system_clock, CharT>
3907 static std::basic_string<CharT> name();
3908 static std::basic_string<CharT> since();
3911 `clock_string<>::name()` returns "system_clock".
3913 `clock_string<>::since()` returns " since Jan 1, 1970"
3918 [section:clock_string_steady_clock `clock_string<steady_clock>` Specialization]
3920 #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
3922 template <class CharT>
3923 struct clock_string<steady_clock, CharT>
3925 static std::basic_string<CharT> name();
3926 static std::basic_string<CharT> since();
3930 `clock_string<>::name()` returns "steady_clock".
3932 `clock_string<>::since()` returns " since boot"
3938 [/==================================================================]
3939 [section:clock_strings_hpp Header `<boost/chrono/clock_strings.hpp>`]
3940 [/==================================================================]
3945 template <class __Clock, class CharT>
3946 struct clock_string;
3951 [section:clock_string Template Class `clock_string<>`]
3953 template <class __Clock, class CharT>
3954 struct clock_string;
3956 This template must be specialized for specific clocks. The specialization must define the following functions
3958 static std::basic_string<CharT> name();
3959 static std::basic_string<CharT> since();
3961 `clock_string<>::name()` return the clock name, which usually corresponds to the class name.
3963 `clock_string<>::since()` return the textual format of the clock epoch.
3968 [endsect] [/section:clock_strings_hpp Header `<boost/chrono/clock_strings.hpp>`]
3970 [/=============================================]
3971 [section:chrono_typeof_hpp Header `<boost/chrono/typeof/boost/chrono/chrono.hpp>`]
3972 [/=============================================]
3974 Register __duration`<>` and __time_point`<>` class templates to [*Boost.Typeof].
3979 [section:io_v1 Chrono I/O V1]
3980 [/==================================================================]
3981 [section:chrono_io_hpp Header `<boost/chrono/chrono_io.hpp>`]
3982 [/==================================================================]
3989 template <class CharT>
3990 class duration_punct;
3992 template <class CharT, class Traits>
3993 std::basic_ostream<CharT, Traits>&
3994 duration_short(std::basic_ostream<CharT, Traits>& os);
3996 template <class CharT, class Traits>
3997 std::basic_ostream<CharT, Traits>&
3998 duration_long(std::basic_ostream<CharT, Traits>& os);
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);
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)
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);
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);
4021 [section:duration_punct Template Class `duration_punct<>`]
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).
4025 template <class CharT>
4026 class duration_punct
4027 : public std::locale::facet
4030 typedef std::basic_string<CharT> string_type;
4031 enum {use_long, use_short};
4033 static std::locale::id id;
4035 explicit duration_punct(int use = use_long);
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);
4042 duration_punct(int use, const duration_punct& d);
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;
4048 bool is_short_name() const;
4049 bool is_long_name() const;
4054 [section:manipulators I/O Manipulators]
4056 The short or long format can be easily chosen by streaming a `duration_short` or `duration_long` manipulator respectively.
4058 template <class CharT, class Traits>
4059 std::basic_ostream<CharT, Traits>&
4060 duration_short(std::basic_ostream<CharT, Traits>& os);
4062 __effects Set the __duration_punct facet to stream __durations and __time_points as abbreviations.
4064 __returns the output stream
4066 template <class CharT, class Traits>
4067 std::basic_ostream<CharT, Traits>&
4068 duration_long(std::basic_ostream<CharT, Traits>& os);
4071 __effects Set the __duration_punct facet to stream durations and time_points as long text.
4073 __returns the output stream
4078 [section:streams I/O Streams Operations]
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.
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.
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);
4088 __effects outputs the __duration as an abbreviated or long text format depending on the state of the __duration_punct facet.
4090 __returns the output stream
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)
4096 __effects reads a __duration from the input stream. If a format error is found, the input stream state will be set to `failbit`.
4098 __returns the input stream
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);
4105 __effects outputs the __time_point as an abbreviated or long text format depending on the state of the __duration_punct facet.
4107 __returns the output stream
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);
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`.
4117 __returns the input stream
4125 [section:io Chrono I/O V2]
4127 [/==================================================================]
4128 [section:chrono_io_hpp Header `<boost/chrono/chrono_io.hpp>`]
4129 [/==================================================================]
4132 This file includes the i/o of the two major components, duration and time_point.
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>
4147 [endsect] [/section:chrono_io_hpp Header `<boost/chrono/chrono_io.hpp>`]
4149 [/==================================================================]
4150 [section:duration_style_hpp Header `<boost/chrono/io/duration_style.hpp>`]
4151 [/==================================================================]
4158 enum class __duration_style {
4164 [section:duration_style Scoped enum `duration_style`]
4166 enum class duration_style {
4170 __duration unit names come in two varieties: prefix and symbol.
4172 [endsect] [/section:duration_style Scoped enum `duration_style`]
4174 [endsect] [/section:duration_style_hpp Header `<boost/chrono/io/duration_style.hpp>`]
4176 [/==================================================================]
4177 [section:timezone_hpp Header `<boost/chrono/io/timezone.hpp>`]
4178 [/==================================================================]
4192 [section:timezone Scoped enum `timezone`]
4194 enum class timezone {
4198 [endsect] [/section:timezone Scoped enum `timezone`]
4201 [endsect] [/section:timezone_hpp Header `<boost/chrono/io/timezone.hpp>`]
4204 [/==================================================================]
4205 [section:ios_state_hpp Header `<boost/chrono/io/ios_base_state.hpp>`]
4206 [/==================================================================]
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);
4215 timezone __get_timezone(std::ios_base & ios);
4216 void __set_timezone(std::ios_base& ios, timezone tz);
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);
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;
4232 [section:sag Setter and getters]
4234 [section:get_duration_style Non Member Function `get_duration_style(std::ios_base &)`]
4236 duration_style get_duration_style(std::ios_base & ios);
4238 __returns The stream's __duration_style attribute associated to `ios`.
4242 [section:set_duration_style Non Member Function `set_duration_style(std::ios_base &,duration_style)`]
4244 void set_duration_style(std::ios_base& ios, duration_style style);
4246 __effects Set the stream's __duration_style attribute associated to `ios` with the `style` parameter.
4250 [section:get_timezone Non Member Function `get_timezone(std::ios_base&)`]
4252 timezone get_timezone(std::ios_base & ios);
4254 __returns The stream's __timezone attribute associated to `ios`.
4258 [section:set_timezone Non Member Function `set_timezone(std::ios_base&,duration_style)`]
4260 void set_timezone(std::ios_base& ios, timezone tz);
4262 __effects Set the stream's __timezone attribute associated to `ios` with the `tz` parameter.
4266 [section:get_time_fmt Non Member Function `get_time_fmt(std::ios_base &)`]
4268 template<typename CharT>
4269 std::basic_string<CharT> get_time_fmt(std::ios_base & ios);
4271 __returns The stream's time format attribute associated to `ios`.
4275 [section:set_time_fmt Non Member Function `set_time_fmt(std::ios_base&, std::basic_string<CharT> const&)`]
4277 template<typename CharT>
4278 void set_time_fmt(std::ios_base& ios, std::basic_string<CharT> const& fmt);
4280 __effects Set the stream's time format attribute associated to `ios` with the `fmt` parameter.
4282 The format is composed of zero or more directives.
4283 Each directive is composed of one of the following:
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.
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:
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).] [.]]
4326 [section:ioss I/O State Savers]
4327 [section:duration_style_io_saver Template Class `duration_style_io_saver`]
4331 struct duration_style_io_saver
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
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();
4342 The `state_type` is a version of the IOStreams base class `std::ios_base`.
4344 [section:c1 Constructor `duration_style_io_saver(state_type&)`]
4346 This constructor takes a stream object and saves a reference to the stream and
4347 the current value of a particular stream attribute.
4349 explicit duration_style_io_saver(state_type &s);
4351 __effects Constructs a __duration_style_io_saver by storing `s`.
4355 [section:c2 Constructor `duration_style_io_saver(state_type&, aspect_type)`]
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.
4360 explicit duration_style_io_saver(state_type &s, aspect_type new_value);
4362 __effects Constructs a __duration_style_io_saver by storing `s`. Sets the `state_type` `aspect_type` with the value `new_value`.
4366 [section:d Destructor `~duration_style_io_saver()`]
4368 The destructor restores the stream's attribute to the saved value.
4370 ~duration_style_io_saver();
4372 __effects As if __duration_style_io_saver__restore().
4375 [section:restore Member Function `restore()`]
4377 The restoration can be activated early (and often) with the restore member function.
4381 __effects Restores the stream's __duration_style attribute to the saved value.
4387 [section:timezone_io_saver Template Class `timezone_io_saver<>`]
4390 template<typename CharT = char, typename Traits = std::char_traits<CharT> >
4391 struct __timezone_io_saver
4393 typedef std::basic_ios<CharT, Traits> state_type;
4394 typedef __timezone aspect_type;
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();
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.
4405 [section:c1 Constructor `timezone_io_saver(state_type&)`]
4407 This constructor takes a stream object and saves a reference to the stream and the current value of a particular stream attribute.
4409 explicit timezone_io_saver(state_type &s);
4411 __effects Constructs a __timezone_io_saver by storing `s`.
4415 [section:c2 Constructor `timezone_io_saver(state_type&, aspect_type)`]
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.
4420 explicit timezone_io_saver(state_type &s, aspect_type new_value);
4422 __effects Constructs a __timezone_io_saver by storing `s`. Sets the `state_type` `aspect_type` with the value `new_value`.
4427 [section:d Destructor `~timezone_io_saver()`]
4429 The destructor restores the stream's attribute to the saved value.
4431 ~timezone_io_saver();
4433 __effects As if __timezone_io_saver__restore().
4436 [section:restore Member Function `restore()`]
4438 The restoration can be activated early (and often) with the restore member function.
4442 __effects Restores the stream's __timezone attribute to the saved value.
4449 [section:time_fmt_io_saver Template Class `time_fmt_io_saver<>`]
4451 template<typename CharT = char, typename Traits = std::char_traits<CharT> >
4452 struct __time_fmt_io_saver
4454 typedef std::basic_ios<CharT, Traits> state_type;
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();
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.
4465 [section:c1 Constructor `time_fmt_io_saver(state_type&)`]
4467 This constructor takes a stream object and saves a reference to the stream and the current value of a particular stream attribute.
4469 explicit time_fmt_io_saver(state_type &s);
4471 __effects Constructs a __time_fmt_io_saver by storing `s`.
4475 [section:c2 Constructor `time_fmt_io_saver(state_type&, aspect_type)`]
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.
4480 explicit time_fmt_io_saver(state_type &s, aspect_type new_value);
4482 __effects Constructs a __time_fmt_io_saver by storing `s`. Sets the `state_type` `aspect_type` with the value `new_value`.
4487 [section:d Destructor `~time_fmt_io_saver()`]
4489 The destructor restores the stream's attribute to the saved value.
4491 ~time_fmt_io_saver();
4493 __effects As if __time_fmt_io_saver__restore().
4496 [section:restore Member Function `restore()`]
4498 The restoration can be activated early (and often) with the restore member function.
4502 __effects Restores the stream's time format attribute to the saved value.
4509 [endsect] [/section:ios_state_hpp Header `<boost/chrono/io/ios_sate.hpp>`]
4511 [/==================================================================]
4512 [section:duration_get_hpp Header `<boost/chrono/io/duration_get.hpp>`]
4513 [/==================================================================]
4518 template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
4519 class __duration_get;
4524 [section:duration_get Template Class `duration_get`]
4526 template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
4527 class duration_get: public std::locale::facet
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.
4534 explicit __duration_get_c(size_t refs = 0);
4536 template <typename Rep, typename Period>
4537 iter_type __duration_get_get(
4541 std::ios_base::iostate& err,
4542 duration<Rep, Period>& d,
4543 const char_type* pattern,
4544 const char_type* pat_end
4547 template <typename Rep, typename Period>
4548 iter_type __duration_get_get2(
4552 std::ios_base::iostate& err,
4553 duration<Rep, Period>& d
4556 template <typename Rep>
4557 iter_type __duration_get_get_value(
4561 std::ios_base::iostate& err,
4565 iter_type __duration_get_get_unit(
4569 std::ios_base::iostate& err,
4570 detail::rt_ratio &rt
4573 static std::locale::id id; // Unique identifier for this type of facet.
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
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.
4591 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4592 [section:c Constructor `duration_get(size_t)`]
4594 explicit duration_get(size_t refs);
4596 Constructs a __duration_get facet.
4600 * [param refs] references
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.
4611 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4612 [section:d Destructor `~duration_get()`]
4616 Destructs a __duration_get facet.
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`]
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;
4626 Extracts a duration from the range `[s,end)` following the pattern `[pattern,pat_end)`.
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
4638 __requires `[s, end) and [pattern, pat_end)` shall be valid ranges.
4640 __effects The function starts by evaluating `err = std::ios_base::goodbit`.
4642 Then it computes an intermediate representation based on `Rep` according to the following rules:
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`.
4649 Next the following local variable `r` of type intermediate representation and `rt` of type `rt_ratio` are default constructed.
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:
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
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`.
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`.
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`.
4691 __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid duration.
4694 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4695 [section:get2 Template Member Function `get(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,duration<Rep,Period>&) const`]
4697 template <typename Rep, typename Period>
4702 std::ios_base::iostate& err,
4703 duration<Rep, Period>& d
4706 Extracts a duration from the range `[s,end)` following the default pattern.
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
4718 Stores the duration pattern from the __duration_unit facet associated to 'ios` in let say `str`. Last as if
4720 return get(s, end, ios, err, ios, d, str.data(), str.data() + str.size());
4722 __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid duration.
4726 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4727 [section:get_value Template Member Function `get_value(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,Rep&) const`]
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;
4732 Extracts a duration representation from the range `[s,end)`.
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
4744 return std::use_facet<std::num_get<char_type, iter_type>>(ios.getloc()).get(s, end, ios, err, r);
4746 __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid `Rep` value.
4749 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4750 [section:get_unit Member Function `get_unit(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,rt_ratio&) const`]
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;
4754 Extracts a duration unit from the range `[s,end)`.
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.
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
4771 return do_get_n_d_prefix_unit(facet, i, e, is, err);
4773 * Otherwise the next character is not `'['`. Return the parse the longest string possible matching one of the
4774 durations units, as if
4776 return do_get_prefix_unit(facet, i, e, is, err, rt);
4778 __returns `i`, an iterator pointing just beyond the last character that can be determined to be part of a valid duration unit.
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`]
4784 virtual iter_type do_get_n_d_prefix_unit(
4785 duration_units<CharT> const &facet,
4789 std::ios_base::iostate& err
4792 Extracts the run-time ratio associated to the duration when it is given in [N/D] form.
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.
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.
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`.
4809 __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid name.
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`]
4815 virtual iter_type do_get_prefix_unit(
4816 duration_units<CharT> const &facet,
4820 std::ios_base::iostate& err,
4821 detail::rt_ratio &rt
4824 Extracts the run-time ratio associated to the duration when it is given in prefix form.
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.
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.
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`.
4841 __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid name.
4844 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4848 [endsect] [/section:duration_get_hpp]
4850 [/==================================================================]
4851 [section:duration_put_hpp Header `<boost/chrono/io/duration_put.hpp>`]
4852 [/==================================================================]
4857 template <class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
4858 class __duration_put;
4863 [section:duration_put Template Class `duration_put`]
4865 template <class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
4866 class duration_put: public std::locale::facet
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.
4873 explicit __duration_put_c(size_t refs = 0);
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;
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;
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;
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;
4889 static std::locale::id id; // Unique identifier for this type of facet.
4894 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4895 [section:c Constructor `duration_put(size_t)`]
4897 explicit duration_put(size_t refs);
4899 Constructs a __duration_put facet.
4903 * [param refs] references
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.
4914 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4915 [section:d Destructor `~duration_put()`]
4919 Destructs a __duration_put facet.
4922 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4923 [section:put Member Function `put(iter_type,std::ios_base&,char_type,duration<Rep,Period> const&, const CharT*,const CharT*)`]
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;
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
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)`.
4951 __returns An iterator pointing immediately after the last character produced.
4955 [section:put2 Member Function `put(iter_type,std::ios_base&,char_type fill, duration<Rep, Period> const&)`]
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;
4962 * [param s] an output stream iterator
4963 * [param ios] a reference to a ios_base
4964 * [param d] the duration
4966 Retrieves Stores the duration pattern from the __duration_unit facet in let say `str`. Last as if
4968 return put(s, ios, d, str.data(), str.data() + str.size());
4970 __returns An iterator pointing immediately after the last character produced.
4973 [section:put_value Member Function `put_value(iter_type, std::ios_base&, char_type, duration<Rep,Period> const&)`]
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;
4980 * [param s] an output stream iterator
4981 * [param ios] a reference to a ios_base
4982 * [param d] the duration
4984 __effects As if std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, ' ', static_cast<long int> (d.count())).
4986 __returns An iterator pointing immediately after the last character produced.
4989 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
4990 [section:put_unit Member Function `put_unit(iter_type,std::ios_base&,char_type,duration<Rep, Period> const&)`]
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;
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
5002 __effects Let `facet` be the `duration_units<CharT>` facet associated to `ios`. If the associated unit is named, as if
5004 string_type str = facet.get_unit(get_duration_style(ios), d);
5005 s=std::copy(str.begin(), str.end(), s);
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)`.
5009 __returns s, iterator pointing immediately after the last character produced.
5012 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
5015 [endsect] [/section:duration_put_hpp]
5017 [/==================================================================]
5018 [section:duration_units_hpp Header `<boost/chrono/io/duration_units.hpp>`]
5019 [/==================================================================]
5024 template <typename CharT = char>
5025 class duration_units;
5031 [section:rt_ratio Class `rt_ratio`]
5036 template <typename Period>
5037 rt_ratio(Period const&) :
5038 num(Period::type::num), den(Period::type::den)
5042 rt_ratio(intmax_t n = 0, intmax_t d = 1) :
5052 [section:duration_units Template Class `duration_units`]
5054 template <typename CharT = char>
5055 class duration_units: public std::locale::facet
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.
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;
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;
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,
5088 [section:c Constructor `duration_units()`]
5090 explicit duration_units(size_t refs = 0);
5092 Construct a __duration_units facet.
5096 * [param refs] references
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.
5107 [section:d Destructor `~duration_units()`]
5109 virtual ~duration_units();
5111 __effects Destroys the facet.
5114 [section:get_n_d_valid_units_start Member Function `get_n_d_valid_units_start()`]
5116 virtual const string_type* get_n_d_valid_units_start() const =0;
5118 __returns pointer to the start of valid [N/D] units.
5122 [section:get_n_d_valid_units_end Member Function `get_n_d_valid_units_end()`]
5124 virtual const string_type* get_n_d_valid_units_end() const=0;
5126 __returns pointer to the end of valid [N/D] units.
5129 [section:get_valid_units_start Member Function `get_valid_units_start()`]
5131 virtual const string_type* get_valid_units_start() const=0;
5133 __returns pointer to the start of valid units, symbol or prefix with its different plural forms.
5136 [section:get_valid_units_end Member Function `get_valid_units_end()`]
5138 virtual const string_type* get_valid_units_end() const=0;
5140 __returns pointer to the end of valid units.
5143 [section:match_n_d_valid_unit Member Function `match_n_d_valid_unit(const string_type*)`]
5145 virtual bool match_n_d_valid_unit(const string_type* k) const = 0;
5149 * [param k] the found pointer to the [N/D] unit.
5151 __returns `true` if `k` matches a valid unit.
5154 [section:match_valid_unit Member Function `match_valid_unit(const string_type*,rt_ratio&)`]
5156 virtual bool match_valid_unit(const string_type* k, rt_ratio& rt) const = 0;
5160 * [param k] the found pointer to the unit.
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.
5166 [section:get_pattern Member Function `get_pattern()`]
5168 virtual string_type get_pattern() const=0;
5170 __returns the pattern to be used by default.
5173 [section:get_unit Template Member Function `get_unit(duration_style,duration<Rep,Period> const&)`]
5175 template <typename Rep, typename Period>
5176 string_type get_unit(duration_style style, duration<Rep, Period> const& d) const;
5179 __returns `get_unit(style, d.count(), rt_ratio(Period()))`, the unit associated to this duration.
5183 [section:get_n_d_unit Template Member Function `get_n_d_unit(duration_style,duration<Rep,Period> const&)`]
5185 template <typename Rep, typename Period>
5186 string_type get_n_d_unit(duration_style style, duration<Rep, Period> const& d) const;
5188 __returns get_n_d_unit(style, d.count(), rt_ratio(Period())), i.e. the [N/D] suffix unit associated to this duration.
5192 [section:is_named_unit Template Member Function `is_named_unit()`]
5194 template <typename Period>
5195 bool is_named_unit() const;
5197 __returns `do_is_named_unit(rt_ratio(Period()))`, true if the unit associated to the given Period is named, false otherwise.
5201 [section:do_get_n_d_unit Protected Member Function `do_get_n_d_unit(duration_style,rt_ratio,intmax_t)`]
5203 virtual string_type do_get_n_d_unit(duration_style style, rt_ratio rt, intmax_t v) const = 0;
5205 __returns the [N/D] suffix unit associated to this duration.
5209 [section:do_get_unit Protected Member Function `do_get_unit(duration_style,rt_ratio,intmax_t)`]
5211 virtual string_type do_get_unit(duration_style style,rt_ratio rt, intmax_t v) const = 0;
5213 __returns the unit associated to this duration.
5217 [section:do_is_named_unit Protected Member Function `do_is_named_unit(rt_ratio)`]
5219 virtual bool do_is_named_unit(rt_ratio rt) const =0;
5221 __returns true if the unit associated to the given Period is named, false otherwise.
5225 [endsect] [/section:duration_units]
5227 [section:duration_units_default Template Class `duration_units_default`]
5229 template <typename CharT = char>
5230 class duration_units_default: public duration_units<CharT>
5233 static const std::size_t pfs_ = 2; // The default English facet has two plural forms.
5236 typedef CharT char_type;
5237 typedef std::basic_string<CharT> string_type;
5239 explicit duration_units_default(size_t refs = 0);
5240 ~duration_units_default();
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;
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;
5254 virtual std::size_t do_get_plural_forms() const;
5255 virtual std::size_t do_get_plural_form(int_least64_t value) const;
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;
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;
5295 This class is used to define the strings for the default English.
5296 This facet names the units associated to the following periods:
5319 [section:c Constructor `duration_units_default()`]
5321 explicit duration_units_default(size_t refs = 0);
5323 Construct a duration_units_default facet.
5327 * [param refs] references
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.
5338 [section:d Destructor `~duration_units_default()`]
5340 virtual ~duration_units_default();
5342 __effects Destroys the facet.
5345 [section:get_n_d_valid_units_start Member Function `get_n_d_valid_units_start()`]
5347 virtual const string_type* get_n_d_valid_units_start() const;
5349 __returns pointer to the start of valid [N/D] units.
5353 [section:get_n_d_valid_units_end Member Function `get_n_d_valid_units_end()`]
5355 virtual const string_type* get_n_d_valid_units_end() const;
5357 __returns pointer to the end of valid [N/D] units.
5360 [section:get_valid_units_start Member Function `get_valid_units_start()`]
5362 virtual const string_type* get_valid_units_start() const;
5364 __returns pointer to the start of valid units, symbol or prefix with its different plural forms.
5367 [section:get_valid_units_end Member Function `get_valid_units_end()`]
5369 virtual const string_type* get_valid_units_end() const;
5371 __returns pointer to the end of valid units.
5374 [section:match_n_d_valid_unit Member Function `match_n_d_valid_unit(const string_type*)`]
5376 virtual bool match_n_d_valid_unit(const string_type* k) const;
5380 * [param k] the found pointer to the [N/D] unit.
5382 __returns `true` if `k` matches a valid unit.
5385 [section:match_valid_unit Member Function `match_valid_unit(const string_type*,rt_ratio&)`]
5387 virtual bool match_valid_unit(const string_type* k, rt_ratio& rt) const;
5391 * [param k] the found pointer to the unit.
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.
5397 [section:get_pattern Member Function `get_pattern()`]
5399 virtual string_type get_pattern() const;
5401 __returns the pattern to be used by default.
5405 [section:do_get_n_d_unit Protected Member Function `do_get_n_d_unit(duration_style,rt_ratio,intmax_t)`]
5407 virtual string_type do_get_n_d_unit(duration_style style, rt_ratio rt, intmax_t v) const;
5409 __returns the [N/D] suffix unit associated to this duration.
5413 [section:do_get_unit Protected Member Function `do_get_unit(duration_style,rt_ratio,intmax_t)`]
5415 virtual string_type do_get_unit(duration_style style,rt_ratio rt, intmax_t v) const;
5417 __returns the unit associated to this duration.
5421 [section:do_is_named_unit Protected Member Function `do_is_named_unit(rt_ratio)`]
5423 virtual bool do_is_named_unit(rt_ratio rt) const;
5425 __returns true if the unit associated to the given Period is named, false otherwise.
5429 [section:do_get_plural_forms Protected Member Function `do_get_plural_forms()`]
5431 virtual std::size_t do_get_plural_forms() const;
5433 __returns the number of associated plural forms this facet manages.
5437 [section:do_get_plural_form Protected Member Function `do_get_plural_form(int_least64_t)`]
5439 virtual std::size_t do_get_plural_form(int_least64_t value) const;
5441 Gets the associated plural form.
5445 [param value] the duration representation
5447 __returns the plural form associated to the `value` parameter. In English there are 2 plural forms
5449 * 0 singular (-1 or 1)
5450 * 1 plural for all others
5454 [section:do_get_unit_seconds Protected Member Function `do_get_unit(duration_style,ratio<1>,std::size_t)`]
5456 virtual string_type do_get_unit(duration_style style, ratio<1> u, std::size_t pf) const;
5460 * [param style] the duration style.
5461 * [param period] the period associated to the duration hours.
5462 * [param pf] the requested plural form.
5464 __returns if style is symbol returns "s", otherwise if pf is 0 return "second", if pf is 1 "seconds"
5468 [section:do_get_unit_minutes Protected Member Function `do_get_unit(duration_style style,ratio<60>,std::size_t)`]
5470 virtual string_type do_get_unit(duration_style style, ratio<60> u, std::size_t pf) const;
5474 * [param style] the duration style.
5475 * [param period] the period associated to the duration hours.
5476 * [param pf] the requested plural form.
5478 __returns if style is symbol returns "min", otherwise if pf is 0 return "minute", if pf is 1 "minutes"
5482 [section:do_get_unit_hours Protected Member Function `do_get_unit(duration_style,ratio<3600>,std::size_t)`]
5484 virtual string_type do_get_unit(duration_style style, ratio<3600> u, std::size_t pf) const;
5488 * [param style] the duration style.
5489 * [param period] the period associated to the duration hours.
5490 * [param pf] the requested plural form.
5492 __returns if style is symbol returns "h", otherwise if pf is 0 return "hour", if pf is 1 "hours"
5496 [section:do_get_unit_xxx Protected Member Function `do_get_unit(duration_style,Period,std::size_t)`]
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;
5517 * [param style] the duration style.
5518 * [param u] the period tag atto.
5519 * [param pf] the requested plural form.
5521 __returns the concatenation of the prefix associated to period `u` + the one associated to seconds.
5525 [section:do_get_ratio_prefix_xxx Protected Member Function `do_get_ratio_prefix(duration_style, Period)`]
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;
5546 * [param style] the duration style.
5547 * [param u] the period tag atto.
5549 __returns depending on the value of `style` return the ratio_string symbol or prefix.
5554 [endsect] [/section:duration_units_default]
5556 [endsect] [/section:duration_units_hpp]
5558 [/==================================================================]
5559 [section:duration_io_hpp Header `<boost/chrono/io/duration_io.hpp>`]
5560 [/==================================================================]
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);
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);
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);
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)
5593 [section:manipulators I/O Manipulators]
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.
5598 [section:duration_fmt Template Class `duration_fmt`]
5604 explicit __duration_fmt__c1(__duration_style style) noexcept;
5606 #ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
5608 __duration_fmt__op_duration_style() const noexcept;
5610 __duration_style __duration_fmt__get_duration_style() const noexcept;
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);
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);
5622 [section:c1 Constructor `duration_fmt(duration_style)`]
5624 explicit duration_fmt(duration_style f) noexcept;
5626 __effects Constructs a __duration_fmt by storing `f`.
5628 __postcondition `static_cast<duration_style>(*this) == f`.
5631 [section:op_duration_style Member Function `operator duration_style()`]
5633 explicit operator duration_style() const noexcept;
5634 duration_style get_duration_style() const noexcept;
5636 __returns: The stored __duration_fmt `f`.
5639 [section:op_out Member Function `operator <<(basic_ostream<>&, duration_fmt)`]
5641 template<class CharT, class Traits>
5642 basic_ostream<CharT, Traits>&
5643 operator<<(basic_ostream<CharT, Traits>& s, duration_fmt d);
5645 __effects: `__set_duration_style(s, static_cast<__duration_style>(d))))`.
5650 [section:op_in Member Function `operator >>(basic_istream<>&, duration_fmt)`]
5652 template<class CharT, class Traits>
5653 basic_istream<CharT, Traits>&
5654 operator>>(basic_istream<CharT, Traits>& s, duration_fmt d);
5656 __effects: `__set_duration_style(s, static_cast<__duration_style>(d))))`.
5663 [section:symbol_format Non Member Function `symbol_format(ios_base&)`]
5665 std::ios_base& __symbol_format(ios_base& ios);
5667 __effects: `__set_duration_style(s, __duration_style::symbol)`.
5672 [section:name_format Non Member Function `name_format(ios_base&)`]
5674 std::ios_base& __name_format(ios_base& ios);
5676 __effects: `__set_duration_style(s, __duration_style::prefix)`.
5685 [section:streams I/O Streams Operations]
5687 [section:duration__op_out Member Function `operator <<(basic_ostream<>&, const duration<>& d)`]
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.
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);
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.
5705 [section:duration__op_in Member Function `operator <<(basic_istream<>&, const duration<>& d)`]
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)
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.
5715 If any step fails, calls `os.setstate(std::ios_base::failbit | std::ios_base::badbit)`.
5723 [endsect] [/section:duration_io_hpp Header `<boost/chrono/io/duration_io.hpp>`]
5725 [/==================================================================]
5726 [section:time_point_get_hpp Header `<boost/chrono/io/time_point_get.hpp>`]
5727 [/==================================================================]
5731 template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
5732 class time_point_get;
5736 [section:time_point_get Template Class `time_point_get`]
5738 template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
5739 class time_point_get: public std::locale::facet
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.
5745 explicit __time_point_get_c(size_t refs = 0);
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;
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;
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;
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;
5762 static std::locale::id id; // Unique identifier for this type of facet.
5764 __time_point_get_d();
5768 `time_point_get` is used to parse a character sequence, extracting
5769 the duration and the epoch into a class `time_point`.
5771 The pattern can contain the format specifiers `%d` and `%e` in any order.
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.
5778 If the end iterator is reached during parsing the member function sets `std::ios_base::eofbit` in `err`.
5780 [section:c Constructor `time_point_get(size_t)`]
5782 explicit time_point_get(size_t refs);
5784 Constructs a __time_point_get facet.
5788 * [param refs] references
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.
5800 [section:d Destructor `~time_point_get()`]
5804 __effects Destroy the facet.
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*)`]
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;
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
5823 __requires `[pattern,pat_end)` must be a valid range.
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:
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
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`.
5855 __returns An iterator pointing just beyond the last character that can be determined to be part of a valid time_point.
5859 [section:get2 Template Member Function `get(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,time_point<Clock,Duration>&)`]
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;
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
5873 __effects Stores the duration pattern from the `duration_unit` facet in let say `str`. Last as if
5875 return get(s, end, ios, err, ios, d, str.data(), str.data() + str.size());
5877 __returns An iterator pointing just beyond the last character that can be determined to be part of a valid name.
5880 [section:get_duration Template Member Function `get_duration(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,duration<Rep,Period>&)`]
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;
5888 return facet.get(s, end, ios, err, d);
5890 where `facet` is either the `duration_get` facet associated to the `ios` or an instance of the default `duration_get` facet.
5892 __returns An iterator pointing just beyond the last character that can be determined to be part of a valid duration.
5895 [section:get_epoch Template Member Function `get_epoch(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&)`]
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;
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.
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`.
5907 __returns An iterator pointing just beyond the last character that can be determined to be part of a epoch.
5911 [endsect] [/section:time_point_get]
5914 [endsect] [/section:time_point_get_hpp]
5916 [/==================================================================]
5917 [section:time_point_put_hpp Header `<boost/chrono/io/time_point_put.hpp>`]
5918 [/==================================================================]
5922 template <class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
5923 class time_point_put;
5928 [section:time_point_put Template Class `time_point_put`]
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.
5934 tparam ChatT a character type
5935 tparam OutputIterator a model of `OutputIterator`
5938 template <class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
5939 class time_point_put: public std::locale::facet
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.
5946 explicit time_point_put(size_t refs = 0);
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;
5959 static std::locale::id id; // Unique identifier for this type of facet.
5965 [section:c Constructor `time_point_get(size_t)`]
5967 explicit time_point_put(size_t refs = 0);
5970 Construct a time_point_put facet.
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.
5982 * [param refs] references
5986 [section:put1 Member Function `put()`]
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;
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
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)`.
6017 __returns An iterator pointing immediately after the last character produced.
6021 [section:put2 Member Function `put()`]
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;
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
6035 __effects Stores the time_point pattern from the __time_point_unit facet in let say `str`. Last as if
6037 return put(s, ios, fill, tp, str.data(), str.data() + str.size());
6039 __returns An iterator pointing immediately after the last character produced.
6043 [section:put_duration Member Function `put_duration()`]
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;
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
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>`.
6058 __returns An iterator pointing immediately after the last character produced.
6062 [section:put_epoch Member Function `put_epoch()`]
6064 template <typename Clock>
6065 iter_type put_epoch(iter_type i, std::ios_base& os) const;
6069 * [param i] an output stream iterator
6070 * [param ios] a reference to a ios_base
6074 string_type str = facet.template get_epoch<Clock>();
6075 s=std::copy(str.begin(), str.end(), s);
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>`.
6081 __returns s, iterator pointing immediately after the last character produced.
6087 [endsect] [/section:time_point_put_hpp]
6089 [/==================================================================]
6090 [section:time_point_units_hpp Header `<boost/chrono/io/time_point_units.hpp>`]
6091 [/==================================================================]
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,
6104 [section:get_epoch_custom Template Function `get_epoch_custom`]
6106 template <typename CharT, typename Clock, typename TPUFacet>
6107 std::basic_string<CharT> get_epoch_custom(Clock, TPUFacet& f);
6110 Customization point to the epoch associated to the clock `Clock`
6111 The default calls `f.do_get_epoch(Clock())`.
6113 The user can overload this function.
6116 __returns Forwards the call to the facet as if
6118 return f.do_get_epoch(Clock());
6122 [//////////////////////////////////////////////////////////]
6123 [section:time_point_units Template Class `time_point_units`]
6126 __time_point_units facet gives useful information about the time_point pattern,
6127 the text associated to a time_point's epoch,
6129 template <typename CharT=char>
6130 class time_point_units: public std::locale::facet
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.
6137 explicit time_point_units(size_t refs = 0);
6139 virtual string_type get_pattern() const =0;
6140 template <typename Clock>
6141 string_type get_epoch() const;
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;
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;
6154 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
6155 virtual string_type do_get_epoch(thread_clock) const=0;
6161 [section:c Constructor `time_point_units()`]
6163 explicit time_point_units(size_t refs = 0);
6165 Construct a __time_point_units facet.
6169 * [param refs] references
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.
6181 [section:get_pattern Member Function `get_pattern()`]
6183 virtual string_type get_pattern() const =0;
6185 __returns the pattern to be used by default.
6189 [section:get_epoch Member Function `get_epoch()`]
6191 template <typename Clock>
6192 string_type get_epoch() const;
6194 __returns the epoch associated to the clock `Clock` as if `return get_epoch_custom<CharT>(Clock(), *this);
6199 [section:d Destructor `time_point_units()`]
6201 virtual ~time_point_units();
6207 [section:do_get_epoch_system_clock Member Function `do_get_epoch(system_clock)`]
6209 virtual string_type do_get_epoch(system_clock) const=0;
6213 * [param c] a dummy instance of __system_clock.
6215 __returns The epoch string associated to the __system_clock.
6219 [section:do_get_epoch_steady_clock Member Function `do_get_epoch(steady_clock)`]
6221 virtual string_type do_get_epoch(steady_clock) const=0;
6225 * [param c] a dummy instance of __steady_clock.
6227 __returns The epoch string associated to the __steady_clock.
6231 [section:do_get_epoch_process_real_cpu_clock Member Function `do_get_epoch(process_real_cpu_clock)`]
6233 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
6234 virtual string_type do_get_epoch(process_real_cpu_clock) const=0;
6239 * [param c] a dummy instance of __process_real_cpu_clock.
6241 __returns The epoch string associated to the __process_real_cpu_clock.
6245 [section:do_get_epoch_process_user_cpu_clock Member Function `do_get_epoch(process_user_cpu_clock)`]
6247 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
6248 virtual string_type do_get_epoch(process_user_cpu_clock) const=0;
6253 * [param c] a dummy instance of __process_real_cpu_clock.
6255 __returns The epoch string associated to the process_user_cpu_clock.
6259 [section:do_get_epoch_process_system_cpu_clock Member Function `do_get_epoch(process_system_cpu_clock)`]
6261 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
6262 virtual string_type do_get_epoch(process_system_cpu_clock) const=0;
6267 * [param c] a dummy instance of __process_system_cpu_clock.
6269 __returns The epoch string associated to the process_user_cpu_clock.
6273 [section:do_get_epoch_process_process_cpu_clock Member Function `do_get_epoch(process_cpu_clock)`]
6275 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
6276 virtual string_type do_get_epoch(process_cpu_clock) const=0;
6281 * [param c] a dummy instance of __process_cpu_clock.
6283 __returns The epoch string associated to the process_cpu_clock.
6287 [section:do_get_epoch_process_thread_clock Member Function `do_get_epoch(thread_clock)`]
6289 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
6290 virtual string_type do_get_epoch(thread_clock) const=0;
6295 * [param c] a dummy instance of __thread_clock.
6297 __returns The epoch string associated to the __thread_clock.
6303 [section:time_point_units_default Template Class `time_point_units_default`]
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>
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.
6313 explicit time_point_units_default(size_t refs = 0);
6314 ~time_point_units_default();
6317 * __returns the default pattern "%d%e".
6319 string_type get_pattern() const;
6323 * [param c a dummy instance of __system_clock.
6324 * __returns The epoch string returned by `clock_string<system_clock,CharT>::since()`.
6326 string_type do_get_epoch(system_clock ) const;
6328 * [param c a dummy instance of __steady_clock.
6329 * __returns The epoch string returned by `clock_string<steady_clock,CharT>::since()`.
6331 string_type do_get_epoch(steady_clock ) const;
6332 #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
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()`.
6337 string_type do_get_epoch(process_real_cpu_clock ) const;
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()`.
6342 string_type do_get_epoch(process_user_cpu_clock ) const;
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()`.
6347 string_type do_get_epoch(process_system_cpu_clock ) const;
6349 * [param c a dummy instance of __process_cpu_clock.
6350 * __returns The epoch string returned by `clock_string<process_cpu_clock,CharT>::since()`.
6352 string_type do_get_epoch(process_cpu_clock ) const;
6355 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
6357 * [param c a dummy instance of __thread_clock.
6358 * __returns The epoch string returned by `clock_string<thread_clock,CharT>::since()`.
6360 string_type do_get_epoch(thread_clock ) const;
6366 [endsect] [/section:time_point_units_hpp]
6369 [/==================================================================]
6370 [section:time_point_io_hpp Header `<boost/chrono/io/time_point_io.hpp>`]
6371 [/==================================================================]
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);
6388 template<typename CharT = char, typename Traits = std::char_traits<CharT> >
6389 struct __timezone_io_saver
6391 typedef std::basic_ios<CharT, Traits> state_type;
6392 typedef timezone aspect_type;
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();
6400 template<typename CharT = char, typename Traits = std::char_traits<CharT> >
6401 struct __time_fmt_io_saver
6403 typedef std::basic_ios<CharT, Traits> state_type;
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();
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);
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);
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);
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);
6440 [section:manip I/O Manipulators]
6441 [section:time_fmt1 Non Member Function `time_fmt(__timezone)` ]
6443 unspecified time_fmt(__timezone tz);
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:
6447 __set_timezone(s, tz);
6451 [section:time_fmt2 Non Member Function `time_fmt(__timezone, string)` ]
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);
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:
6460 __set_timezone(s, tz);
6461 __set_time_fmt<CharT>(s, f);
6468 [section:streams I/O Streams Operations]
6470 [section:system_clock `system_clock`]
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:
6476 - [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile
6478 - [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile
6480 In this case the io operators behave like any time_point as if the specialization was removed.
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`.
6486 [section:op_out Non Member Function `operator<<()`]
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);
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.
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).
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.
6504 If the formatting string is empty, then output as follows:
6506 First output `tm` using `"%F %H:%M:"`
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'`.
6513 Finally if `tz` is __local, output the `tm` using the pattern " %z". Else append the sequence " +0000" to the stream.
6515 If any step fails, calls `os.setstate(ios_base::failbit | ios_base::badbit)`.
6520 [section:op_in Non Member Function `operator>>()`]
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);
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.
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.
6538 void test(std::chrono::system_clock::time_point tp)
6540 std::stringstream s;
6542 boost::chrono::system_clock::time_point tp2;
6554 [section:other_clocks Other Clocks]
6555 [section:op_out Non Member Function `operator<<()`]
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);
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.
6571 22644271279698 nanoseconds since boot
6575 [section:op_in Non Member Function `operator>>()`]
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);
6582 Extracts `tp` from the stream `is`.
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.
6588 If any step fails, calls `os.setstate(std::ios_base::failbit | std::ios_base::badbit)`.
6599 [endsect] [/section:time_point_io_hpp Header `<boost/chrono/io/time_point_io.hpp>`]
6604 [/==================================================================]
6605 [section:duration_unit_string_hpp Header `<boost/chrono/io/duration_unit_string.hpp>`]
6606 [/==================================================================]
6608 namespace boost { namespace chrono {
6610 template <class Period, class CharT>
6611 struct duration_period_strings
6613 static std::basic_string<CharT> plural();
6614 static std::basic_string<CharT> singular();
6615 static std::basic_string<CharT> symbol();
6618 template <class Period, class CharT>
6619 struct duration_period
6621 static std::basic_string<CharT> prefix(std::basic_string<CharT> const& translation);
6622 static std::basic_string<CharT> symbol();
6625 template <class CharT, class Rep, class Period>
6626 std::basic_string<CharT> duration_unit_string(
6628 duration<Rep,Period> const& d);
6632 [section:duration_period_suffix Template Class `duration_period_suffix<>`]
6636 [section: duration_unit_string Non Member Function `duration_unit_string()`]
6638 template <class CharT, class Rep, class Period>
6639 std::basic_string<CharT> duration_unit_string(
6641 duration<Rep,Period> const& d);
6643 First units are obtained from `Period::type` and stored in two `basic_string<CharT>` (e.g. singular/plural) according to the following rules:
6645 * If `is_prefix` is `true`
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"`.
6652 Finally the intermediary unit string obtained by calling __duration_prefix_translate function with the `singular`, `plural` and the duration `d` as parameters.
6654 * If `is_prefix` is `true`
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"`.
6661 Finally the intermediary unit string is obtained by calling duration_symbol_translate function
6663 Note: The string literals above need to be converted to the correct literal type to be assigned to a `basic_string<CharT>`.
6667 [endsect] [/section:duration_units_string_hpp Header `<boost/chrono/io/duration_uinit_string.hpp>`]
6669 [/==================================================================]
6670 [section:translate_hpp Header `<boost/chrono/io/translate.hpp>`]
6671 [/==================================================================]
6673 namespace boost { namespace chrono {
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,
6682 template <class CharT>
6683 std::basic_string<CharT> duration_symbol_translate(
6684 std::basic_string<CharT> const &symbol);
6686 template <class CharT>
6687 std::basic_string<CharT> epoch_translate(
6688 std::basic_string<CharT> const &epoch);
6695 The library provides a default implementation of these translation function if BOOST_CHRONO_SPECIFIC_TRANSLATE is not defined.
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.
6699 Next follow the behavior of the default implementation.
6701 [section:duration_prefix_translate Non Member Function `duration_prefix_translate()`]
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,
6709 __returns If `r` is `-1` or `1` returns `singular`, else `plural`.
6713 [section:duration_symbol_translate Non Member Function `duration_symbol_translate()`]
6715 template <class CharT>
6716 std::basic_string<CharT> duration_symbol_translate(
6717 std::basic_string<CharT> const &symbol);
6722 [section:epoch_translate Non Member Function `epoch_translate()`]
6724 template <class CharT>
6725 std::basic_string<CharT> epoch_translate(
6726 std::basic_string<CharT> const &epoch);
6732 [endsect] [/section:translate_hpp Header `<boost/chrono/io/translate.hpp>`]
6735 [endsect] [/section:io Chrono I/O]
6738 [section:round Chrono Rounding Utilities]
6739 [/==================================================================]
6740 [section:floor_hpp Header `<boost/chrono/floor.hpp>`]
6741 [/==================================================================]
6743 namespace boost { namespace chrono {
6744 template <class To, class Rep, class Period>
6745 To floor(const duration<Rep, Period>& d);
6748 This function round down the given parameter.
6751 [/==================================================================]
6752 [section:round_hpp Header `<boost/chrono/round.hpp>`]
6753 [/==================================================================]
6755 namespace boost { namespace chrono {
6756 template <class To, class Rep, class Period>
6757 To round(const duration<Rep, Period>& d);
6760 This function round to nearest, to even on tie the given parameter.
6764 [/==================================================================]
6765 [section:ceil_hpp Header `<boost/chrono/ceil.hpp>`]
6766 [/==================================================================]
6768 namespace boost { namespace chrono {
6769 template <class To, class Rep, class Period>
6770 To ceil(const duration<Rep, Period>& d);
6773 This function round up the given parameter.
6779 [section:other_clocks Other Clocks]
6781 [/==================================================================]
6782 [section:process_cpu_clocks_hpp Header `<boost/chrono/process_cpu_clocks.hpp>`]
6783 [/==================================================================]
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.
6787 Process clocks don't include the time spent by the child process.
6789 #define BOOST_CHRONO_HAS_PROCESS_CLOCKS
6791 namespace boost { namespace chrono {
6793 class process_real_cpu_clock;
6794 class process_user_cpu_clock;
6795 class process_system_cpu_clock;
6796 class process_cpu_clock;
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);
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);
6810 template <class Rep>
6811 struct duration_values<process_times<Rep> >;
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>;
6821 template <class Rep>
6822 class numeric_limits<boost::chrono::process_times<Rep> >;
6825 [section: BOOST_CHRONO_HAS_PROCESS_CLOCKS Macro `BOOST_CHRONO_HAS_PROCESS_CLOCKS `]
6827 This macro is defined if the platform supports process clocks.
6831 [section:process_real_cpu_clock Class `process_real_cpu_clock`]
6833 __process_real_cpu_clock satisfy the __clock_req.
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()`.
6837 class process_real_cpu_clock {
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;
6845 static time_point now( ) noexcept;
6846 static time_point now( system::error_code & ec );
6851 [section:process_user_cpu_clock Class `process_user_cpu_clock`]
6853 __process_user_cpu_clock satisfy the __clock_req.
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()`.
6857 class process_user_cpu_clock {
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;
6865 static time_point now( ) noexcept;
6866 static time_point now( system::error_code & ec );
6872 [section:process_system_cpu_clock Class `process_system_cpu_clock`]
6874 __process_system_cpu_clock satisfy the __clock_req.
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()`.
6878 class process_system_cpu_clock {
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;
6886 static time_point now( ) noexcept;
6887 static time_point now( system::error_code & ec );
6893 [section:process_cpu_clock Class `process_cpu_clock`]
6895 `process_cpu_clock` can be considered as a `tuple<process_real_cpu_clock, process_user_cpu_clock, process_system_cpu_clock>`.
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.
6899 The process relative real, user and system current time can be obtained at once by calling `process_clocks::now()`.
6901 class process_cpu_clock
6904 typedef process_times<nanoseconds::rep> times ;
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;
6912 static time_point now( ) noexcept;
6913 static time_point now( system::error_code & ec );
6918 [section:times Template Class `process_times`]
6920 This class is the representation of the `process_cpu_clock::duration` class. As such it needs to implements the arithmetic operators.
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> > > >
6927 Rep real; // real (i.e wall clock) time
6928 Rep user; // user cpu time
6929 Rep system; // system cpu time
6933 process_real_cpu_clock::rep r,
6934 process_user_cpu_clock::rep u,
6935 process_system_cpu_clock::rep s);
6937 template <typename Rep2>
6938 explicit process_times(
6940 template <typename Rep2>
6941 explicit process_times(
6942 process_times<Rep2> const& rhs);
6943 operator rep() const;
6945 bool operator==(process_times const& rhs);
6946 template <typename Rep2>
6947 bool operator==(process_times<Rep2> const& rhs);
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;
6958 [section:times_io `process_times` Input/Output]
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);
6965 __effects Output each part separated by ';' and surrounded by '{', '}'.
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);
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.
6981 [section:times_duration_values `duration_values` Specialization for `process_times<>`]
6983 template <class Rep>
6984 struct __duration_values<process_times<Rep> >
6986 static process_times<Rep> zero();
6987 static process_times<Rep> max();
6988 static process_times<Rep> min();
6991 The `times` specific functions `zero()`, `max()` and `min()` uses the relative functions on the representation of each component.
6995 [section:clock_string_process_real_cpu_clock `clock_string<process_real_cpu_clock>` Specialization]
6997 template <class CharT>
6998 struct clock_string<process_real_cpu_clock, CharT>
7000 static std::basic_string<CharT> name();
7001 static std::basic_string<CharT> since();
7004 `clock_string<>::name()` returns "process_real_cpu_clock".
7006 `clock_string<>::since()` returns " since process start-up"
7010 [section:clock_string_process_user_cpu_clock `clock_string<process_user_cpu_clock>` Specialization]
7012 template <class CharT>
7013 struct clock_string<process_user_cpu_clock, CharT>
7015 static std::basic_string<CharT> name();
7016 static std::basic_string<CharT> since();
7019 `clock_string<>::name()` returns "process_user_cpu_clock".
7021 `clock_string<>::since()` returns " since process start-up"
7026 [section:clock_string_process_system_cpu_clock `clock_string<process_system_cpu_clock>` Specialization]
7028 template <class CharT>
7029 struct clock_string<process_system_cpu_clock, CharT>
7031 static std::basic_string<CharT> name();
7032 static std::basic_string<CharT> since();
7035 `clock_string<>::name()` returns "process_system_cpu_clock".
7037 `clock_string<>::since()` returns " since process start-up"
7042 [section:clock_string_process_cpu_clock `clock_string<process_cpu_clock>` Specialization]
7044 template <class CharT>
7045 struct clock_string<process_cpu_clock, CharT>
7047 static std::basic_string<CharT> name();
7048 static std::basic_string<CharT> since();
7051 `clock_string<>::name()` returns "process_cpu_clock".
7053 `clock_string<>::since()` returns " since process start-up"
7057 [section:times_numeric_limits `numeric_limits` Specialization for `process_times<>`]
7061 class numeric_limits<boost::chrono::process_times<Rep>> {
7062 typedef boost::chrono::process_times<Rep> Res;
7065 static const bool is_specialized = true;
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;
7078 The `process_times<Rep>` specialization functions `min()`, `max()` and `lowest()` uses the relative functions on the representation of each component.
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.
7092 [/==================================================================]
7093 [section:thread_clock_hpp Header `<boost/chrono/thread_clock.hpp>`]
7094 [/==================================================================]
7096 Knowing the time a thread takes to execute is useful in both test and production environments.
7098 #define BOOST_CHRONO_HAS_THREAD_CLOCK
7099 #define BOOST_CHRONO_THREAD_CLOCK_IS_STEADY
7100 namespace boost { namespace chrono {
7103 template <class CharT>
7104 struct clock_string<thread_clock, CharT>;
7108 [section:BOOST_CHRONO_HAS_THREAD_CLOCK Macro `BOOST_CHRONO_HAS_THREAD_CLOCK`]
7110 This macro is defined if the platform supports thread clocks.
7114 [section:BOOST_CHRONO_THREAD_CLOCK_IS_STEADY Macro `BOOST_CHRONO_THREAD_CLOCK_IS_STEADY`]
7116 This macro is defined if the platform has a thread clock. Its value is true if it is steady and false otherwise.
7120 [section:thread_clock Class `thread_clock`]
7122 __thread_clock satisfy the __clock_req.
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()`.
7126 class thread_clock {
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;
7134 static time_point now( ) noexcept;
7135 static time_point now( system::error_code & ec );
7142 [section:clock_string_thread_clock `clock_string<thread_clock>` Specialization]
7144 #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
7145 template <class CharT>
7146 struct clock_string<thread_clock, CharT>
7148 static std::basic_string<CharT> name();
7149 static std::basic_string<CharT> since();
7153 `clock_string<>::name()` returns "thread_clock".
7155 `clock_string<>::since()` returns " since thread start-up"
7164 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7166 [/include stopwatches/reference.qbk]
7167 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7170 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7171 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7173 [section:deprecated Deprecated Headers]
7175 See Boost.Stopwatches for similar functionality.
7177 [/==================================================]
7178 [section:timer_hpp Deprecated Header `<boost/chrono/timer.hpp>`]
7179 [/==================================================]
7181 This header has been deprecated, use instead <boost/chrono/stopwatch.hpp>.
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;
7189 typedef <see above> high_resolution_timer;
7193 typedef <see above> process_real_cpu_timer;
7194 typedef <see above> process_user_cpu_timer;
7195 typedef <see above> process_system_cpu_timer;
7197 [section:timer Template Class `timer<>`]
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.
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.
7205 template <class __Clock> class timer {
7207 typedef __Clock clock;
7208 typedef typename __Clock::duration duration;
7209 typedef typename __Clock::time_point time_point;
7211 explicit timer( system::error_code & ec = system::throws );
7215 void start( system::error_code & ec = system::throws );
7216 duration elapsed( system::error_code & ec = system::throws );
7222 [section:timer_typedefs `timer` useful typedefs]
7224 typedef boost::chrono::timer< boost::chrono::system_clock >
7226 #ifdef __BOOST_CHRONO_HAS_CLOCK_STEADY
7227 typedef boost::chrono::timer< boost::chrono::steady_clock >
7230 typedef boost::chrono::timer< boost::chrono::high_resolution_clock >
7231 high_resolution_timer;
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;
7242 [/==================================================================]
7243 [section:process_times_hpp Deprecated Header `<boost/chrono/process_times.hpp>`]
7244 [/==================================================================]
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.
7248 namespace boost { namespace chrono {
7250 class process_clock;
7251 typedef <see below> process_times;
7252 class process_timer;
7257 [section:process_clock Class `process_clock`]
7259 `process_clock` doesn't satisfy the __Clock Requirements as the function now do not follows the __Clock prototype.
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.
7263 The process relative real, user and system current time can be obtained at once by calling `process_clock::now()`.
7266 class process_clock {
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;
7274 struct process_times;
7275 static void now( process_times & times,
7276 system::error_code & ec = system::throws );
7279 [section:process_times Class `process_times`]
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
7290 [section:process_times Typedef `process_times`]
7292 typedef process_clock::process_times process_times;
7294 This is a synonym of process_clock::process_times included for backward compatibility.
7298 [section:process_timer Class `process_timer`]
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.
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.
7304 class process_timer {
7306 typedef process_clock clock;
7307 typedef process_clock::duration duration;
7308 typedef process_clock::time_point time_point;
7310 explicit process_timer( system::error_code & ec = system::throws );
7313 void start( system::error_code & ec = system::throws );
7314 void elapsed( process_times & times, system::error_code & ec = system::throws );
7318 [section:run_timer Class `run_timer`]
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:
7322 * format : The output format
7323 * places(precision): the number of decimal places used.
7325 The default places is given by default_places and is 3.
7327 The default format is "nreal %rs, cpu %cs (%p%), user %us, system %ss\\n", where
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
7335 All the units are given using the suffix "s" following the System International d'Unites Std.
7337 class run_timer : public process_timer {
7339 explicit run_timer( system::error_code & ec = system::throws );
7340 explicit run_timer( std::ostream & os,
7341 system::error_code & ec = system::throws );
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 );
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 );
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 );
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 );
7365 void start( system::error_code & ec = system::throws );
7367 void report( system::error_code & ec = system::throws );
7369 void test_report( duration real_, duration user_, duration system_ );
7370 bool reported() const;
7371 static int default_places();
7381 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7382 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7387 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7388 [/=================]
7389 [section Appendices]
7390 [/=================]
7392 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7393 [/==================================]
7394 [section:history Appendix: History]
7395 [/==================================]
7397 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7398 [section [*Version 2.0.7, August 18, 2016 - 1.62] ]
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
7406 [endsect] [/section [*Version 2.0.7] ]
7407 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7408 [section [*Version 2.0.6, December 18, 2015 - 1.60] ]
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
7416 [endsect] [/section [*Version 2.0.6] ]
7417 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7418 [section [*Version 2.0.5, February 18, 2015 - 1.58] ]
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> >
7431 [endsect] [/section [*Version 2.0.5] ]
7432 [section [*Version 2.0.4, July 12, 2014 - 1.56] ]
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
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
7450 [endsect] [/section [*Version 2.0.4] ]
7452 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7453 [section [*Version 2.0.3, September 29, 2013 - 1.55] ]
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.
7463 [endsect] [/section [*Version 2.0.3] ]
7465 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7466 [section [*Version 2.0.2, June 15, 2013 - 1.54] ]
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.
7480 [endsect] [/section [*Version 2.0.2] ]
7482 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7483 [section [*Version 2.0.1, January 18, 2013 - 1.53] ]
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.
7491 When BOOST_CHRONO_VERSION==2 the preceding deprecated functions are not available.
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)
7500 [endsect] [/section [*Version 2.0.1] ]
7502 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7503 [section [*Version 2.0.0, October 23, 2012 - 1.52] ]
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.
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.
7518 When BOOST_CHRONO_VERSION==2 the preceding deprecated functions are not available.
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
7529 * [@http://svn.boost.org/trac/boost/ticket/6871 #6871] chrono_io.hpp: operator<<(ostream& os, ...) modifies the state of os.
7531 * The new io interface provided in version 2 solves this issue. You should move to the new version.
7533 [*Known bugs not fixed yet:]
7535 * [@http://svn.boost.org/trac/boost/ticket/7525 #7525] Wrong clock_string<system_clock>::since() on Windows
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:
7541 - [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile
7543 - [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile
7545 In this case the io operators behave like any time_point as if the specialization was removed.
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`.
7551 [endsect] [/section [*Version 2.0.0] ]
7553 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7554 [section [*Version 1.2.3, August 1, 2012 - 1.51] ]
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.
7567 [endsect] [/section [*Version 1.2.3] ]
7569 [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
7570 [section [*Version 1.2.2, April 1, 2012 - 1.50] ]
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.
7578 [endsect] [/section [*Version 1.2.2] ]
7580 [section [*Version 1.2.1, February 1, 2012 - 1.49] ]
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.
7590 [endsect] [/section [*Version 1.2.1] ]
7593 [section [*Version 1.2.0, October 17, 2011] ]
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.
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.
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,
7626 [endsect] [/section [*Version 1.2.0] ]
7629 [section [*Version 1.1.0, Mars 17, 2011] ]
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.
7638 * [@http://svn.boost.org/trac/boost/ticket/5322 #5322] Explicit default constructed chrono::durations are uninitialized
7641 [endsect] [/section [*Version 1.1.0] ]
7643 [section [*Version 1.0.0, January 6, 2011] ]
7645 * Moved chrono to trunk taking in account the review remarks.
7646 * Documentation revision.
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.
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.
7663 * Fix some warnings.
7664 * Fix original errors on Mac
7665 * Don't fix the link with boost_system to static.
7669 * Added test on process and thread clocks.
7670 * Moved to lightweight_test.hpp.
7671 * Able to test multiple configurations.
7675 * Removed some not useful parts as the test and the tickets.
7677 [endsect] [/section [*Version 1.0.0] ]
7680 [section [*Version 0.6.0, September 22, 2010] ]
7684 * Added experimental chrono_io.
7688 * Fix duration values min implementation.
7693 * Adapted test from libc++/chrono
7697 [section [*Version 0.5.0, September 10, 2010] ]
7701 * Stopwatches, Ratio and CommonType have been moved to separated libraries: Boost.Stopwatches, Boost.Ratio and Boost.TypeTraits.
7705 [section [*Version 0.4.7, September 1, 2010] ]
7709 * Added __lightweight_stopwatch__.
7713 [section [*Version 0.4.6, August 28, 2010] ]
7717 * Implementation of __common_type without using Boost.TypeOf.
7718 * Added __stopwatch_accumulator_time_formatter__ class.
7722 * Type reporter removed from Stopwatches as well as the get_reporter metafunction.
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
7732 [section [*Version 0.4.5, July 6, 2010] ['Documentation update]]
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.
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.
7753 [section [*Version 0.4.4, February 22, 2010] [' Warning fixes]]
7757 * `scoped_suspend` warning removal
7758 * `error_code` management completed
7762 [section [*Version 0.4.3, June 18, 2010] ['Missing file fixe]]
7766 * boost/thread/detail/cv_status.hpp file was not committed.
7770 [section [*Version 0.4.2, June 18, 2010] ['Packaging fixe]]
7772 * Boost.Conversion library, used by Boost.Thread porting to Boost.Chrono was not packaged.
7776 [section [*Version 0.4.1, June 17, 2010] ['Added thread clock implementation on Windows]]
7780 * Added __thread_clock implementation on Windows.
7781 * Added *Boost.Thread* using *Boost.Chrono*.
7785 [section [*Version 0.4, February 28, 2010] ['New thread clock and Suspendible clock ]]
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`.
7797 Added performances measures.
7801 * Bug on timeval_demo.
7803 time_point t(duration(xtime(0))); // this was taken as a function declaration
7804 gettimeofday((timeval*)&t, 0);
7809 gettimeofday(&tv, 0);
7810 xtime xt( tv.tv_sec, tv.tv_usec);
7811 return time_point(duration(xt));
7813 * Bug on run_timer_test (add a global variable to avoid optimization that removes completely the code to be measured
7817 [section [*Version 0.3.2, January 25, 2010] ['New frequency, lifetime and percentage stopwatch_accumulator features]]
7820 * Added overloading for `operator/(Integer/Duration)`
7821 * Added frequency, lifetime and percentage to the default `stopwatch_accumulator_formatter`.
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.
7830 [section [*Version 0.3.1, January 20, 2010] ['New support for wide characters]]
7833 * Support for wide characters on formatters and stopclocks
7834 * added `chrono.hpp` and `stopwatches.hpp` at the boost level
7839 [section [*Version 0.3.0, January 17, 2010] ['New stopwatch/stopclock feature + Bug fixes]]
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
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<>`
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`.
7870 [section [*Version 0.2.1, December 13, 2009] ['Bug fixes]]
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:
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> >'
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.
7895 More updated documentation.
7899 [section [*Version 0.2.0, December 8, 2009] ['+ Features + Bug fixes + Updated documentation]]
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/`.
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.
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]] .
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
7933 [section [*Version 0.1.0, April 29, 2009] ['Beman's boostified version Chrono]]
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
7945 * `high_resolution_clock`
7947 * Class template timer, with typedefs:
7950 * `high_resolution_timer`
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.
7962 [/======================================]
7963 [section:rationale Appendix: Rationale]
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.
7967 [heading Why duration needs operator%]
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:
7973 typedef boost::chrono::hours hours;
7974 typedef boost::chrono::minutes minutes;
7975 typedef boost::chrono::seconds seconds;
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)))
7992 [/======================================================]
7993 [section:implementation Appendix: Implementation Notes]
7995 [heading Which APIs have been chosen to implement each clock on each platform?]
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)] ]
8012 [/======================================================]
8013 [section:faq Appendix: FAQ]
8015 [heading Why does process_cpu_clock sometimes give more cpu seconds than real seconds?]
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.
8020 [heading Are integer overflows in the duration arithmetic detected and reported?]
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.
8024 [heading Which clocks should be used to benchmarking?]
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.
8028 [heading Which clocks should be used for watching?]
8030 For trace purposes, it is probably best to use a system-wide clock.
8032 [endsect] [/section:faq Appendix: FAQ]
8034 [/====================================================]
8035 [section:acknowledgements Appendix: Acknowledgements]
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.
8039 time2_demo contained this comment:
8041 Much thanks to Andrei Alexandrescu, Walter Brown, Peter Dimov, Jeff Garland, Terry Golubiewski, Daniel Krugler, Anthony Williams.
8043 The file <boost/chrono_io.hpp> has been adapted from the experimental header `<chrono_io>` from Howard Hinnant. Thanks for all Howard.
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.
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.
8049 Thanks to Ronald Bock, Andrew Chinoff, Paul A. Bristow and John Bytheway for his help polishing the documentation.
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.
8053 Thanks to Ronald Bock for reporting Valgind issues and for the many suggestions he made concerning the documentation.
8057 [/=====================================]
8058 [section:todo Appendix: Future plans]
8059 [/=====================================]
8061 [heading For later releases]
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].