1// manipulate_clock_object.cpp ----------------------------------------------------------//
2
3// Copyright 2008 Howard Hinnant
4// Copyright 2008 Beman Dawes
5// Copyright 2009 Vicente J. Botet Escriba
6
7// Distributed under the Boost Software License, Version 1.0.
8// See http://www.boost.org/LICENSE_1_0.txt
9
10/*
11This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which
12was derived by Beman Dawes from Howard Hinnant's time2_demo prototype.
13Many thanks to Howard for making his code available under the Boost license.
14The original code was modified to conform to Boost conventions and to section
1520.9 Time utilities [time] of the C++ committee's working paper N2798.
16See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf.
17
18time2_demo contained this comment:
19
20 Much thanks to Andrei Alexandrescu,
21 Walter Brown,
22 Peter Dimov,
23 Jeff Garland,
24 Terry Golubiewski,
25 Daniel Krugler,
26 Anthony Williams.
27*/
28
29#include <boost/chrono/chrono.hpp>
30#include <boost/type_traits.hpp>
31
32#include <iostream>
33
34using namespace boost::chrono;
35
36#if defined _MSC_VER
37#pragma warning(push)
38#pragma warning(disable:4100)
39#endif
40void manipulate_clock_object(system_clock clock)
41#if defined _MSC_VER
42#pragma warning(pop)
43#endif
44{
45 system_clock::duration delay = milliseconds(5);
46 system_clock::time_point start = clock.now();
47
48 while ((clock.now() - start) <= delay) {}
49
50 system_clock::time_point stop = clock.now();
51 system_clock::duration elapsed = stop - start;
52 std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n";
53}
54
55
56int main()
57{
58 manipulate_clock_object(clock: system_clock());
59 return 0;
60}
61
62

source code of boost/libs/chrono/example/manipulate_clock_object.cpp