From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- src/boost/libs/chrono/CMakeLists.txt | 48 + src/boost/libs/chrono/README.md | 8 + src/boost/libs/chrono/build/Jamfile.v2 | 113 ++ src/boost/libs/chrono/example/await_keystroke.cpp | 73 + src/boost/libs/chrono/example/chrono_unit_test.cpp | 32 + src/boost/libs/chrono/example/clock_name.cpp | 20 + src/boost/libs/chrono/example/clock_name.hpp | 68 + src/boost/libs/chrono/example/cycle_count.cpp | 140 ++ src/boost/libs/chrono/example/explore_limits.cpp | 60 + src/boost/libs/chrono/example/french.cpp | 130 ++ .../i_dont_like_the_default_duration_behavior.cpp | 97 ++ src/boost/libs/chrono/example/io_ex1.cpp | 87 + src/boost/libs/chrono/example/io_ex2.cpp | 36 + src/boost/libs/chrono/example/io_ex3.cpp | 48 + src/boost/libs/chrono/example/io_ex4.cpp | 32 + src/boost/libs/chrono/example/io_ex5.cpp | 90 ++ .../chrono/example/manipulate_clock_object.cpp | 61 + src/boost/libs/chrono/example/min_time_point.cpp | 79 + src/boost/libs/chrono/example/miscellaneous.cpp | 156 ++ src/boost/libs/chrono/example/rounding.cpp | 44 + .../libs/chrono/example/run_timer_example.cpp | 22 + .../libs/chrono/example/run_timer_example2.cpp | 24 + .../libs/chrono/example/runtime_resolution.cpp | 244 +++ src/boost/libs/chrono/example/saturating.cpp | 505 ++++++ .../example/simulated_thread_interface_demo.cpp | 198 +++ src/boost/libs/chrono/example/test_clock.cpp | 182 +++ src/boost/libs/chrono/example/test_clock2.cpp | 210 +++ src/boost/libs/chrono/example/test_duration.cpp | 203 +++ src/boost/libs/chrono/example/test_minmax.cpp | 17 + .../libs/chrono/example/test_special_values.cpp | 51 + .../libs/chrono/example/test_thread_clock.cpp | 42 + src/boost/libs/chrono/example/time2_demo.cpp | 1655 ++++++++++++++++++++ .../libs/chrono/example/time2_demo_output.txt | 191 +++ src/boost/libs/chrono/example/timer.hpp | 62 + src/boost/libs/chrono/example/timeval_demo.cpp | 237 +++ src/boost/libs/chrono/example/xtime.cpp | 109 ++ src/boost/libs/chrono/index.html | 15 + src/boost/libs/chrono/meta/libraries.json | 20 + src/boost/libs/chrono/perf/Jamfile.v2 | 147 ++ src/boost/libs/chrono/perf/store_now_in_vector.cpp | 153 ++ src/boost/libs/chrono/src/chrono.cpp | 15 + src/boost/libs/chrono/src/process_cpu_clocks.cpp | 18 + src/boost/libs/chrono/src/thread_clock.cpp | 19 + src/boost/libs/chrono/sublibs | 0 src/boost/libs/chrono/test/Jamfile.v2 | 465 ++++++ src/boost/libs/chrono/test/another_obj.cpp | 19 + src/boost/libs/chrono/test/clock.h | 30 + src/boost/libs/chrono/test/clock/clock_pass.cpp | 201 +++ src/boost/libs/chrono/test/clock/errored_clock.hpp | 62 + .../libs/chrono/test/duration/arithmetic_pass.cpp | 350 +++++ .../libs/chrono/test/duration/comparisons_pass.cpp | 222 +++ .../duration/cons/convert_float_to_int_fail.cpp | 22 + .../test/duration/cons/convert_inexact_fail.cpp | 22 + .../duration/cons/implicit_constructot_fail.cpp | 23 + .../cons/non_implicit_convertible_rep_fail.cpp | 23 + .../treat_as_floating_point_Rep2_true_fail.cpp | 21 + .../libs/chrono/test/duration/constructor_pass.cpp | 134 ++ .../chrono/test/duration/default_ratio_pass.cpp | 29 + .../test/duration/duration_cast_int_fail.cpp | 21 + .../chrono/test/duration/duration_cast_pass.cpp | 59 + .../test/duration/duration_duration_fail.cpp | 24 + .../chrono/test/duration/duration_values_pass.cpp | 76 + .../test/duration/nonmember/divide_rep2_fail.cpp | 22 + .../test/duration/nonmember/modulus_rep2_fail.cpp | 22 + .../duration/nonmember/times_rep2_lhs_fail.cpp | 22 + .../duration/nonmember/times_rep2_rhs_fail.cpp | 22 + .../chrono/test/duration/positive_num_fail.cpp | 23 + .../libs/chrono/test/duration/ratio_alias_pass.cpp | 29 + src/boost/libs/chrono/test/duration/ratio_fail.cpp | 23 + .../libs/chrono/test/duration/rounding_pass.cpp | 105 ++ .../libs/chrono/test/duration/typedefs_pass.cpp | 42 + src/boost/libs/chrono/test/duration/types_pass.cpp | 28 + src/boost/libs/chrono/test/intmax_c.cpp | 19 + src/boost/libs/chrono/test/io/duration_input.cpp | 124 ++ src/boost/libs/chrono/test/io/duration_output.cpp | 114 ++ src/boost/libs/chrono/test/io/time_point_input.cpp | 238 +++ .../libs/chrono/test/io/time_point_output.cpp | 317 ++++ src/boost/libs/chrono/test/one_obj.cpp | 23 + src/boost/libs/chrono/test/rep.h | 67 + src/boost/libs/chrono/test/run_timer_test.cpp | 226 +++ src/boost/libs/chrono/test/test_10631.cpp | 61 + src/boost/libs/chrono/test/test_10778.cpp | 19 + src/boost/libs/chrono/test/test_11006.cpp | 21 + src/boost/libs/chrono/test/test_11012.cpp | 27 + src/boost/libs/chrono/test/test_12176.cpp | 11 + src/boost/libs/chrono/test/test_7868.cpp | 81 + src/boost/libs/chrono/test/test_9337.cpp | 27 + .../chrono/test/time_point/arithmetic_ext_pass.cpp | 70 + .../chrono/test/time_point/arithmetic_pass.cpp | 151 ++ .../test/time_point/comparisons/equal_fail.cpp | 32 + .../test/time_point/comparisons/less_fail.cpp | 32 + .../chrono/test/time_point/comparisons_pass.cpp | 146 ++ .../chrono/test/time_point/cons/implicit_fail.cpp | 23 + .../non_implicit_convertible_duration_fail.cpp | 27 + .../chrono/test/time_point/constructor_pass.cpp | 80 + .../test/time_point/default_duration.pass.cpp | 24 + .../test/time_point/default_duration_pass.cpp | 24 + .../libs/chrono/test/time_point/duration.fail.cpp | 22 + .../libs/chrono/test/time_point/min_max_pass.cpp | 34 + .../chrono/test/time_point/not_duration_fail.cpp | 22 + .../test/time_point/time_point_cast_int_fail.cpp | 24 + .../test/time_point/time_point_cast_pass.cpp | 67 + .../test/traits/common_type_duration_pass.cpp | 43 + .../test/traits/common_type_time_point_pass.cpp | 47 + .../chrono/test/traits/duration_values_pass.cpp | 41 + .../test/traits/treat_as_floating_point_pass.cpp | 41 + src/boost/libs/chrono/test/win32_test.cpp | 149 ++ 107 files changed, 10376 insertions(+) create mode 100644 src/boost/libs/chrono/CMakeLists.txt create mode 100644 src/boost/libs/chrono/README.md create mode 100644 src/boost/libs/chrono/build/Jamfile.v2 create mode 100644 src/boost/libs/chrono/example/await_keystroke.cpp create mode 100644 src/boost/libs/chrono/example/chrono_unit_test.cpp create mode 100644 src/boost/libs/chrono/example/clock_name.cpp create mode 100644 src/boost/libs/chrono/example/clock_name.hpp create mode 100644 src/boost/libs/chrono/example/cycle_count.cpp create mode 100644 src/boost/libs/chrono/example/explore_limits.cpp create mode 100644 src/boost/libs/chrono/example/french.cpp create mode 100644 src/boost/libs/chrono/example/i_dont_like_the_default_duration_behavior.cpp create mode 100644 src/boost/libs/chrono/example/io_ex1.cpp create mode 100644 src/boost/libs/chrono/example/io_ex2.cpp create mode 100644 src/boost/libs/chrono/example/io_ex3.cpp create mode 100644 src/boost/libs/chrono/example/io_ex4.cpp create mode 100644 src/boost/libs/chrono/example/io_ex5.cpp create mode 100644 src/boost/libs/chrono/example/manipulate_clock_object.cpp create mode 100644 src/boost/libs/chrono/example/min_time_point.cpp create mode 100644 src/boost/libs/chrono/example/miscellaneous.cpp create mode 100644 src/boost/libs/chrono/example/rounding.cpp create mode 100644 src/boost/libs/chrono/example/run_timer_example.cpp create mode 100644 src/boost/libs/chrono/example/run_timer_example2.cpp create mode 100644 src/boost/libs/chrono/example/runtime_resolution.cpp create mode 100644 src/boost/libs/chrono/example/saturating.cpp create mode 100644 src/boost/libs/chrono/example/simulated_thread_interface_demo.cpp create mode 100644 src/boost/libs/chrono/example/test_clock.cpp create mode 100644 src/boost/libs/chrono/example/test_clock2.cpp create mode 100644 src/boost/libs/chrono/example/test_duration.cpp create mode 100644 src/boost/libs/chrono/example/test_minmax.cpp create mode 100644 src/boost/libs/chrono/example/test_special_values.cpp create mode 100644 src/boost/libs/chrono/example/test_thread_clock.cpp create mode 100644 src/boost/libs/chrono/example/time2_demo.cpp create mode 100644 src/boost/libs/chrono/example/time2_demo_output.txt create mode 100644 src/boost/libs/chrono/example/timer.hpp create mode 100644 src/boost/libs/chrono/example/timeval_demo.cpp create mode 100644 src/boost/libs/chrono/example/xtime.cpp create mode 100644 src/boost/libs/chrono/index.html create mode 100644 src/boost/libs/chrono/meta/libraries.json create mode 100644 src/boost/libs/chrono/perf/Jamfile.v2 create mode 100644 src/boost/libs/chrono/perf/store_now_in_vector.cpp create mode 100644 src/boost/libs/chrono/src/chrono.cpp create mode 100644 src/boost/libs/chrono/src/process_cpu_clocks.cpp create mode 100644 src/boost/libs/chrono/src/thread_clock.cpp create mode 100644 src/boost/libs/chrono/sublibs create mode 100644 src/boost/libs/chrono/test/Jamfile.v2 create mode 100644 src/boost/libs/chrono/test/another_obj.cpp create mode 100644 src/boost/libs/chrono/test/clock.h create mode 100644 src/boost/libs/chrono/test/clock/clock_pass.cpp create mode 100644 src/boost/libs/chrono/test/clock/errored_clock.hpp create mode 100644 src/boost/libs/chrono/test/duration/arithmetic_pass.cpp create mode 100644 src/boost/libs/chrono/test/duration/comparisons_pass.cpp create mode 100644 src/boost/libs/chrono/test/duration/cons/convert_float_to_int_fail.cpp create mode 100644 src/boost/libs/chrono/test/duration/cons/convert_inexact_fail.cpp create mode 100644 src/boost/libs/chrono/test/duration/cons/implicit_constructot_fail.cpp create mode 100644 src/boost/libs/chrono/test/duration/cons/non_implicit_convertible_rep_fail.cpp create mode 100644 src/boost/libs/chrono/test/duration/cons/treat_as_floating_point_Rep2_true_fail.cpp create mode 100644 src/boost/libs/chrono/test/duration/constructor_pass.cpp create mode 100644 src/boost/libs/chrono/test/duration/default_ratio_pass.cpp create mode 100644 src/boost/libs/chrono/test/duration/duration_cast_int_fail.cpp create mode 100644 src/boost/libs/chrono/test/duration/duration_cast_pass.cpp create mode 100644 src/boost/libs/chrono/test/duration/duration_duration_fail.cpp create mode 100644 src/boost/libs/chrono/test/duration/duration_values_pass.cpp create mode 100644 src/boost/libs/chrono/test/duration/nonmember/divide_rep2_fail.cpp create mode 100644 src/boost/libs/chrono/test/duration/nonmember/modulus_rep2_fail.cpp create mode 100644 src/boost/libs/chrono/test/duration/nonmember/times_rep2_lhs_fail.cpp create mode 100644 src/boost/libs/chrono/test/duration/nonmember/times_rep2_rhs_fail.cpp create mode 100644 src/boost/libs/chrono/test/duration/positive_num_fail.cpp create mode 100644 src/boost/libs/chrono/test/duration/ratio_alias_pass.cpp create mode 100644 src/boost/libs/chrono/test/duration/ratio_fail.cpp create mode 100644 src/boost/libs/chrono/test/duration/rounding_pass.cpp create mode 100644 src/boost/libs/chrono/test/duration/typedefs_pass.cpp create mode 100644 src/boost/libs/chrono/test/duration/types_pass.cpp create mode 100644 src/boost/libs/chrono/test/intmax_c.cpp create mode 100644 src/boost/libs/chrono/test/io/duration_input.cpp create mode 100644 src/boost/libs/chrono/test/io/duration_output.cpp create mode 100644 src/boost/libs/chrono/test/io/time_point_input.cpp create mode 100644 src/boost/libs/chrono/test/io/time_point_output.cpp create mode 100644 src/boost/libs/chrono/test/one_obj.cpp create mode 100644 src/boost/libs/chrono/test/rep.h create mode 100644 src/boost/libs/chrono/test/run_timer_test.cpp create mode 100644 src/boost/libs/chrono/test/test_10631.cpp create mode 100644 src/boost/libs/chrono/test/test_10778.cpp create mode 100644 src/boost/libs/chrono/test/test_11006.cpp create mode 100644 src/boost/libs/chrono/test/test_11012.cpp create mode 100644 src/boost/libs/chrono/test/test_12176.cpp create mode 100644 src/boost/libs/chrono/test/test_7868.cpp create mode 100644 src/boost/libs/chrono/test/test_9337.cpp create mode 100644 src/boost/libs/chrono/test/time_point/arithmetic_ext_pass.cpp create mode 100644 src/boost/libs/chrono/test/time_point/arithmetic_pass.cpp create mode 100644 src/boost/libs/chrono/test/time_point/comparisons/equal_fail.cpp create mode 100644 src/boost/libs/chrono/test/time_point/comparisons/less_fail.cpp create mode 100644 src/boost/libs/chrono/test/time_point/comparisons_pass.cpp create mode 100644 src/boost/libs/chrono/test/time_point/cons/implicit_fail.cpp create mode 100644 src/boost/libs/chrono/test/time_point/cons/non_implicit_convertible_duration_fail.cpp create mode 100644 src/boost/libs/chrono/test/time_point/constructor_pass.cpp create mode 100644 src/boost/libs/chrono/test/time_point/default_duration.pass.cpp create mode 100644 src/boost/libs/chrono/test/time_point/default_duration_pass.cpp create mode 100644 src/boost/libs/chrono/test/time_point/duration.fail.cpp create mode 100644 src/boost/libs/chrono/test/time_point/min_max_pass.cpp create mode 100644 src/boost/libs/chrono/test/time_point/not_duration_fail.cpp create mode 100644 src/boost/libs/chrono/test/time_point/time_point_cast_int_fail.cpp create mode 100644 src/boost/libs/chrono/test/time_point/time_point_cast_pass.cpp create mode 100644 src/boost/libs/chrono/test/traits/common_type_duration_pass.cpp create mode 100644 src/boost/libs/chrono/test/traits/common_type_time_point_pass.cpp create mode 100644 src/boost/libs/chrono/test/traits/duration_values_pass.cpp create mode 100644 src/boost/libs/chrono/test/traits/treat_as_floating_point_pass.cpp create mode 100644 src/boost/libs/chrono/test/win32_test.cpp (limited to 'src/boost/libs/chrono') diff --git a/src/boost/libs/chrono/CMakeLists.txt b/src/boost/libs/chrono/CMakeLists.txt new file mode 100644 index 000000000..038b475c1 --- /dev/null +++ b/src/boost/libs/chrono/CMakeLists.txt @@ -0,0 +1,48 @@ +# Copyright 2019 Mike Dev +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt +# +# NOTE: CMake support for Boost.Chrono is currently experimental at best +# and the interface is likely to change in the future + +cmake_minimum_required( VERSION 3.5 ) +project( BoostChrono LANGUAGES CXX) + +add_library( boost_chrono + src/chrono.cpp + src/process_cpu_clocks.cpp + src/thread_clock.cpp +) +add_library( Boost::chrono ALIAS boost_chrono ) + +target_include_directories( boost_chrono PUBLIC include ) +target_compile_definitions( boost_chrono + PUBLIC + # NOTE: + # We deactivate autolinking because cmake based builds don't need it + # and we don't implement name mangling for the library file anyway. + # Ususally the parent CMakeLists.txt file should already have globally defined BOOST_ALL_NO_LIB + BOOST_CHRONO_NO_LIB + $<$,SHARED_LIBRARY>:BOOST_CHRONO_DYN_LINK=1> + $<$,STATIC_LIBRARY>:BOOST_CHRONO_STATIC_LINK=1> +) + +target_link_libraries( boost_chrono + PUBLIC + Boost::assert + Boost::config + Boost::core + Boost::integer + Boost::move + Boost::mpl + Boost::predef + Boost::ratio + Boost::static_assert + Boost::system + Boost::throw_exception + Boost::type_traits + Boost::typeof + Boost::utility + PRIVATE + $<$>:Boost::winapi> +) diff --git a/src/boost/libs/chrono/README.md b/src/boost/libs/chrono/README.md new file mode 100644 index 000000000..a2f91b262 --- /dev/null +++ b/src/boost/libs/chrono/README.md @@ -0,0 +1,8 @@ +Chrono +====== + +Useful time utilities. C++11. + +### License + +Distributed under the [Boost Software License, Version 1.0](http://boost.org/LICENSE_1_0.txt). diff --git a/src/boost/libs/chrono/build/Jamfile.v2 b/src/boost/libs/chrono/build/Jamfile.v2 new file mode 100644 index 000000000..1d887e2f6 --- /dev/null +++ b/src/boost/libs/chrono/build/Jamfile.v2 @@ -0,0 +1,113 @@ +# Boost Chrono Library Build Jamfile + +# Copyright Beman Dawes 2002, 2006, 2008 +# Copyright 2009-2012 Vicente J.Botet Escriba. + +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or www.boost.org/LICENSE_1_0.txt) + +# See library home page at http://www.boost.org/libs/chrono + +project boost/chrono + : source-location ../src + : requirements + freebsd:"-lrt" + linux:"-lrt -lpthread" + pgi:"-lrt" + #single:BOOST_CHRONO_THREAD_DISABLED + #BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_COMMON_TYPE_USES_STATIC_ASSERT + #BOOST_RATIO_USES_STATIC_ASSERT + #BOOST_CHRONO_USES_STATIC_ASSERT + #BOOST_COMMON_TYPE_USES_MPL_ASSERT + #BOOST_RATIO_USES_MPL_ASSERT + #BOOST_CHRONO_USES_MPL_ASSERT + #BOOST_COMMON_TYPE_USES_ARRAY_ASSERT + #BOOST_RATIO_USES_ARRAY_ASSERT + #BOOST_CHRONO_USES_ARRAY_ASSERT + sun:__typeof__=__typeof__ + #gcc-3.4.4:--enable-auto-import + #gcc-4.3.4:--enable-auto-import + #gcc-mingw-4.4.0:--enable-auto-import + #gcc-mingw-4.5.0:--enable-auto-import + all + gcc:-Wextra + #gcc:-pedantic + clang:on + gcc:-Wno-long-long + #gcc:-Wno-variadic-macros + gcc-4:-Wno-variadic-macros + gcc-5:-Wno-variadic-macros + darwin:-Wextra + darwin:-pedantic + darwin:-Wno-long-long + #darwin:-Wno-variadic-macros + darwin-4:-Wno-variadic-macros + darwin-5:-Wno-variadic-macros + #pathscale:-Wextra + pathscale:-Wno-long-long + pathscale:-pedantic + clang:-Wextra + clang:-pedantic + clang:-Wno-long-long + clang:-Wno-variadic-macros + gcc-4.4.0,windows:-fdiagnostics-show-option + gcc-4.5.0,windows:-fdiagnostics-show-option + gcc-4.6.0,windows:-fdiagnostics-show-option + gcc-4.6.3,windows:-fdiagnostics-show-option + gcc-4.7.0,windows:-fdiagnostics-show-option + gcc-4.8.0,windows:-fdiagnostics-show-option + msvc:/wd4512 + +# Note: Some of the remarks from the Intel compiler are disabled +# remark #193: zero used for undefined preprocessing identifier "XXX" +# remark #304: access control not specified ("public" by default) +# remark #383: value copied to temporary, reference to temporary used +# remark #444: destructor for base class "XXX" (declared at line YYY") is not virtual +# remark #593: variable "XXX" was set but never used +# remark #981: operands are evaluated in unspecified order +# remark #1418: external function definition with no prior declaration +# remark #2415: variable "XXX" of static storage duration was declared but never referenced + + intel:-wd193,304,383,444 + intel:-wd593,981 + intel:-wd1418 + intel:-wd2415 + + + + : usage-requirements # pass these requirement to dependents (i.e. users) + single:BOOST_CHRONO_THREAD_DISABLED + #BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_COMMON_TYPE_USES_STATIC_ASSERT + #BOOST_RATIO_USES_STATIC_ASSERT + #BOOST_CHRONO_USES_STATIC_ASSERT + #BOOST_COMMON_TYPE_USES_MPL_ASSERT + #BOOST_RATIO_USES_MPL_ASSERT + #BOOST_CHRONO_USES_MPL_ASSERT + #BOOST_COMMON_TYPE_USES_ARRAY_ASSERT + #BOOST_RATIO_USES_ARRAY_ASSERT + #BOOST_CHRONO_USES_ARRAY_ASSERT + #vacpp:BOOST_COMMON_TYPE_DONT_USE_TYPEOF + vacpp:BOOST_TYPEOF_EMULATION + sun:__typeof__=__typeof__ + + shared:BOOST_CHRONO_DYN_LINK=1 + static:BOOST_CHRONO_STATIC_LINK=1 + gcc-3.4.4:--enable-auto-import + gcc-4.3.4:--enable-auto-import + gcc-4.4.0,windows:--enable-auto-import + gcc-4.5.0,windows:--enable-auto-import + ; + +SOURCES = chrono thread_clock process_cpu_clocks ; + + +lib boost_chrono + : $(SOURCES).cpp + : + shared:BOOST_ALL_DYN_LINK=1 # tell source we're building dll's + static:BOOST_All_STATIC_LINK=1 # tell source we're building static lib's + ; + +boost-install boost_chrono ; diff --git a/src/boost/libs/chrono/example/await_keystroke.cpp b/src/boost/libs/chrono/example/await_keystroke.cpp new file mode 100644 index 000000000..6e5062437 --- /dev/null +++ b/src/boost/libs/chrono/example/await_keystroke.cpp @@ -0,0 +1,73 @@ +// await_keystroke.cpp -----------------------------------------------------// + +// Copyright Beman Dawes 2008 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#define _CRT_SECURE_NO_WARNINGS + +#include +#include +#include + +using namespace boost::chrono; + +template< class Clock > +class timer +{ + typename Clock::time_point start; +public: + + timer() : start( Clock::now() ) {} + + typename Clock::duration elapsed() const + { + return Clock::now() - start; + } + + double seconds() const + { + return elapsed().count() * ((double)Clock::period::num/Clock::period::den); + } +}; + +int main() +{ + timer t1; + timer t2; + timer t3; + + std::cout << "Strike any key: "; + std::cin.get(); + + std::cout << std::fixed << std::setprecision(9); + std::cout << "system_clock-----------: " + << t1.seconds() << " seconds\n"; + std::cout << "steady_clock--------: " + << t2.seconds() << " seconds\n"; + std::cout << "high_resolution_clock--: " + << t3.seconds() << " seconds\n"; + + system_clock::time_point d4 = system_clock::now(); + system_clock::time_point d5 = system_clock::now(); + + std::cout << "\nsystem_clock latency-----------: " << (d5 - d4).count() << std::endl; + + steady_clock::time_point d6 = steady_clock::now(); + steady_clock::time_point d7 = steady_clock::now(); + + std::cout << "steady_clock latency--------: " << (d7 - d6).count() << std::endl; + + high_resolution_clock::time_point d8 = high_resolution_clock::now(); + high_resolution_clock::time_point d9 = high_resolution_clock::now(); + + std::cout << "high_resolution_clock latency--: " << (d9 - d8).count() << std::endl; + + std::time_t now = system_clock::to_time_t(system_clock::now()); + + std::cout << "\nsystem_clock::now() reports UTC is " + << std::asctime(std::gmtime(&now)) << "\n"; + + return 0; +} diff --git a/src/boost/libs/chrono/example/chrono_unit_test.cpp b/src/boost/libs/chrono/example/chrono_unit_test.cpp new file mode 100644 index 000000000..f06fca19c --- /dev/null +++ b/src/boost/libs/chrono/example/chrono_unit_test.cpp @@ -0,0 +1,32 @@ +// chrono_unit_test.cpp ----------------------------------------------------// + +// Copyright 2008 Beman Dawes + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#define _CRT_SECURE_NO_WARNINGS // disable VC++ foolishness + +#include +#include + + +int main() +{ + std::time_t sys_time + = boost::chrono::system_clock::to_time_t(boost::chrono::system_clock::now()); + + #ifdef UNDER_CE + // Windows CE does not define asctime() + struct tm * t = std::gmtime(&sys_time); + std::cout + << "system_clock::to_time_t(system_clock::now()) is " + << t->tm_mon << "/" << t->tm_mday << "/" << (1900 + t->tm_year) << " " << t->tm_hour << ":" << t->tm_min << ":" << t->tm_sec << std::endl; + #else + std::cout + << "system_clock::to_time_t(system_clock::now()) is " + << std::asctime(std::gmtime(&sys_time)) << std::endl; + #endif + + return 0; +} diff --git a/src/boost/libs/chrono/example/clock_name.cpp b/src/boost/libs/chrono/example/clock_name.cpp new file mode 100644 index 000000000..e10117d6a --- /dev/null +++ b/src/boost/libs/chrono/example/clock_name.cpp @@ -0,0 +1,20 @@ +// stopclock_perf.cpp ---------------------------------------------------// + +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See http://www.boost.org/libs/chrono for documentation. + +#include "clock_name.hpp" +#include + +int main() +{ + std::cout << name::apply() << '\n'; +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + std::cout << name::apply() << '\n'; +#endif + std::cout << name::apply() << '\n'; +} diff --git a/src/boost/libs/chrono/example/clock_name.hpp b/src/boost/libs/chrono/example/clock_name.hpp new file mode 100644 index 000000000..74e8ff7cc --- /dev/null +++ b/src/boost/libs/chrono/example/clock_name.hpp @@ -0,0 +1,68 @@ +// stopclock_perf.cpp ---------------------------------------------------// + +// Copyright 2009 Vicente J. Botet Escriba +// Copyright 2009 Howard Hinnant + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See http://www.boost.org/libs/chrono for documentation. + +#ifndef BOOST_CHRONO_CLOCK_NAME_HPP +#define BOOST_CHRONO_CLOCK_NAME_HPP + +#include +#include + +template ::value, +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + bool = boost::is_same::value, +#else + bool = false, +#endif + bool = boost::is_same::value + > +struct name; + +template +struct name { + static const char* apply() { return "unknown clock";} +}; + +template +struct name { + static const char* apply() { return "system_clock";} +}; + +template +struct name { + static const char* apply() { return "steady_clock";} +}; + +template +struct name { + static const char* apply() { return "high_resolution_clock";} +}; + +template +struct name { + static const char* apply() { return "steady_clock and high_resolution_clock";} +}; + +template +struct name { + static const char* apply() { return "system_clock and high_resolution_clock";} +}; + +template +struct name { + static const char* apply() { return "system_clock and steady_clock";} +}; + +template +struct name { + static const char* apply() { return "system_clock, steady_clock and high_resolution_clock";} +}; + +#endif diff --git a/src/boost/libs/chrono/example/cycle_count.cpp b/src/boost/libs/chrono/example/cycle_count.cpp new file mode 100644 index 000000000..abae9c25e --- /dev/null +++ b/src/boost/libs/chrono/example/cycle_count.cpp @@ -0,0 +1,140 @@ +// cycle_count.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#include +#include + +#include + +using namespace boost::chrono; + + +template +struct cycle_count +{ + typedef typename boost::ratio_multiply, boost::mega>::type frequency; // Mhz + typedef typename boost::ratio_divide, frequency>::type period; + typedef long long rep; + typedef boost::chrono::duration duration; + typedef boost::chrono::time_point time_point; + + static time_point now() + { + static long long tick = 0; + // return exact cycle count + return time_point(duration(++tick)); // fake access to clock cycle count + } +}; + +template +struct approx_cycle_count +{ + static const long long frequency = speed * 1000000; // MHz + typedef nanoseconds duration; + typedef duration::rep rep; + typedef duration::period period; + static const long long nanosec_per_sec = period::den; + typedef boost::chrono::time_point time_point; + + static time_point now() + { + static long long tick = 0; + // return cycle count as an approximate number of nanoseconds + // compute as if nanoseconds is only duration in the std::lib + return time_point(duration(++tick * nanosec_per_sec / frequency)); + } +}; + +void cycle_count_delay() +{ + { + typedef cycle_count<400> clock; + std::cout << "\nSimulated " << clock::frequency::num / boost::mega::num << "MHz clock which has a tick period of " + << duration(clock::duration(1)).count() << " nanoseconds\n"; + nanoseconds delayns(500); + clock::duration delay = duration_cast(delayns); + std::cout << "delay = " << delayns.count() << " nanoseconds which is " << delay.count() << " cycles\n"; + clock::time_point start = clock::now(); + clock::time_point stop = start + delay; + while (clock::now() < stop) // no multiplies or divides in this loop + ; + clock::time_point end = clock::now(); + clock::duration elapsed = end - start; + std::cout << "paused " << elapsed.count() << " cycles "; + std::cout << "which is " << duration_cast(elapsed).count() << " nanoseconds\n"; + } + { + typedef approx_cycle_count<400> clock; + std::cout << "\nSimulated " << clock::frequency / 1000000 << "MHz clock modeled with nanoseconds\n"; + clock::duration delay = nanoseconds(500); + std::cout << "delay = " << delay.count() << " nanoseconds\n"; + clock::time_point start = clock::now(); + clock::time_point stop = start + delay; + while (clock::now() < stop) // 1 multiplication and 1 division in this loop + ; + clock::time_point end = clock::now(); + clock::duration elapsed = end - start; + std::cout << "paused " << elapsed.count() << " nanoseconds\n"; + } + { + typedef cycle_count<1500> clock; + std::cout << "\nSimulated " << clock::frequency::num / boost::mega::num << "MHz clock which has a tick period of " + << duration(clock::duration(1)).count() << " nanoseconds\n"; + nanoseconds delayns(500); + clock::duration delay = duration_cast(delayns); + std::cout << "delay = " << delayns.count() << " nanoseconds which is " << delay.count() << " cycles\n"; + clock::time_point start = clock::now(); + clock::time_point stop = start + delay; + while (clock::now() < stop) // no multiplies or divides in this loop + ; + clock::time_point end = clock::now(); + clock::duration elapsed = end - start; + std::cout << "paused " << elapsed.count() << " cycles "; + std::cout << "which is " << duration_cast(elapsed).count() << " nanoseconds\n"; + } + { + typedef approx_cycle_count<1500> clock; + std::cout << "\nSimulated " << clock::frequency / 1000000 << "MHz clock modeled with nanoseconds\n"; + clock::duration delay = nanoseconds(500); + std::cout << "delay = " << delay.count() << " nanoseconds\n"; + clock::time_point start = clock::now(); + clock::time_point stop = start + delay; + while (clock::now() < stop) // 1 multiplication and 1 division in this loop + ; + clock::time_point end = clock::now(); + clock::duration elapsed = end - start; + std::cout << "paused " << elapsed.count() << " nanoseconds\n"; + } +} + +int main() +{ + cycle_count_delay(); + return 0; +} + diff --git a/src/boost/libs/chrono/example/explore_limits.cpp b/src/boost/libs/chrono/example/explore_limits.cpp new file mode 100644 index 000000000..730b193cb --- /dev/null +++ b/src/boost/libs/chrono/example/explore_limits.cpp @@ -0,0 +1,60 @@ +// explore_limits.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#include +#include + +#include + +using namespace boost::chrono; + + +void explore_limits() +{ + typedef duration, + hours::period>::type> Years; +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + steady_clock::time_point t1( Years(250)); + steady_clock::time_point t2(-Years(250)); +#else + system_clock::time_point t1( Years(250)); + system_clock::time_point t2(-Years(250)); +#endif + // nanosecond resolution is likely to overflow. "up cast" to microseconds. + // The "up cast" trades precision for range. + microseconds d = time_point_cast(t1) - time_point_cast(t2); + std::cout << d.count() << " microseconds\n"; +} + + +int main() +{ + explore_limits(); + return 0; +} + diff --git a/src/boost/libs/chrono/example/french.cpp b/src/boost/libs/chrono/example/french.cpp new file mode 100644 index 000000000..f885a601c --- /dev/null +++ b/src/boost/libs/chrono/example/french.cpp @@ -0,0 +1,130 @@ +// french.cpp ----------------------------------------------------------// + +// Copyright 2010 Howard Hinnant +// Copyright 2011 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// Adapted to Boost from the original Hawards's code + + +#include +#include +#include +#include +#include +#include + + +#if BOOST_CHRONO_VERSION==2 +#include + + using namespace boost; + using namespace boost::chrono; + + template + class duration_units_fr: public duration_units_default + { + public: + typedef CharT char_type; + + explicit duration_units_fr(size_t refs = 0) : + duration_units_default(refs) + { + } + protected: + + using duration_units_default::do_get_unit; + std::size_t do_get_plural_form(boost::int_least64_t value) const + { + return (value == -1 || value == 0 || value == 1) ? 0 : 1; + } + + std::basic_string do_get_unit(duration_style style, ratio<1> , std::size_t pf) const + { + static const CharT t[] = + { 's' }; + static const std::basic_string symbol(t, t + sizeof (t) / sizeof (t[0])); + static const CharT u[] = + { 's', 'e', 'c', 'o', 'n', 'd', 'e' }; + static const std::basic_string singular(u, u + sizeof (u) / sizeof (u[0])); + static const CharT v[] = + { 's', 'e', 'c', 'o', 'n', 'd', 'e', 's' }; + static const std::basic_string plural(v, v + sizeof (v) / sizeof (v[0])); + + if (style == duration_style::symbol) return symbol; + if (pf == 0) return singular; + if (pf == 1) return plural; + // assert + //throw "exception"; + return ""; + } + + std::basic_string do_get_unit(duration_style style, ratio<60> , std::size_t pf) const + { + static const CharT t[] = + { 'm', 'i', 'n' }; + static const std::basic_string symbol(t, t + sizeof (t) / sizeof (t[0])); + + static const CharT u[] = + { 'm', 'i', 'n', 'u', 't', 'e' }; + static const std::basic_string singular(u, u + sizeof (u) / sizeof (u[0])); + static const CharT v[] = + { 'm', 'i', 'n', 'u', 't', 'e', 's' }; + static const std::basic_string plural(v, v + sizeof (v) / sizeof (v[0])); + + if (style == duration_style::symbol) return symbol; + if (pf == 0) return singular; + if (pf == 1) return plural; + // assert + //throw "exception"; + return ""; + } + + std::basic_string do_get_unit(duration_style style, ratio<3600> , std::size_t pf) const + { + static const CharT t[] = + { 'h' }; + static const std::basic_string symbol(t, t + sizeof (t) / sizeof (t[0])); + static const CharT u[] = + { 'h', 'e', 'u', 'r', 'e' }; + static const std::basic_string singular(u, u + sizeof (u) / sizeof (u[0])); + static const CharT v[] = + { 'h', 'e', 'u', 'r', 'e', 's' }; + static const std::basic_string plural(v, v + sizeof (v) / sizeof (v[0])); + + if (style == duration_style::symbol) return symbol; + if (pf == 0) return singular; + if (pf == 1) return plural; + // assert + //throw "exception"; + return ""; + } + }; +#endif + +int main() +{ + using std::cout; + using std::locale; + using namespace boost; + using namespace boost::chrono; + +#if BOOST_CHRONO_VERSION==2 + cout.imbue(locale(locale(), new duration_units_fr<>())); +#else + cout.imbue(locale(locale(), new duration_punct + ( + duration_punct::use_long, + "secondes", "minutes", "heures", + "s", "m", "h" + ))); +#endif + hours h(5); + minutes m(45); + seconds s(15); + milliseconds ms(763); + cout << h << ", " << m << ", " << s << " et " << ms << '\n'; + cout << hours(0) << ", " << minutes(0) << ", " << s << " et " << ms << '\n'; + return 0; +} diff --git a/src/boost/libs/chrono/example/i_dont_like_the_default_duration_behavior.cpp b/src/boost/libs/chrono/example/i_dont_like_the_default_duration_behavior.cpp new file mode 100644 index 000000000..3fb4a90de --- /dev/null +++ b/src/boost/libs/chrono/example/i_dont_like_the_default_duration_behavior.cpp @@ -0,0 +1,97 @@ +// i_dont_like_the_default_duration_behavior.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#include +#include + +#include + +namespace I_dont_like_the_default_duration_behavior +{ + +// Here's how you override the duration's default constructor to do anything you want (in this case zero) + +template +class zero_default +{ +public: + typedef R rep; + +private: + rep rep_; +public: + zero_default(rep i = 0) : rep_(i) {} + operator rep() const {return rep_;} + + zero_default& operator+=(zero_default x) {rep_ += x.rep_; return *this;} + zero_default& operator-=(zero_default x) {rep_ -= x.rep_; return *this;} + zero_default& operator*=(zero_default x) {rep_ *= x.rep_; return *this;} + zero_default& operator/=(zero_default x) {rep_ /= x.rep_; return *this;} + + zero_default operator+ () const {return *this;} + zero_default operator- () const {return zero_default(-rep_);} + zero_default& operator++() {++rep_; return *this;} + zero_default operator++(int) {return zero_default(rep_++);} + zero_default& operator--() {--rep_; return *this;} + zero_default operator--(int) {return zero_default(rep_--);} + + friend zero_default operator+(zero_default x, zero_default y) {return x += y;} + friend zero_default operator-(zero_default x, zero_default y) {return x -= y;} + friend zero_default operator*(zero_default x, zero_default y) {return x *= y;} + friend zero_default operator/(zero_default x, zero_default y) {return x /= y;} + + friend bool operator==(zero_default x, zero_default y) {return x.rep_ == y.rep_;} + friend bool operator!=(zero_default x, zero_default y) {return !(x == y);} + friend bool operator< (zero_default x, zero_default y) {return x.rep_ < y.rep_;} + friend bool operator<=(zero_default x, zero_default y) {return !(y < x);} + friend bool operator> (zero_default x, zero_default y) {return y < x;} + friend bool operator>=(zero_default x, zero_default y) {return !(x < y);} +}; + +typedef boost::chrono::duration, boost::nano > nanoseconds; +typedef boost::chrono::duration, boost::micro > microseconds; +typedef boost::chrono::duration, boost::milli > milliseconds; +typedef boost::chrono::duration > seconds; +typedef boost::chrono::duration, boost::ratio<60> > minutes; +typedef boost::chrono::duration, boost::ratio<3600> > hours; + +void test() +{ + milliseconds ms; + std::cout << ms.count() << '\n'; +} + +} // I_dont_like_the_default_duration_behavior + + +int main() +{ + I_dont_like_the_default_duration_behavior::test(); + return 0; +} + diff --git a/src/boost/libs/chrono/example/io_ex1.cpp b/src/boost/libs/chrono/example/io_ex1.cpp new file mode 100644 index 000000000..2e021dd3d --- /dev/null +++ b/src/boost/libs/chrono/example/io_ex1.cpp @@ -0,0 +1,87 @@ +// io_ex1.cpp ----------------------------------------------------------// + +// Copyright 2010 Howard Hinnant +// Copyright 2010 Vicente J. Botet Escriba +// Copyright (c) Microsoft Corporation 2014 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was adapted by Vicente J. Botet Escriba from Hinnant's html documentation. +Many thanks to Howard for making his code available under the Boost license. + +*/ + +#include +#include +#include +#include +#include +#include + +int main() +{ + using std::cout; + using namespace boost; + using namespace boost::chrono; + + cout << "milliseconds(1) = " + << milliseconds(1) << '\n'; + cout << "milliseconds(3) + microseconds(10) = " + << milliseconds(3) + microseconds(10) << '\n'; + + cout << "hours(3) + minutes(10) = " + << hours(3) + minutes(10) << '\n'; + + typedef duration > ClockTick; + cout << "ClockTick(3) + nanoseconds(10) = " + << ClockTick(3) + nanoseconds(10) << '\n'; + + cout << "\nSet cout to use short names:\n"; +#if BOOST_CHRONO_VERSION==2 + cout << duration_fmt(duration_style::symbol); +#else + cout << duration_short; +#endif + cout << "milliseconds(3) + microseconds(10) = " + << milliseconds(3) + microseconds(10) << '\n'; + + cout << "hours(3) + minutes(10) = " + << hours(3) + minutes(10) << '\n'; + + cout << "ClockTick(3) + nanoseconds(10) = " + << ClockTick(3) + nanoseconds(10) << '\n'; + + cout << "\nsystem_clock::now() = " << system_clock::now() << '\n'; +#if defined _MSC_VER && _MSC_VER == 1700 +#else +#if BOOST_CHRONO_VERSION==2 + cout << "\nsystem_clock::now() = " << time_fmt(chrono::timezone::local) << system_clock::now() << '\n'; + cout << "\nsystem_clock::now() = " << time_fmt(chrono::timezone::local,"%Y/%m/%d") << system_clock::now() << '\n'; +#endif +#endif + +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + cout << "steady_clock::now() = " << steady_clock::now() << '\n'; +#endif +#if BOOST_CHRONO_VERSION==2 + cout << "\nSet cout to use long names:\n" << duration_fmt(duration_style::prefix) + << "high_resolution_clock::now() = " << high_resolution_clock::now() << '\n'; +#else + cout << "\nSet cout to use long names:\n" << duration_long + << "high_resolution_clock::now() = " << high_resolution_clock::now() << '\n'; +#endif +#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) + cout << "\nthread_clock::now() = " << thread_clock::now() << '\n'; +#endif +#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS) + cout << "\nprocess_real_cpu_clock::now() = " << process_real_cpu_clock::now() << '\n'; +#if BOOST_PLAT_WINDOWS_DESKTOP + cout << "\nprocess_user_cpu_clock::now() = " << process_user_cpu_clock::now() << '\n'; + cout << "\nprocess_system_cpu_clock::now() = " << process_system_cpu_clock::now() << '\n'; + cout << "\nprocess_cpu_clock::now() = " << process_cpu_clock::now() << '\n'; +#endif +#endif + return 0; +} diff --git a/src/boost/libs/chrono/example/io_ex2.cpp b/src/boost/libs/chrono/example/io_ex2.cpp new file mode 100644 index 000000000..b67b4e146 --- /dev/null +++ b/src/boost/libs/chrono/example/io_ex2.cpp @@ -0,0 +1,36 @@ +// io_ex2.cpp ----------------------------------------------------------// + +// Copyright 2010 Howard Hinnant +// Copyright 2010 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was adapted by Vicente J. Botet Escriba from Hinnant's html documentation. +Many thanks to Howard for making his code available under the Boost license. + +*/ + +#include +#include +#include + +int main() +{ + using namespace boost::chrono; + + std::istringstream in("5000 milliseconds 4000 ms 3001 ms"); + seconds d(0); + in >> d; + BOOST_ASSERT(in.good()); + BOOST_ASSERT(d == seconds(5)); + in >> d; + BOOST_ASSERT(in.good()); + BOOST_ASSERT(d == seconds(4)); + in >> d; + BOOST_ASSERT(in.fail()); + BOOST_ASSERT(d == seconds(4)); + return 0; +} + diff --git a/src/boost/libs/chrono/example/io_ex3.cpp b/src/boost/libs/chrono/example/io_ex3.cpp new file mode 100644 index 000000000..c972df426 --- /dev/null +++ b/src/boost/libs/chrono/example/io_ex3.cpp @@ -0,0 +1,48 @@ +// io_ex1.cpp ----------------------------------------------------------// + +// Copyright 2010 Howard Hinnant +// Copyright 2010 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was adapted by Vicente J. Botet Escriba from Hinnant's html documentation. +Many thanks to Howard for making his code available under the Boost license. + +*/ + +#include +#include +#include +#include + +int main() +{ + using namespace boost::chrono; + using std::cout; + + high_resolution_clock::time_point t0 = high_resolution_clock::now(); + std::stringstream io; + io << t0; + BOOST_ASSERT(!io.fail()); + cout << io.str() << '\n'; + BOOST_ASSERT(!io.fail()); + high_resolution_clock::time_point t1; + io >> t1; + BOOST_ASSERT(!io.fail()); + cout << io.str() << '\n'; + cout << t0 << '\n'; + cout << t1 << '\n'; + high_resolution_clock::time_point t = high_resolution_clock::now(); + cout << t << '\n'; + + cout << "That took " << t - t0 << '\n'; + cout << "That took " << t - t1 << '\n'; + + return 0; +} + +//~ 50908679121461 nanoseconds since boot +//~ That took 649630 nanoseconds + diff --git a/src/boost/libs/chrono/example/io_ex4.cpp b/src/boost/libs/chrono/example/io_ex4.cpp new file mode 100644 index 000000000..04856ed7f --- /dev/null +++ b/src/boost/libs/chrono/example/io_ex4.cpp @@ -0,0 +1,32 @@ +// io_ex1.cpp ----------------------------------------------------------// + +// Copyright 2010 Howard Hinnant +// Copyright 2010 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was adapted by Vicente J. Botet Escriba from Hinnant's html documentation. +Many thanks to Howard for making his code available under the Boost license. + +*/ + +#include +#include + +int main() +{ + using std::cout; + using namespace boost; + using namespace boost::chrono; + +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + typedef time_point > > T; + T tp = steady_clock::now(); + std::cout << tp << '\n'; +#endif + return 0; +} + +//~ 17.8666 hours since boot diff --git a/src/boost/libs/chrono/example/io_ex5.cpp b/src/boost/libs/chrono/example/io_ex5.cpp new file mode 100644 index 000000000..4bd5cbb46 --- /dev/null +++ b/src/boost/libs/chrono/example/io_ex5.cpp @@ -0,0 +1,90 @@ +// io_ex1.cpp ----------------------------------------------------------// + +// Copyright 2010 Howard Hinnant +// Copyright 2010 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was adapted by Vicente J. Botet Escriba from Hinnant's html documentation. +Many thanks to Howard for making his code available under the Boost license. + +*/ + +#include +#include +#include + +// format duration as [-]d/hh::mm::ss.cc +template +std::basic_ostream& +display(std::basic_ostream& os, + boost::chrono::duration d) +{ + using std::cout; + using namespace boost; + using namespace boost::chrono; + + typedef duration > days; + typedef duration centiseconds; + + // if negative, print negative sign and negate + if (d < duration(0)) + { + d = -d; + os << '-'; + } + // round d to nearest centiseconds, to even on tie + centiseconds cs = duration_cast(d); + if (d - cs > milliseconds(5) + || (d - cs == milliseconds(5) && cs.count() & 1)) + ++cs; + // separate seconds from centiseconds + seconds s = duration_cast(cs); + cs -= s; + // separate minutes from seconds + minutes m = duration_cast(s); + s -= m; + // separate hours from minutes + hours h = duration_cast(m); + m -= h; + // separate days from hours + days dy = duration_cast(h); + h -= dy; + // print d/hh:mm:ss.cc + os << dy.count() << '/'; + if (h < hours(10)) + os << '0'; + os << h.count() << ':'; + if (m < minutes(10)) + os << '0'; + os << m.count() << ':'; + if (s < seconds(10)) + os << '0'; + os << s.count() << '.'; + if (cs < centiseconds(10)) + os << '0'; + os << cs.count(); + return os; +} + +int main() +{ + using std::cout; + using namespace boost; + using namespace boost::chrono; + +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + display(cout, steady_clock::now().time_since_epoch() + + duration(1)) << '\n'; +#endif + display(cout, -milliseconds(6)) << '\n'; + display(cout, duration(1)) << '\n'; + display(cout, -duration(1)) << '\n'; +} + +//~ 12/06:03:22.95 +//~ -0/00:00:00.01 +//~ 11/13:46:40.00 +//~ -11/13:46:40.00 diff --git a/src/boost/libs/chrono/example/manipulate_clock_object.cpp b/src/boost/libs/chrono/example/manipulate_clock_object.cpp new file mode 100644 index 000000000..96d89541b --- /dev/null +++ b/src/boost/libs/chrono/example/manipulate_clock_object.cpp @@ -0,0 +1,61 @@ +// manipulate_clock_object.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#include +#include + +#include + +using namespace boost::chrono; + +#if defined _MSC_VER +#pragma warning(push) +#pragma warning(disable:4100) +#endif +void manipulate_clock_object(system_clock clock) +#if defined _MSC_VER +#pragma warning(pop) +#endif +{ + system_clock::duration delay = milliseconds(5); + system_clock::time_point start = clock.now(); + + while ((clock.now() - start) <= delay) {} + + system_clock::time_point stop = clock.now(); + system_clock::duration elapsed = stop - start; + std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; +} + + +int main() +{ + manipulate_clock_object(system_clock()); + return 0; +} + diff --git a/src/boost/libs/chrono/example/min_time_point.cpp b/src/boost/libs/chrono/example/min_time_point.cpp new file mode 100644 index 000000000..91a4b72b5 --- /dev/null +++ b/src/boost/libs/chrono/example/min_time_point.cpp @@ -0,0 +1,79 @@ +// min_time_point.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#include +#include + +#include + +using namespace boost::chrono; + +template +void print_duration(std::ostream& os, duration d) +{ + os << d.count() << " * " << Period::num << '/' << Period::den << " seconds\n"; +} + +namespace my_ns { +// Example min utility: returns the earliest time_point +// Being able to *easily* write this function is a major feature! +template +inline +typename boost::common_type, + time_point >::type +min BOOST_PREVENT_MACRO_SUBSTITUTION (time_point t1, time_point t2) +{ + return t2 < t1 ? t2 : t1; +} +} +void test_min() +{ +#if 1 + typedef time_point::type> T1; + typedef time_point::type> T2; + typedef boost::common_type::type T3; + /*auto*/ T1 t1 = system_clock::now() + seconds(3); + /*auto*/ T2 t2 = system_clock::now() + nanoseconds(3); + /*auto*/ T3 t3 = (my_ns::min)(t1, t2); +#else + BOOST_AUTO(t1, system_clock::now() + seconds(3)); + BOOST_AUTO(t2, system_clock::now() + nanoseconds(3)); + BOOST_AUTO(t3, (min)(t1, t2)); +#endif + print_duration(std::cout, t1 - t3); + print_duration(std::cout, t2 - t3); +} + +int main() +{ + test_min(); + return 0; +} + diff --git a/src/boost/libs/chrono/example/miscellaneous.cpp b/src/boost/libs/chrono/example/miscellaneous.cpp new file mode 100644 index 000000000..414546f55 --- /dev/null +++ b/src/boost/libs/chrono/example/miscellaneous.cpp @@ -0,0 +1,156 @@ +// miscellaneous.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#include +#include + +#include + +// miscellaneous tests and demos: + +#include +#include + +using namespace boost::chrono; + +void physics_function(duration d) +{ + std::cout << "d = " << d.count() << '\n'; +} + +void drive_physics_function() +{ + physics_function(nanoseconds(3)); + physics_function(hours(3)); + physics_function(duration(2./3)); + std::cout.precision(16); + physics_function( hours(3) + nanoseconds(-3) ); +} + +void test_range() +{ + using namespace boost::chrono; + hours h1 = hours(24 * ( 365 * 292 + 292/4)); + nanoseconds n1 = h1 + nanoseconds(1); + nanoseconds delta = n1 - h1; + std::cout << "292 years of hours = " << h1.count() << "hr\n"; + std::cout << "Add a nanosecond = " << n1.count() << "ns\n"; + std::cout << "Find the difference = " << delta.count() << "ns\n"; +} + +void test_extended_range() +{ + using namespace boost::chrono; + hours h1 = hours(24 * ( 365 * 244000 + 244000/4)); + /*auto*/ microseconds u1 = h1 + microseconds(1); + /*auto*/ microseconds delta = u1 - h1; + std::cout << "244,000 years of hours = " << h1.count() << "hr\n"; + std::cout << "Add a microsecond = " << u1.count() << "us\n"; + std::cout << "Find the difference = " << delta.count() << "us\n"; +} + +template +void inspect_duration(boost::chrono::duration d, const std::string& name) +{ + typedef boost::chrono::duration Duration; + std::cout << "********* " << name << " *********\n"; + std::cout << "The period of " << name << " is " << (double)Period::num/Period::den << " seconds.\n"; + std::cout << "The frequency of " << name << " is " << (double)Period::den/Period::num << " Hz.\n"; + std::cout << "The representation is "; + if (boost::is_floating_point::value) + { + std::cout << "floating point\n"; + std::cout << "The precision is the most significant "; + std::cout << std::numeric_limits::digits10 << " decimal digits.\n"; + } + else if (boost::is_integral::value) + { + std::cout << "integral\n"; + d = Duration(Rep(1)); + boost::chrono::duration dsec = d; + std::cout << "The precision is " << dsec.count() << " seconds.\n"; + } + else + { + std::cout << "a class type\n"; + d = Duration(Rep(1)); + boost::chrono::duration dsec = d; + std::cout << "The precision is " << dsec.count() << " seconds.\n"; + } + d = Duration((std::numeric_limits::max)()); + using namespace boost::chrono; + typedef duration, hours::period>::type> Years; + Years years = d; + std::cout << "The range is +/- " << years.count() << " years.\n"; + std::cout << "sizeof(" << name << ") = " << sizeof(d) << '\n'; +} + +void inspect_all() +{ + using namespace boost::chrono; + std::cout.precision(6); + inspect_duration(nanoseconds(), "nanoseconds"); + inspect_duration(microseconds(), "microseconds"); + inspect_duration(milliseconds(), "milliseconds"); + inspect_duration(seconds(), "seconds"); + inspect_duration(minutes(), "minutes"); + inspect_duration(hours(), "hours"); + inspect_duration(duration(), "duration"); +} + +void test_milliseconds() +{ + using namespace boost::chrono; + milliseconds ms(250); + ms += milliseconds(1); + milliseconds ms2(150); + milliseconds msdiff = ms - ms2; + if (msdiff == milliseconds(101)) + std::cout << "success\n"; + else + std::cout << "failure: " << msdiff.count() << '\n'; +} + +int main() +{ + using namespace boost; + drive_physics_function(); + test_range(); + test_extended_range(); + inspect_all(); + test_milliseconds(); + inspect_duration(common_type, hours, microseconds>::type(), + "common_type, hours, microseconds>::type"); + duration d = milliseconds(3) * 2.5; + inspect_duration(milliseconds(3) * 2.5, "milliseconds(3) * 2.5"); + std::cout << d.count() << '\n'; +// milliseconds ms(3.5); // doesn't compile +// std::cout << "milliseconds ms(3.5) doesn't compile\n"; + return 0; +} + diff --git a/src/boost/libs/chrono/example/rounding.cpp b/src/boost/libs/chrono/example/rounding.cpp new file mode 100644 index 000000000..31fa59568 --- /dev/null +++ b/src/boost/libs/chrono/example/rounding.cpp @@ -0,0 +1,44 @@ +// french.cpp ----------------------------------------------------------// + +// Copyright 2010 Howard Hinnant +// Copyright 2011 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// Adapted to Boost from the original Hawards's code + +#include +//#include +#include +#include +#include + +int main() +{ + boost::chrono::milliseconds ms(2500); + std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl; + std::cout << boost::chrono::floor(ms).count() + << " seconds\n"; + std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl; + std::cout << boost::chrono::round(ms).count() + << " seconds\n"; + std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl; + std::cout << boost::chrono::ceil(ms).count() + << " seconds\n"; + std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl; + ms = boost::chrono::milliseconds(2516); + std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl; + typedef boost::chrono::duration > frame_rate; + std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl; + std::cout << boost::chrono::floor(ms).count() + << " [1/30] seconds\n"; + std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl; + std::cout << boost::chrono::round(ms).count() + << " [1/30] seconds\n"; + std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl; + std::cout << boost::chrono::ceil(ms).count() + << " [1/30] seconds\n"; + std::cout << __FILE__ << "[" << __LINE__ << "]" << std::endl; + + return 0; +} diff --git a/src/boost/libs/chrono/example/run_timer_example.cpp b/src/boost/libs/chrono/example/run_timer_example.cpp new file mode 100644 index 000000000..de1c318f9 --- /dev/null +++ b/src/boost/libs/chrono/example/run_timer_example.cpp @@ -0,0 +1,22 @@ +// run_timer_example.cpp ---------------------------------------------------// + +// Copyright Beman Dawes 2006, 2008 +// Copyright 2009/2010 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See http://www.boost.org/libs/chrono for documentation. + +#include +#include + +int main() +{ + boost::chrono::run_timer t; + + for ( long i = 0; i < 10000; ++i ) + std::sqrt( 123.456L ); // burn some time + + return 0; +} diff --git a/src/boost/libs/chrono/example/run_timer_example2.cpp b/src/boost/libs/chrono/example/run_timer_example2.cpp new file mode 100644 index 000000000..521859714 --- /dev/null +++ b/src/boost/libs/chrono/example/run_timer_example2.cpp @@ -0,0 +1,24 @@ +// run_timer_example.cpp ---------------------------------------------------// + +// Copyright Beman Dawes 2006, 2008 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See http://www.boost.org/libs/chrono for documentation. + +#include +#include + +int main( int argc, char * argv[] ) +{ + const char * format = argc > 1 ? argv[1] : "%t cpu seconds\n"; + int places = argc > 2 ? std::atoi( argv[2] ) : 2; + + boost::chrono::run_timer t( format, places ); + + for ( long i = 0; i < 10000; ++i ) + std::sqrt( 123.456L ); // burn some time + + return 0; +} diff --git a/src/boost/libs/chrono/example/runtime_resolution.cpp b/src/boost/libs/chrono/example/runtime_resolution.cpp new file mode 100644 index 000000000..29c411450 --- /dev/null +++ b/src/boost/libs/chrono/example/runtime_resolution.cpp @@ -0,0 +1,244 @@ +// runtime_resolution.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba +// Copyright (c) Microsoft Corporation 2014 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ +#define _CRT_SECURE_NO_WARNINGS // disable VC++ foolishness + +#include +#include + +#include + +#if defined(BOOST_CHRONO_MAC_API) +#include //for gettimeofday and timeval +#include // mach_absolute_time, mach_timebase_info_data_t +#endif + +#if defined(BOOST_CHRONO_WINDOWS_API) +#include + +namespace +{ + #if defined UNDER_CE || BOOST_PLAT_WINDOWS_RUNTIME + // Windows CE and Windows store does not define timeval + struct timeval { + long tv_sec; /* seconds */ + long tv_usec; /* and microseconds */ + }; + #endif + + int gettimeofday(struct timeval * tp, void *) + { + FILETIME ft; + #if defined(UNDER_CE) + // Windows CE does not define GetSystemTimeAsFileTime so we do it in two steps. + SYSTEMTIME st; + ::GetSystemTime( &st ); + ::SystemTimeToFileTime( &st, &ft ); + #else + ::GetSystemTimeAsFileTime( &ft ); // never fails + #endif + long long t = (static_cast(ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + # if !defined( BOOST_MSVC ) || BOOST_MSVC > 1300 // > VC++ 7.0 + t -= 116444736000000000LL; + # else + t -= 116444736000000000; + # endif + t /= 10; // microseconds + tp->tv_sec = static_cast( t / 1000000UL); + tp->tv_usec = static_cast( t % 1000000UL); + return 0; + } +} // unnamed namespace + +#endif + +// Handle duration with resolution not known until run time +using namespace boost::chrono; + +namespace runtime_resolution +{ + +class duration +{ +public: + typedef long long rep; +private: + rep rep_; + + static const double ticks_per_nanosecond; + +public: + typedef boost::chrono::duration tonanosec; + + duration() {} // = default; + explicit duration(const rep& r) : rep_(r) {} + + // conversions + explicit duration(const tonanosec& d) + : rep_(static_cast(d.count() * ticks_per_nanosecond)) {} + + // explicit + tonanosec convert_to_nanosec() const {return tonanosec(rep_/ticks_per_nanosecond);} + + // observer + + rep count() const {return rep_;} + + // arithmetic + + duration& operator+=(const duration& d) {rep_ += d.rep_; return *this;} + duration& operator-=(const duration& d) {rep_ += d.rep_; return *this;} + duration& operator*=(rep rhs) {rep_ *= rhs; return *this;} + duration& operator/=(rep rhs) {rep_ /= rhs; return *this;} + + duration operator+() const {return *this;} + duration operator-() const {return duration(-rep_);} + duration& operator++() {++rep_; return *this;} + duration operator++(int) {return duration(rep_++);} + duration& operator--() {--rep_; return *this;} + duration operator--(int) {return duration(rep_--);} + + friend duration operator+(duration x, duration y) {return x += y;} + friend duration operator-(duration x, duration y) {return x -= y;} + friend duration operator*(duration x, rep y) {return x *= y;} + friend duration operator*(rep x, duration y) {return y *= x;} + friend duration operator/(duration x, rep y) {return x /= y;} + + friend bool operator==(duration x, duration y) {return x.rep_ == y.rep_;} + friend bool operator!=(duration x, duration y) {return !(x == y);} + friend bool operator< (duration x, duration y) {return x.rep_ < y.rep_;} + friend bool operator<=(duration x, duration y) {return !(y < x);} + friend bool operator> (duration x, duration y) {return y < x;} + friend bool operator>=(duration x, duration y) {return !(x < y);} +}; + +static +double +init_duration() +{ +#if defined(BOOST_CHRONO_WINDOWS_API) + return static_cast(1) / 1000; // Windows FILETIME is 1 per microsec +#elif defined(BOOST_CHRONO_MAC_API) + mach_timebase_info_data_t MachInfo; + mach_timebase_info(&MachInfo); + return static_cast(MachInfo.denom) / MachInfo.numer; +#elif defined(BOOST_CHRONO_POSIX_API) + return static_cast(1) / 1000; +#endif + +} + +const double duration::ticks_per_nanosecond = init_duration(); + +class clock; + +class time_point +{ +public: + typedef runtime_resolution::clock clock; + typedef long long rep; +private: + rep rep_; + + + rep count() const {return rep_;} +public: + + time_point() : rep_(0) {} + explicit time_point(const duration& d) + : rep_(d.count()) {} + + // arithmetic + + time_point& operator+=(const duration& d) {rep_ += d.count(); return *this;} + time_point& operator-=(const duration& d) {rep_ -= d.count(); return *this;} + + friend time_point operator+(time_point x, duration y) {return x += y;} + friend time_point operator+(duration x, time_point y) {return y += x;} + friend time_point operator-(time_point x, duration y) {return x -= y;} + friend duration operator-(time_point x, time_point y) {return duration(x.rep_ - y.rep_);} +}; + + +class clock +{ +public: + typedef runtime_resolution::duration::rep rep; + typedef runtime_resolution::duration duration; + typedef runtime_resolution::time_point time_point; + + static time_point now() + { + +#if defined(BOOST_CHRONO_WINDOWS_API) + timeval tv; + gettimeofday( &tv, 0 ); + return time_point(duration((static_cast(tv.tv_sec)<<32) | tv.tv_usec)); + +#elif defined(BOOST_CHRONO_MAC_API) + + timeval tv; + gettimeofday( &tv, 0 ); + return time_point(duration((static_cast(tv.tv_sec)<<32) | tv.tv_usec)); + +#elif defined(BOOST_CHRONO_POSIX_API) + timespec ts; + ::clock_gettime( CLOCK_REALTIME, &ts ); + + return time_point(duration((static_cast(ts.tv_sec)<<32) | ts.tv_nsec/1000)); + + +#endif // POSIX + + } +}; + +void test() +{ + std::cout << "runtime_resolution test\n"; + clock::duration delay(boost::chrono::milliseconds(5)); + clock::time_point start = clock::now(); + while (clock::now() - start <= delay) + ; + clock::time_point stop = clock::now(); + clock::duration elapsed = stop - start; + std::cout << "paused " << + boost::chrono::nanoseconds( + boost::chrono::duration_cast( elapsed.convert_to_nanosec() )).count() + << " nanoseconds\n"; +} + +} // runtime_resolution + + +int main() +{ + runtime_resolution::test(); + return 0; +} + diff --git a/src/boost/libs/chrono/example/saturating.cpp b/src/boost/libs/chrono/example/saturating.cpp new file mode 100644 index 000000000..b7c7ba1f2 --- /dev/null +++ b/src/boost/libs/chrono/example/saturating.cpp @@ -0,0 +1,505 @@ +// saturating.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#define _CRT_SECURE_NO_WARNINGS // disable VC++ foolishness + +#include +#include + +#include + +////////////////////////////////////////////////////////// +//////////////////// User2 Example /////////////////////// +////////////////////////////////////////////////////////// + +// Demonstrate User2: +// A "saturating" signed integral type is developed. This type has +/- infinity and a nan +// (like IEEE floating point) but otherwise obeys signed integral arithmetic. +// This class is subsequently used as the rep in boost::chrono::duration to demonstrate a +// duration class that does not silently ignore overflow. +#include +#include +#include + +namespace User2 +{ + +template +class saturate +{ +public: + typedef I int_type; + + static const int_type nan = int_type(int_type(1) << (sizeof(int_type) * CHAR_BIT - 1)); + static const int_type neg_inf = nan + 1; + static const int_type pos_inf = -neg_inf; +private: + int_type i_; + +// static_assert(std::is_integral::value && std::is_signed::value, +// "saturate only accepts signed integral types"); +// static_assert(nan == -nan && neg_inf < pos_inf, +// "saturate assumes two's complement hardware for signed integrals"); + +public: + saturate() : i_(nan) {} + explicit saturate(int_type i) : i_(i) {} + // explicit + operator int_type() const; + + saturate& operator+=(saturate x); + saturate& operator-=(saturate x) {return *this += -x;} + saturate& operator*=(saturate x); + saturate& operator/=(saturate x); + saturate& operator%=(saturate x); + + saturate operator- () const {return saturate(-i_);} + saturate& operator++() {*this += saturate(int_type(1)); return *this;} + saturate operator++(int) {saturate tmp(*this); ++(*this); return tmp;} + saturate& operator--() {*this -= saturate(int_type(1)); return *this;} + saturate operator--(int) {saturate tmp(*this); --(*this); return tmp;} + + friend saturate operator+(saturate x, saturate y) {return x += y;} + friend saturate operator-(saturate x, saturate y) {return x -= y;} + friend saturate operator*(saturate x, saturate y) {return x *= y;} + friend saturate operator/(saturate x, saturate y) {return x /= y;} + friend saturate operator%(saturate x, saturate y) {return x %= y;} + + friend bool operator==(saturate x, saturate y) + { + if (x.i_ == nan || y.i_ == nan) + return false; + return x.i_ == y.i_; + } + + friend bool operator!=(saturate x, saturate y) {return !(x == y);} + + friend bool operator<(saturate x, saturate y) + { + if (x.i_ == nan || y.i_ == nan) + return false; + return x.i_ < y.i_; + } + + friend bool operator<=(saturate x, saturate y) + { + if (x.i_ == nan || y.i_ == nan) + return false; + return x.i_ <= y.i_; + } + + friend bool operator>(saturate x, saturate y) + { + if (x.i_ == nan || y.i_ == nan) + return false; + return x.i_ > y.i_; + } + + friend bool operator>=(saturate x, saturate y) + { + if (x.i_ == nan || y.i_ == nan) + return false; + return x.i_ >= y.i_; + } + + friend std::ostream& operator<<(std::ostream& os, saturate s) + { + switch (s.i_) + { + case pos_inf: + return os << "inf"; + case nan: + return os << "nan"; + case neg_inf: + return os << "-inf"; + }; + return os << s.i_; + } +}; + +template +saturate::operator I() const +{ + switch (i_) + { + case nan: + case neg_inf: + case pos_inf: + throw std::out_of_range("saturate special value can not convert to int_type"); + } + return i_; +} + +template +saturate& +saturate::operator+=(saturate x) +{ + switch (i_) + { + case pos_inf: + switch (x.i_) + { + case neg_inf: + case nan: + i_ = nan; + } + return *this; + case nan: + return *this; + case neg_inf: + switch (x.i_) + { + case pos_inf: + case nan: + i_ = nan; + } + return *this; + } + switch (x.i_) + { + case pos_inf: + case neg_inf: + case nan: + i_ = x.i_; + return *this; + } + if (x.i_ >= 0) + { + if (i_ < pos_inf - x.i_) + i_ += x.i_; + else + i_ = pos_inf; + return *this; + } + if (i_ > neg_inf - x.i_) + i_ += x.i_; + else + i_ = neg_inf; + return *this; +} + +template +saturate& +saturate::operator*=(saturate x) +{ + switch (i_) + { + case 0: + switch (x.i_) + { + case pos_inf: + case neg_inf: + case nan: + i_ = nan; + } + return *this; + case pos_inf: + switch (x.i_) + { + case nan: + case 0: + i_ = nan; + return *this; + } + if (x.i_ < 0) + i_ = neg_inf; + return *this; + case nan: + return *this; + case neg_inf: + switch (x.i_) + { + case nan: + case 0: + i_ = nan; + return *this; + } + if (x.i_ < 0) + i_ = pos_inf; + return *this; + } + switch (x.i_) + { + case 0: + i_ = 0; + return *this; + case nan: + i_ = nan; + return *this; + case pos_inf: + if (i_ < 0) + i_ = neg_inf; + else + i_ = pos_inf; + return *this; + case neg_inf: + if (i_ < 0) + i_ = pos_inf; + else + i_ = neg_inf; + return *this; + } + int s = (i_ < 0 ? -1 : 1) * (x.i_ < 0 ? -1 : 1); + i_ = i_ < 0 ? -i_ : i_; + int_type x_i_ = x.i_ < 0 ? -x.i_ : x.i_; + if (i_ <= pos_inf / x_i_) + i_ *= x_i_; + else + i_ = pos_inf; + i_ *= s; + return *this; +} + +template +saturate& +saturate::operator/=(saturate x) +{ + switch (x.i_) + { + case pos_inf: + case neg_inf: + switch (i_) + { + case pos_inf: + case neg_inf: + case nan: + i_ = nan; + break; + default: + i_ = 0; + break; + } + return *this; + case nan: + i_ = nan; + return *this; + case 0: + switch (i_) + { + case pos_inf: + case neg_inf: + case nan: + return *this; + case 0: + i_ = nan; + return *this; + } + if (i_ > 0) + i_ = pos_inf; + else + i_ = neg_inf; + return *this; + } + switch (i_) + { + case 0: + case nan: + return *this; + case pos_inf: + case neg_inf: + if (x.i_ < 0) + i_ = -i_; + return *this; + } + i_ /= x.i_; + return *this; +} + +template +saturate& +saturate::operator%=(saturate x) +{ +// *this -= *this / x * x; // definition + switch (x.i_) + { + case nan: + case neg_inf: + case 0: + case pos_inf: + i_ = nan; + return *this; + } + switch (i_) + { + case neg_inf: + case pos_inf: + i_ = nan; + case nan: + return *this; + } + i_ %= x.i_; + return *this; +} + +// Demo overflow-safe integral durations ranging from picoseconds resolution to millennium resolution +typedef boost::chrono::duration, boost::pico > picoseconds; +typedef boost::chrono::duration, boost::nano > nanoseconds; +typedef boost::chrono::duration, boost::micro > microseconds; +typedef boost::chrono::duration, boost::milli > milliseconds; +typedef boost::chrono::duration > seconds; +typedef boost::chrono::duration, boost::ratio< 60LL> > minutes; +typedef boost::chrono::duration, boost::ratio< 3600LL> > hours; +typedef boost::chrono::duration, boost::ratio< 86400LL> > days; +typedef boost::chrono::duration, boost::ratio< 31556952LL> > years; +typedef boost::chrono::duration, boost::ratio<31556952000LL> > millennium; + +} // User2 + +// Demonstrate custom promotion rules (needed only if there are no implicit conversions) +namespace User2 { namespace detail { + +template ::value> +struct promote_helper; + +template +struct promote_helper, true> // integral +{ + typedef typename boost::common_type::type rep; + typedef User2::saturate type; +}; + +template +struct promote_helper, false> // floating +{ + typedef T1 type; +}; + +} } + +namespace boost +{ + +template +struct common_type, User2::saturate > +{ + typedef typename common_type::type rep; + typedef User2::saturate type; +}; + +template +struct common_type > + : User2::detail::promote_helper > {}; + +template +struct common_type, T2> + : User2::detail::promote_helper > {}; + + +// Demonstrate specialization of duration_values: + +namespace chrono { + +template +struct duration_values > +{ + typedef User2::saturate Rep; +public: + static Rep zero() {return Rep(0);} + static Rep max BOOST_PREVENT_MACRO_SUBSTITUTION () {return Rep(Rep::pos_inf-1);} + static Rep min BOOST_PREVENT_MACRO_SUBSTITUTION () {return -(max)();} +}; + +} // namespace chrono + +} // namespace boost + +#include + +void testUser2() +{ + std::cout << "*************\n"; + std::cout << "* testUser2 *\n"; + std::cout << "*************\n"; + using namespace User2; + typedef seconds::rep sat; + years yr(sat(100)); + std::cout << "100 years expressed as years = " << yr.count() << '\n'; + nanoseconds ns = yr; + std::cout << "100 years expressed as nanoseconds = " << ns.count() << '\n'; + ns += yr; + std::cout << "200 years expressed as nanoseconds = " << ns.count() << '\n'; + ns += yr; + std::cout << "300 years expressed as nanoseconds = " << ns.count() << '\n'; +// yr = ns; // does not compile + std::cout << "yr = ns; // does not compile\n"; +// picoseconds ps1 = yr; // does not compile, compile-time overflow in ratio arithmetic + std::cout << "ps = yr; // does not compile\n"; + ns = yr; + picoseconds ps = ns; + std::cout << "100 years expressed as picoseconds = " << ps.count() << '\n'; + ps = ns / sat(1000); + std::cout << "0.1 years expressed as picoseconds = " << ps.count() << '\n'; + yr = years(sat(-200000000)); + std::cout << "200 million years ago encoded in years: " << yr.count() << '\n'; + days d = boost::chrono::duration_cast(yr); + std::cout << "200 million years ago encoded in days: " << d.count() << '\n'; + millennium c = boost::chrono::duration_cast(yr); + std::cout << "200 million years ago encoded in millennium: " << c.count() << '\n'; + std::cout << "Demonstrate \"uninitialized protection\" behavior:\n"; + seconds sec; + for (++sec; sec < seconds(sat(10)); ++sec) + ; + std::cout << sec.count() << '\n'; + std::cout << "\n"; +} + +void testStdUser() +{ + std::cout << "***************\n"; + std::cout << "* testStdUser *\n"; + std::cout << "***************\n"; + using namespace boost::chrono; + hours hr = hours(100); + std::cout << "100 hours expressed as hours = " << hr.count() << '\n'; + nanoseconds ns = hr; + std::cout << "100 hours expressed as nanoseconds = " << ns.count() << '\n'; + ns += hr; + std::cout << "200 hours expressed as nanoseconds = " << ns.count() << '\n'; + ns += hr; + std::cout << "300 hours expressed as nanoseconds = " << ns.count() << '\n'; +// hr = ns; // does not compile + std::cout << "hr = ns; // does not compile\n"; +// hr * ns; // does not compile + std::cout << "hr * ns; // does not compile\n"; + duration fs(2.5); + std::cout << "duration has count() = " << fs.count() << '\n'; +// seconds sec = fs; // does not compile + std::cout << "seconds sec = duration won't compile\n"; + seconds sec = duration_cast(fs); + std::cout << "seconds has count() = " << sec.count() << '\n'; + std::cout << "\n"; +} + + +int main() +{ + testStdUser(); + testUser2(); + return 0; +} + diff --git a/src/boost/libs/chrono/example/simulated_thread_interface_demo.cpp b/src/boost/libs/chrono/example/simulated_thread_interface_demo.cpp new file mode 100644 index 000000000..81f2e86fe --- /dev/null +++ b/src/boost/libs/chrono/example/simulated_thread_interface_demo.cpp @@ -0,0 +1,198 @@ +// simulated_thread_interface_demo.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#define _CRT_SECURE_NO_WARNINGS // disable VC++ foolishness + +#include +#include + +#include +#include +#include +#include + +////////////////////////////////////////////////////////// +///////////// simulated thread interface ///////////////// +////////////////////////////////////////////////////////// + +namespace { +void print_time(boost::chrono::system_clock::time_point t) +{ + using namespace boost::chrono; + time_t c_time = system_clock::to_time_t(t); + std::tm* tmptr = std::localtime(&c_time); + system_clock::duration d = t.time_since_epoch(); + std::cout << tmptr->tm_hour << ':' << tmptr->tm_min << ':' << tmptr->tm_sec + << '.' << (d - duration_cast(d)).count(); +} +} + +namespace boost { +namespace this_thread { + +template +void sleep_for(const boost::chrono::duration& d) +{ + boost::chrono::microseconds t = boost::chrono::duration_cast(d); + if (t < d) + ++t; + if (t > boost::chrono::microseconds(0)) + std::cout << "sleep_for " << t.count() << " microseconds\n"; +} + +template +void sleep_until(const boost::chrono::time_point& t) +{ + using namespace boost::chrono; + typedef time_point Time; + typedef system_clock::time_point SysTime; + if (t > Clock::now()) + { + typedef typename boost::common_type::type D; + /* auto */ D d = t - Clock::now(); + microseconds us = duration_cast(d); + if (us < d) + ++us; + SysTime st = system_clock::now() + us; + std::cout << "sleep_until "; + ::print_time(st); + std::cout << " which is " << (st - system_clock::now()).count() << " microseconds away\n"; + } +} + +} // this_thread + +struct mutex {}; + +struct timed_mutex +{ + bool try_lock() {std::cout << "timed_mutex::try_lock()\n"; return true;} + + template + bool try_lock_for(const boost::chrono::duration& d) + { + boost::chrono::microseconds t = boost::chrono::duration_cast(d); + if (t <= boost::chrono::microseconds(0)) + return try_lock(); + std::cout << "try_lock_for " << t.count() << " microseconds\n"; + return true; + } + + template + bool try_lock_until(const boost::chrono::time_point& t) + { + using namespace boost::chrono; + typedef time_point Time; + typedef system_clock::time_point SysTime; + if (t <= Clock::now()) + return try_lock(); + typedef typename boost::common_type::type D; + /* auto */ D d = t - Clock::now(); + microseconds us = duration_cast(d); + SysTime st = system_clock::now() + us; + std::cout << "try_lock_until "; + ::print_time(st); + std::cout << " which is " << (st - system_clock::now()).count() + << " microseconds away\n"; + return true; + } +}; + +struct condition_variable +{ + template + bool wait_for(mutex&, const boost::chrono::duration& d) + { + boost::chrono::microseconds t = boost::chrono::duration_cast(d); + std::cout << "wait_for " << t.count() << " microseconds\n"; + return true; + } + + template + bool wait_until(mutex&, const boost::chrono::time_point& t) + { + using namespace boost::chrono; + typedef time_point Time; + typedef system_clock::time_point SysTime; + if (t <= Clock::now()) + return false; + typedef typename boost::common_type::type D; + /* auto */ D d = t - Clock::now(); + microseconds us = duration_cast(d); + SysTime st = system_clock::now() + us; + std::cout << "wait_until "; + ::print_time(st); + std::cout << " which is " << (st - system_clock::now()).count() + << " microseconds away\n"; + return true; + } +}; + +} + +////////////////////////////////////////////////////////// +//////////// Simple sleep and wait examples ////////////// +////////////////////////////////////////////////////////// + +boost::mutex m; +boost::timed_mutex mut; +boost::condition_variable cv; + +void basic_examples() +{ + std::cout << "Running basic examples\n"; + using namespace boost; + using namespace boost::chrono; + system_clock::time_point time_limit = system_clock::now() + seconds(4) + milliseconds(500); + this_thread::sleep_for(seconds(3)); + this_thread::sleep_for(nanoseconds(300)); + this_thread::sleep_until(time_limit); +// this_thread::sleep_for(time_limit); // desired compile-time error +// this_thread::sleep_until(seconds(3)); // desired compile-time error + mut.try_lock_for(milliseconds(30)); + mut.try_lock_until(time_limit); +// mut.try_lock_for(time_limit); // desired compile-time error +// mut.try_lock_until(milliseconds(30)); // desired compile-time error + cv.wait_for(m, minutes(1)); // real code would put this in a loop + cv.wait_until(m, time_limit); // real code would put this in a loop + // For those who prefer floating point + this_thread::sleep_for(duration(0.25)); + this_thread::sleep_until(system_clock::now() + duration(1.5)); +} + + + +int main() +{ + basic_examples(); + return 0; +} + diff --git a/src/boost/libs/chrono/example/test_clock.cpp b/src/boost/libs/chrono/example/test_clock.cpp new file mode 100644 index 000000000..ffb945863 --- /dev/null +++ b/src/boost/libs/chrono/example/test_clock.cpp @@ -0,0 +1,182 @@ +// test_system_clock.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#include +#include + +#include + +#include "clock_name.hpp" + +#if defined(BOOST_NO_CXX11_CONSTEXPR) + +using namespace boost::chrono; + +template +void test_clock() +{ + std::cout << "\n"<< name::apply() << " test" << std::endl; +{ + typename Clock::duration delay = milliseconds(5); + typename Clock::time_point start = Clock::now(); + while (Clock::now() - start <= delay) + ; + typename Clock::time_point stop = Clock::now(); + //typename Clock::duration elapsed = stop - start; + std::cout << "5 milliseconds paused " << nanoseconds(stop - start).count() << " nanoseconds\n"; +} +{ + typename Clock::time_point start = Clock::now(); + typename Clock::time_point stop; + std::size_t counter=1; + while ((stop=Clock::now()) == start) { + ++counter; + } + //typename Clock::duration elapsed = stop - start; + std::cout << "After " << counter << " trials, elapsed time " << nanoseconds(stop - start).count() << " nanoseconds\n"; + + start = Clock::now(); + for (std::size_t c=counter; c>0; --c) { + stop=Clock::now();; + } + std::cout << "After " << counter << " trials, elapsed time " << nanoseconds(stop - start).count() << " nanoseconds\n"; + + +} +{ + typename Clock::time_point start = Clock::now(); + typename Clock::time_point stop = Clock::now(); + std::cout << "Resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n"; +} +} + +void test_system_clock() +{ + std::cout << "system_clock test" << std::endl; + system_clock::duration delay = milliseconds(5); + system_clock::time_point start = system_clock::now(); + while (system_clock::now() - start <= delay) + ; + system_clock::time_point stop = system_clock::now(); + system_clock::duration elapsed = stop - start; + std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; + start = system_clock::now(); + stop = system_clock::now(); + std::cout << "system_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n"; +} + +void test_steady_clock() +{ +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + std::cout << "steady_clock test" << std::endl; + steady_clock::duration delay = milliseconds(5); + steady_clock::time_point start = steady_clock::now(); + while (steady_clock::now() - start <= delay) + ; + steady_clock::time_point stop = steady_clock::now(); + steady_clock::duration elapsed = stop - start; + std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; + start = steady_clock::now(); + stop = steady_clock::now(); + std::cout << "steady_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n"; +#endif +} +void test_hi_resolution_clock() +{ + std::cout << "high_resolution_clock test" << std::endl; + high_resolution_clock::duration delay = milliseconds(5); + high_resolution_clock::time_point start = high_resolution_clock::now(); + while (high_resolution_clock::now() - start <= delay) + ; + high_resolution_clock::time_point stop = high_resolution_clock::now(); + high_resolution_clock::duration elapsed = stop - start; + std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; + start = high_resolution_clock::now(); + stop = high_resolution_clock::now(); + std::cout << "high_resolution_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n"; +} + +//void test_mixed_clock() +//{ +// std::cout << "mixed clock test" << std::endl; +// high_resolution_clock::time_point hstart = high_resolution_clock::now(); +// std::cout << "Add 5 milliseconds to a high_resolution_clock::time_point\n"; +// steady_clock::time_point mend = hstart + milliseconds(5); +// bool b = hstart == mend; +// system_clock::time_point sstart = system_clock::now(); +// std::cout << "Subtracting system_clock::time_point from steady_clock::time_point doesn't compile\n"; +//// mend - sstart; // doesn't compile +// std::cout << "subtract high_resolution_clock::time_point from steady_clock::time_point" +// " and add that to a system_clock::time_point\n"; +// system_clock::time_point send = sstart + duration_cast(mend - hstart); +// std::cout << "subtract two system_clock::time_point's and output that in microseconds:\n"; +// microseconds ms = send - sstart; +// std::cout << ms.count() << " microseconds\n"; +//} +// +//void test_c_mapping() +//{ +// std::cout << "C map test\n"; +// using namespace boost::chrono; +// system_clock::time_point t1 = system_clock::now(); +// std::time_t c_time = system_clock::to_time_t(t1); +// std::tm* tmptr = std::localtime(&c_time); +// std::cout << "It is now " << tmptr->tm_hour << ':' << tmptr->tm_min << ':' << tmptr->tm_sec << ' ' +// << tmptr->tm_year + 1900 << '-' << tmptr->tm_mon + 1 << '-' << tmptr->tm_mday << '\n'; +// c_time = std::mktime(tmptr); +// system_clock::time_point t2 = system_clock::from_time_t(c_time); +// microseconds ms = t1 - t2; +// std::cout << "Round-tripping through the C interface truncated the precision by " << ms.count() << " microseconds\n"; +//} + + +int main() +{ + test_system_clock(); + test_steady_clock(); + test_hi_resolution_clock(); + //test_mixed_clock(); + test_clock(); +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + test_clock(); +#endif + test_clock(); + + + + return 0; +} + +#else +int main() +{ + + + return 0; +} +#endif diff --git a/src/boost/libs/chrono/example/test_clock2.cpp b/src/boost/libs/chrono/example/test_clock2.cpp new file mode 100644 index 000000000..a65586215 --- /dev/null +++ b/src/boost/libs/chrono/example/test_clock2.cpp @@ -0,0 +1,210 @@ +// test_system_clock.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#include +#include + +#include + +#include "clock_name.hpp" + +namespace boost { + namespace detail_chrono { + class steady_clock {}; + class system_clock {}; + } + namespace chrono { + namespace chrono_detail { + using namespace detail_chrono; + struct has_steady_clock { + template< class T > static char sfinae( typename T::rep ); + template< class > static int sfinae( ... ); + + enum { value = sizeof sfinae< steady_clock >( 0 ) == sizeof(char) }; + }; + struct has_system_clock { + template< class T > static char sfinae( typename T::rep ); + template< class > static int sfinae( ... ); + + enum { value = sizeof sfinae< system_clock >( 0 ) == sizeof(char) }; + }; + } + struct has_steady_clock + : integral_constant {}; + struct has_system_clock + : integral_constant {}; + } + +} + +BOOST_STATIC_ASSERT(boost::chrono::has_system_clock::value); +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY +BOOST_STATIC_ASSERT(boost::chrono::has_steady_clock::value); +#else +BOOST_STATIC_ASSERT(!boost::chrono::has_steady_clock::value); +#endif + +using namespace boost::chrono; +using namespace boost; + +template +void test_clock() +{ + std::cout << "\n"<< name::apply() << " test" << std::endl; +{ + typename Clock::duration delay = milliseconds(5); + typename Clock::time_point start = Clock::now(); + while (Clock::now() - start <= delay) + ; + typename Clock::time_point stop = Clock::now(); + //typename Clock::duration elapsed = stop - start; + std::cout << "5 milliseconds paused " << nanoseconds(stop - start).count() << " nanoseconds\n"; +} +{ + typename Clock::time_point start = Clock::now(); + typename Clock::time_point stop; + std::size_t count=1; + while ((stop=Clock::now()) == start) { + ++count; + } + //typename Clock::duration elapsed = stop - start; + std::cout << "After " << count << " trials, elapsed time " << nanoseconds(stop - start).count() << " nanoseconds\n"; + + start = Clock::now(); + for (std::size_t c=count; c>0; --c) { + stop=Clock::now();; + } + std::cout << "After " << count << " trials, elapsed time " << nanoseconds(stop - start).count() << " nanoseconds\n"; + + +} +{ + typename Clock::time_point start = Clock::now(); + typename Clock::time_point stop = Clock::now(); + std::cout << "Resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n"; +} +} + +void test_system_clock() +{ + std::cout << "system_clock test" << std::endl; + //~ system_clock clk; + chrono::system_clock::duration delay = milliseconds(5); + chrono::system_clock::time_point start = system_clock::now(); + while (chrono::system_clock::now() - start <= delay) + ; + chrono::system_clock::time_point stop = system_clock::now(); + chrono::system_clock::duration elapsed = stop - start; + std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; + start = chrono::system_clock::now(); + stop = chrono::system_clock::now(); + std::cout << "system_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n"; +} + +void test_steady_clock() +{ +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + std::cout << "steady_clock test" << std::endl; + steady_clock::duration delay = milliseconds(5); + steady_clock::time_point start = steady_clock::now(); + while (steady_clock::now() - start <= delay) + ; + steady_clock::time_point stop = steady_clock::now(); + steady_clock::duration elapsed = stop - start; + std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; + start = steady_clock::now(); + stop = steady_clock::now(); + std::cout << "steady_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n"; +#endif +} +void test_hi_resolution_clock() +{ + std::cout << "high_resolution_clock test" << std::endl; + high_resolution_clock::duration delay = milliseconds(5); + high_resolution_clock::time_point start = high_resolution_clock::now(); + while (high_resolution_clock::now() - start <= delay) + ; + high_resolution_clock::time_point stop = high_resolution_clock::now(); + high_resolution_clock::duration elapsed = stop - start; + std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; + start = high_resolution_clock::now(); + stop = high_resolution_clock::now(); + std::cout << "high_resolution_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n"; +} + +//void test_mixed_clock() +//{ +// std::cout << "mixed clock test" << std::endl; +// high_resolution_clock::time_point hstart = high_resolution_clock::now(); +// std::cout << "Add 5 milliseconds to a high_resolution_clock::time_point\n"; +// steady_clock::time_point mend = hstart + milliseconds(5); +// bool b = hstart == mend; +// system_clock::time_point sstart = system_clock::now(); +// std::cout << "Subtracting system_clock::time_point from steady_clock::time_point doesn't compile\n"; +//// mend - sstart; // doesn't compile +// std::cout << "subtract high_resolution_clock::time_point from steady_clock::time_point" +// " and add that to a system_clock::time_point\n"; +// system_clock::time_point send = sstart + duration_cast(mend - hstart); +// std::cout << "subtract two system_clock::time_point's and output that in microseconds:\n"; +// microseconds ms = send - sstart; +// std::cout << ms.count() << " microseconds\n"; +//} +// +//void test_c_mapping() +//{ +// std::cout << "C map test\n"; +// using namespace boost::chrono; +// system_clock::time_point t1 = system_clock::now(); +// std::time_t c_time = system_clock::to_time_t(t1); +// std::tm* tmptr = std::localtime(&c_time); +// std::cout << "It is now " << tmptr->tm_hour << ':' << tmptr->tm_min << ':' << tmptr->tm_sec << ' ' +// << tmptr->tm_year + 1900 << '-' << tmptr->tm_mon + 1 << '-' << tmptr->tm_mday << '\n'; +// c_time = std::mktime(tmptr); +// system_clock::time_point t2 = system_clock::from_time_t(c_time); +// microseconds ms = t1 - t2; +// std::cout << "Round-tripping through the C interface truncated the precision by " << ms.count() << " microseconds\n"; +//} + + +int main() +{ + test_system_clock(); + test_steady_clock(); + test_hi_resolution_clock(); + //test_mixed_clock(); + test_clock(); +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + test_clock(); +#endif + test_clock(); + + + + return 0; +} + diff --git a/src/boost/libs/chrono/example/test_duration.cpp b/src/boost/libs/chrono/example/test_duration.cpp new file mode 100644 index 000000000..71489065a --- /dev/null +++ b/src/boost/libs/chrono/example/test_duration.cpp @@ -0,0 +1,203 @@ +// test_duration.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#include +#include +#include + +#include + +template +void inspect_duration(boost::chrono::duration d, const std::string& name) +{ + typedef boost::chrono::duration Duration; + std::cout << "********* " << name << " *********\n"; + std::cout << "The period of " << name << " is " << (double)Period::num/Period::den << " seconds.\n"; + std::cout << "The frequency of " << name << " is " << (double)Period::den/Period::num << " Hz.\n"; + std::cout << "The representation is "; + if (boost::is_floating_point::value) + { + std::cout << "floating point\n"; + std::cout << "The precision is the most significant "; + std::cout << std::numeric_limits::digits10 << " decimal digits.\n"; + } + else if (boost::is_integral::value) + { + std::cout << "integral\n"; + d = Duration(Rep(1)); + boost::chrono::duration dsec = d; + std::cout << "The precision is " << dsec.count() << " seconds.\n"; + } + else + { + std::cout << "a class type\n"; + d = Duration(Rep(1)); + boost::chrono::duration dsec = d; + std::cout << "The precision is " << dsec.count() << " seconds.\n"; + } + d = Duration((std::numeric_limits::max)()); + using namespace boost::chrono; + typedef duration, hours::period>::type> Years; + Years years = d; + std::cout << "The range is +/- " << years.count() << " years.\n"; + std::cout << "sizeof(" << name << ") = " << sizeof(d) << '\n'; +} + +void inspect_all() +{ + using namespace boost::chrono; + std::cout.precision(6); + inspect_duration(nanoseconds(), "nanoseconds"); + inspect_duration(microseconds(), "microseconds"); + inspect_duration(milliseconds(), "milliseconds"); + inspect_duration(seconds(), "seconds"); + inspect_duration(minutes(), "minutes"); + inspect_duration(hours(), "hours"); + inspect_duration(duration(), "duration"); +} + + + +using namespace boost::chrono; +void test_duration_division() +{ + typedef boost::common_type::type h_min_rep; + h_min_rep r3 = hours(3) / minutes(5); + std::cout << r3 << '\n'; + std::cout << hours(3) / minutes(5) << '\n'; + std::cout << hours(3) / milliseconds(5) << '\n'; + std::cout << milliseconds(5) / hours(3) << '\n'; + std::cout << hours(1) / milliseconds(1) << '\n'; +} + +void test_duration_multiply() +{ + hours h15= 5 * hours(3); + (void)h15; + hours h6= hours(3) *2; + (void)h6; +} + +void f(duration d, double res) // accept floating point seconds +{ + // d.count() == 3.e-6 when passed microseconds(3) + BOOST_ASSERT(d.count()==res); +} + +void g(nanoseconds d, boost::intmax_t res) +{ + // d.count() == 3000 when passed microseconds(3) + std::cout << d.count() << " " < +void tmpl(duration d, boost::intmax_t res) +{ + // convert d to nanoseconds, rounding up if it is not an exact conversion + nanoseconds ns = duration_cast(d); + if (ns < d) + ++ns; + // ns.count() == 333333334 when passed 1/3 of a floating point second + BOOST_ASSERT(ns.count()==res); +} + +template +void tmpl2(duration d, boost::intmax_t res) +{ + // convert d to nanoseconds, rounding up if it is not an exact conversion + nanoseconds ns = duration_cast(d); + if (ns < d) + ++ns; + // ns.count() == 333333334 when passed 333333333333 picoseconds + BOOST_ASSERT(ns.count()==res); +} + + + +int main() +{ + minutes m1(3); // m1 stores 3 + minutes m2(2); // m2 stores 2 + minutes m3 = m1 + m2; // m3 stores 5 + BOOST_ASSERT(m3.count()==5); + + microseconds us1(3); // us1 stores 3 + microseconds us2(2); // us2 stores 2 + microseconds us3 = us1 + us2; // us3 stores 5 + BOOST_ASSERT(us3.count()==5); + + microseconds us4 = m3 + us3; // us4 stores 300000005 + BOOST_ASSERT(us4.count()==300000005); + microseconds us5 = m3; // us4 stores 300000000 + BOOST_ASSERT(us5.count()==300000000); + + //minutes m4 = m3 + us3; // won't compile + + minutes m4 = duration_cast(m3 + us3); // m4.count() == 5 + BOOST_ASSERT(m4.count()==5); + + typedef duration > dminutes; + dminutes dm4 = m3 + us3; // dm4.count() == 5.000000083333333 + BOOST_ASSERT(dm4.count()==5.000000083333333); + + f(microseconds(3), 0.000003); + g(microseconds(3), 3000); + duration s(1./3); // 1/3 of a second + g(duration_cast(s), 333333333); // round towards zero in conversion to nanoseconds + //f(s); // does not compile + tmpl(duration(1./3), 333333334); + tmpl2(duration(333333333333LL), 333333334); // About 1/3 of a second worth of picoseconds + + //f(3,3); // Will not compile, 3 is not implicitly convertible to any `duration` + //g(3,3); // Will not compile, 3 is not implicitly convertible to any `duration` + //tmpl(3,3); // Will not compile, 3 is not implicitly convertible to any `duration` + //tmpl2(3,3); // Will not compile, 3 is not implicitly convertible to any `duration` + + { + double r = double(milliseconds(3) / milliseconds(3)); + std::cout << r << '\n'; + + duration d = milliseconds(3) * 2.5; + duration d2 = 2.5 * milliseconds(3) ; + (void)d2; + duration d3 = milliseconds(3) / 2.5; + (void)d3; + duration d4 = milliseconds(3) + milliseconds(5) ; + (void)d4; + inspect_duration(milliseconds(3) * 2.5, "milliseconds(3) * 2.5"); + std::cout << d.count() << '\n'; +// milliseconds ms(3.5); // doesn't compile + std::cout << "milliseconds ms(3.5) doesn't compile\n"; + } + + test_duration_division(); + test_duration_multiply(); + return 0; +} + diff --git a/src/boost/libs/chrono/example/test_minmax.cpp b/src/boost/libs/chrono/example/test_minmax.cpp new file mode 100644 index 000000000..a4eca7f64 --- /dev/null +++ b/src/boost/libs/chrono/example/test_minmax.cpp @@ -0,0 +1,17 @@ +// test_duration.cpp ----------------------------------------------------------// + +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#if !defined(__GNUC__) + +#define min(A,B) ((A)<(B)?(A):(B)) +#define max(A,B) ((A)>(B)?(A):(B)) + +#include + +#endif + + diff --git a/src/boost/libs/chrono/example/test_special_values.cpp b/src/boost/libs/chrono/example/test_special_values.cpp new file mode 100644 index 000000000..dcda2a769 --- /dev/null +++ b/src/boost/libs/chrono/example/test_special_values.cpp @@ -0,0 +1,51 @@ +// test_special_values.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#include +#include + +#include + +using namespace boost::chrono; + +void test_special_values() +{ + std::cout << "duration::min().count() = " << ((duration::min)()).count() << '\n'; + std::cout << "duration::zero().count() = " << duration::zero().count() << '\n'; + std::cout << "duration::max().count() = " << ((duration::max)()).count() << '\n'; + std::cout << "duration::min().count() = " << ((duration::min)()).count() << '\n'; + std::cout << "duration::zero().count() = " << duration::zero().count() << '\n'; + std::cout << "duration::max().count() = " << ((duration::max)()).count() << '\n'; +} + +int main() +{ + test_special_values(); + return 0; +} + diff --git a/src/boost/libs/chrono/example/test_thread_clock.cpp b/src/boost/libs/chrono/example/test_thread_clock.cpp new file mode 100644 index 000000000..2bc7610ec --- /dev/null +++ b/src/boost/libs/chrono/example/test_thread_clock.cpp @@ -0,0 +1,42 @@ +// test_thread_clock.cpp ----------------------------------------------------------// + +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + + +#include +#include + +#include + + +void test_thread_clock() +{ +#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) + using namespace boost::chrono; + + std::cout << "thread_clock test" << std::endl; + thread_clock::duration delay = milliseconds(5); + thread_clock::time_point start = thread_clock::now(); + while (thread_clock::now() - start <= delay) + ; + thread_clock::time_point stop = thread_clock::now(); + thread_clock::duration elapsed = stop - start; + std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; + start = thread_clock::now(); + stop = thread_clock::now(); + std::cout << "thread_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n"; +#else + std::cout << "thread_clock not available\n"; +#endif +} + + +int main() +{ + test_thread_clock(); + return 0; +} + diff --git a/src/boost/libs/chrono/example/time2_demo.cpp b/src/boost/libs/chrono/example/time2_demo.cpp new file mode 100644 index 000000000..35d93b7be --- /dev/null +++ b/src/boost/libs/chrono/example/time2_demo.cpp @@ -0,0 +1,1655 @@ +// time2_demo.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* + +This code was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#define _CRT_SECURE_NO_WARNINGS // disable VC++ foolishness + +#include +#include + +#include +#include +#include +#include +#include + +#include + +namespace +{ + //struct timeval { + // long tv_sec; /* seconds */ + // long tv_usec; /* and microseconds */ + //}; + + int gettimeofday(struct timeval * tp, void *) + { + FILETIME ft; + ::GetSystemTimeAsFileTime( &ft ); // never fails + long long t = (static_cast(ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + # if !defined( BOOST_MSVC ) || BOOST_MSVC > 1300 // > VC++ 7.0 + t -= 116444736000000000LL; + # else + t -= 116444736000000000; + # endif + t /= 10; // microseconds + tp->tv_sec = static_cast( t / 1000000UL); + tp->tv_usec = static_cast( t % 1000000UL); + return 0; + } +} // unnamed namespace + +////////////////////////////////////////////////////////// +///////////// simulated thread interface ///////////////// +////////////////////////////////////////////////////////// + + +namespace std { + +void __print_time(boost::chrono::system_clock::time_point t) +{ + using namespace boost::chrono; + time_t c_time = system_clock::to_time_t(t); + std::tm* tmptr = std::localtime(&c_time); + system_clock::duration d = t.time_since_epoch(); + std::cout << tmptr->tm_hour << ':' << tmptr->tm_min << ':' << tmptr->tm_sec + << '.' << (d - duration_cast(d)).count(); +} + +namespace this_thread { + +template +void sleep_for(const boost::chrono::duration& d) +{ + boost::chrono::microseconds t = boost::chrono::duration_cast(d); + if (t < d) + ++t; + if (t > boost::chrono::microseconds(0)) + std::cout << "sleep_for " << t.count() << " microseconds\n"; +} + +template +void sleep_until(const boost::chrono::time_point& t) +{ + using namespace boost::chrono; + typedef time_point Time; + typedef system_clock::time_point SysTime; + if (t > Clock::now()) + { + typedef typename boost::common_type::type D; + /* auto */ D d = t - Clock::now(); + microseconds us = duration_cast(d); + if (us < d) + ++us; + SysTime st = system_clock::now() + us; + std::cout << "sleep_until "; + __print_time(st); + std::cout << " which is " << (st - system_clock::now()).count() << " microseconds away\n"; + } +} + +} // this_thread + +struct mutex {}; + +struct timed_mutex +{ + bool try_lock() {std::cout << "timed_mutex::try_lock()\n"; return true;} + + template + bool try_lock_for(const boost::chrono::duration& d) + { + boost::chrono::microseconds t = boost::chrono::duration_cast(d); + if (t <= boost::chrono::microseconds(0)) + return try_lock(); + std::cout << "try_lock_for " << t.count() << " microseconds\n"; + return true; + } + + template + bool try_lock_until(const boost::chrono::time_point& t) + { + using namespace boost::chrono; + typedef time_point Time; + typedef system_clock::time_point SysTime; + if (t <= Clock::now()) + return try_lock(); + typedef typename boost::common_type::type D; + /* auto */ D d = t - Clock::now(); + microseconds us = duration_cast(d); + SysTime st = system_clock::now() + us; + std::cout << "try_lock_until "; + __print_time(st); + std::cout << " which is " << (st - system_clock::now()).count() + << " microseconds away\n"; + return true; + } +}; + +struct condition_variable +{ + template + bool wait_for(mutex&, const boost::chrono::duration& d) + { + boost::chrono::microseconds t = boost::chrono::duration_cast(d); + std::cout << "wait_for " << t.count() << " microseconds\n"; + return true; + } + + template + bool wait_until(mutex&, const boost::chrono::time_point& t) + { + using namespace boost::chrono; + typedef time_point Time; + typedef system_clock::time_point SysTime; + if (t <= Clock::now()) + return false; + typedef typename boost::common_type::type D; + /* auto */ D d = t - Clock::now(); + microseconds us = duration_cast(d); + SysTime st = system_clock::now() + us; + std::cout << "wait_until "; + __print_time(st); + std::cout << " which is " << (st - system_clock::now()).count() + << " microseconds away\n"; + return true; + } +}; + +} // namespace std + +////////////////////////////////////////////////////////// +//////////// Simple sleep and wait examples ////////////// +////////////////////////////////////////////////////////// + +std::mutex m; +std::timed_mutex mut; +std::condition_variable cv; + +void basic_examples() +{ + std::cout << "Running basic examples\n"; + using namespace std; + using namespace boost::chrono; + system_clock::time_point time_limit = system_clock::now() + seconds(4) + milliseconds(500); + this_thread::sleep_for(seconds(3)); + this_thread::sleep_for(nanoseconds(300)); + this_thread::sleep_until(time_limit); +// this_thread::sleep_for(time_limit); // desired compile-time error +// this_thread::sleep_until(seconds(3)); // desired compile-time error + mut.try_lock_for(milliseconds(30)); + mut.try_lock_until(time_limit); +// mut.try_lock_for(time_limit); // desired compile-time error +// mut.try_lock_until(milliseconds(30)); // desired compile-time error + cv.wait_for(m, minutes(1)); // real code would put this in a loop + cv.wait_until(m, time_limit); // real code would put this in a loop + // For those who prefer floating point + this_thread::sleep_for(duration(0.25)); + this_thread::sleep_until(system_clock::now() + duration(1.5)); +} + +////////////////////////////////////////////////////////// +//////////////////// User1 Example /////////////////////// +////////////////////////////////////////////////////////// + +namespace User1 +{ +// Example type-safe "physics" code interoperating with boost::chrono::duration types +// and taking advantage of the boost::ratio infrastructure and design philosophy. + +// length - mimics boost::chrono::duration except restricts representation to double. +// Uses boost::ratio facilities for length units conversions. + +template +class length +{ +public: + typedef Ratio ratio; +private: + double len_; +public: + + length() : len_(1) {} + length(const double& len) : len_(len) {} + + // conversions + template + length(const length& d) + : len_(d.count() * boost::ratio_divide::type::den / + boost::ratio_divide::type::num) {} + + // observer + + double count() const {return len_;} + + // arithmetic + + length& operator+=(const length& d) {len_ += d.count(); return *this;} + length& operator-=(const length& d) {len_ -= d.count(); return *this;} + + length operator+() const {return *this;} + length operator-() const {return length(-len_);} + + length& operator*=(double rhs) {len_ *= rhs; return *this;} + length& operator/=(double rhs) {len_ /= rhs; return *this;} +}; + +// Sparse sampling of length units +typedef length > meter; // set meter as "unity" +typedef length centimeter; // 1/100 meter +typedef length kilometer; // 1000 meters +typedef length > inch; // 254/10000 meters +// length takes ratio instead of two integral types so that definitions can be made like so: +typedef length, inch::ratio>::type> foot; // 12 inchs +typedef length, foot::ratio>::type> mile; // 5280 feet + +// Need a floating point definition of seconds +typedef boost::chrono::duration seconds; // unity +// Demo of (scientific) support for sub-nanosecond resolutions +typedef boost::chrono::duration picosecond; // 10^-12 seconds +typedef boost::chrono::duration femtosecond; // 10^-15 seconds +typedef boost::chrono::duration attosecond; // 10^-18 seconds + +// A very brief proof-of-concept for SIUnits-like library +// Hard-wired to floating point seconds and meters, but accepts other units (shown in testUser1()) +template +class quantity +{ + double q_; +public: + quantity() : q_(1) {} + + double get() const {return q_;} + void set(double q) {q_ = q;} +}; + +template <> +class quantity, boost::ratio<0> > +{ + double q_; +public: + quantity() : q_(1) {} + quantity(seconds d) : q_(d.count()) {} // note: only User1::seconds needed here + + double get() const {return q_;} + void set(double q) {q_ = q;} +}; + +template <> +class quantity, boost::ratio<1> > +{ + double q_; +public: + quantity() : q_(1) {} + quantity(meter d) : q_(d.count()) {} // note: only User1::meter needed here + + double get() const {return q_;} + void set(double q) {q_ = q;} +}; + +template <> +class quantity, boost::ratio<0> > +{ + double q_; +public: + quantity() : q_(1) {} + quantity(double d) : q_(d) {} + + double get() const {return q_;} + void set(double q) {q_ = q;} +}; + +// Example SI-Units +typedef quantity, boost::ratio<0> > Scalar; +typedef quantity, boost::ratio<0> > Time; // second +typedef quantity, boost::ratio<1> > Distance; // meter +typedef quantity, boost::ratio<1> > Speed; // meter/second +typedef quantity, boost::ratio<1> > Acceleration; // meter/second^2 + +template +quantity::type, typename boost::ratio_subtract::type> +operator/(const quantity& x, const quantity& y) +{ + typedef quantity::type, typename boost::ratio_subtract::type> R; + R r; + r.set(x.get() / y.get()); + return r; +} + +template +quantity::type, typename boost::ratio_add::type> +operator*(const quantity& x, const quantity& y) +{ + typedef quantity::type, typename boost::ratio_add::type> R; + R r; + r.set(x.get() * y.get()); + return r; +} + +template +quantity +operator+(const quantity& x, const quantity& y) +{ + typedef quantity R; + R r; + r.set(x.get() + y.get()); + return r; +} + +template +quantity +operator-(const quantity& x, const quantity& y) +{ + typedef quantity R; + R r; + r.set(x.get() - y.get()); + return r; +} + +// Example type-safe physics function +Distance +compute_distance(Speed v0, Time t, Acceleration a) +{ + return v0 * t + Scalar(.5) * a * t * t; // if a units mistake is made here it won't compile +} + +} // User1 + + +// Exercise example type-safe physics function and show interoperation +// of custom time durations (User1::seconds) and standard time durations (std::hours). +// Though input can be arbitrary (but type-safe) units, output is always in SI-units +// (a limitation of the simplified Units lib demoed here). +void testUser1() +{ + std::cout << "*************\n"; + std::cout << "* testUser1 *\n"; + std::cout << "*************\n"; + User1::Distance d( User1::mile(110) ); + User1::Time t( boost::chrono::hours(2) ); + User1::Speed s = d / t; + std::cout << "Speed = " << s.get() << " meters/sec\n"; + User1::Acceleration a = User1::Distance( User1::foot(32.2) ) / User1::Time() / User1::Time(); + std::cout << "Acceleration = " << a.get() << " meters/sec^2\n"; + User1::Distance df = compute_distance(s, User1::Time( User1::seconds(0.5) ), a); + std::cout << "Distance = " << df.get() << " meters\n"; + std::cout << "There are " << User1::mile::ratio::den << '/' << User1::mile::ratio::num << " miles/meter"; + User1::meter mt = 1; + User1::mile mi = mt; + std::cout << " which is approximately " << mi.count() << '\n'; + std::cout << "There are " << User1::mile::ratio::num << '/' << User1::mile::ratio::den << " meters/mile"; + mi = 1; + mt = mi; + std::cout << " which is approximately " << mt.count() << '\n'; + User1::attosecond as(1); + User1::seconds sec = as; + std::cout << "1 attosecond is " << sec.count() << " seconds\n"; + std::cout << "sec = as; // compiles\n"; + sec = User1::seconds(1); + as = sec; + std::cout << "1 second is " << as.count() << " attoseconds\n"; + std::cout << "as = sec; // compiles\n"; + std::cout << "\n"; +} + +////////////////////////////////////////////////////////// +//////////////////// User2 Example /////////////////////// +////////////////////////////////////////////////////////// + +// Demonstrate User2: +// A "saturating" signed integral type is developed. This type has +/- infinity and a nan +// (like IEEE floating point) but otherwise obeys signed integral arithmetic. +// This class is subsequently used as the rep in boost::chrono::duration to demonstrate a +// duration class that does not silently ignore overflow. + +namespace User2 +{ + +template +class saturate +{ +public: + typedef I int_type; + + static const int_type nan = int_type(int_type(1) << (sizeof(int_type) * CHAR_BIT - 1)); + static const int_type neg_inf = nan + 1; + static const int_type pos_inf = -neg_inf; +private: + int_type i_; + +// static_assert(std::is_integral::value && std::is_signed::value, +// "saturate only accepts signed integral types"); +// static_assert(nan == -nan && neg_inf < pos_inf, +// "saturate assumes two's complement hardware for signed integrals"); + +public: + saturate() : i_(nan) {} + explicit saturate(int_type i) : i_(i) {} + // explicit + operator int_type() const; + + saturate& operator+=(saturate x); + saturate& operator-=(saturate x) {return *this += -x;} + saturate& operator*=(saturate x); + saturate& operator/=(saturate x); + saturate& operator%=(saturate x); + + saturate operator- () const {return saturate(-i_);} + saturate& operator++() {*this += saturate(int_type(1)); return *this;} + saturate operator++(int) {saturate tmp(*this); ++(*this); return tmp;} + saturate& operator--() {*this -= saturate(int_type(1)); return *this;} + saturate operator--(int) {saturate tmp(*this); --(*this); return tmp;} + + friend saturate operator+(saturate x, saturate y) {return x += y;} + friend saturate operator-(saturate x, saturate y) {return x -= y;} + friend saturate operator*(saturate x, saturate y) {return x *= y;} + friend saturate operator/(saturate x, saturate y) {return x /= y;} + friend saturate operator%(saturate x, saturate y) {return x %= y;} + + friend bool operator==(saturate x, saturate y) + { + if (x.i_ == nan || y.i_ == nan) + return false; + return x.i_ == y.i_; + } + + friend bool operator!=(saturate x, saturate y) {return !(x == y);} + + friend bool operator<(saturate x, saturate y) + { + if (x.i_ == nan || y.i_ == nan) + return false; + return x.i_ < y.i_; + } + + friend bool operator<=(saturate x, saturate y) + { + if (x.i_ == nan || y.i_ == nan) + return false; + return x.i_ <= y.i_; + } + + friend bool operator>(saturate x, saturate y) + { + if (x.i_ == nan || y.i_ == nan) + return false; + return x.i_ > y.i_; + } + + friend bool operator>=(saturate x, saturate y) + { + if (x.i_ == nan || y.i_ == nan) + return false; + return x.i_ >= y.i_; + } + + friend std::ostream& operator<<(std::ostream& os, saturate s) + { + switch (s.i_) + { + case pos_inf: + return os << "inf"; + case nan: + return os << "nan"; + case neg_inf: + return os << "-inf"; + }; + return os << s.i_; + } +}; + +template +saturate::operator int_type() const +{ + switch (i_) + { + case nan: + case neg_inf: + case pos_inf: + throw std::out_of_range("saturate special value can not convert to int_type"); + } + return i_; +} + +template +saturate& +saturate::operator+=(saturate x) +{ + switch (i_) + { + case pos_inf: + switch (x.i_) + { + case neg_inf: + case nan: + i_ = nan; + } + return *this; + case nan: + return *this; + case neg_inf: + switch (x.i_) + { + case pos_inf: + case nan: + i_ = nan; + } + return *this; + } + switch (x.i_) + { + case pos_inf: + case neg_inf: + case nan: + i_ = x.i_; + return *this; + } + if (x.i_ >= 0) + { + if (i_ < pos_inf - x.i_) + i_ += x.i_; + else + i_ = pos_inf; + return *this; + } + if (i_ > neg_inf - x.i_) + i_ += x.i_; + else + i_ = neg_inf; + return *this; +} + +template +saturate& +saturate::operator*=(saturate x) +{ + switch (i_) + { + case 0: + switch (x.i_) + { + case pos_inf: + case neg_inf: + case nan: + i_ = nan; + } + return *this; + case pos_inf: + switch (x.i_) + { + case nan: + case 0: + i_ = nan; + return *this; + } + if (x.i_ < 0) + i_ = neg_inf; + return *this; + case nan: + return *this; + case neg_inf: + switch (x.i_) + { + case nan: + case 0: + i_ = nan; + return *this; + } + if (x.i_ < 0) + i_ = pos_inf; + return *this; + } + switch (x.i_) + { + case 0: + i_ = 0; + return *this; + case nan: + i_ = nan; + return *this; + case pos_inf: + if (i_ < 0) + i_ = neg_inf; + else + i_ = pos_inf; + return *this; + case neg_inf: + if (i_ < 0) + i_ = pos_inf; + else + i_ = neg_inf; + return *this; + } + int s = (i_ < 0 ? -1 : 1) * (x.i_ < 0 ? -1 : 1); + i_ = i_ < 0 ? -i_ : i_; + int_type x_i_ = x.i_ < 0 ? -x.i_ : x.i_; + if (i_ <= pos_inf / x_i_) + i_ *= x_i_; + else + i_ = pos_inf; + i_ *= s; + return *this; +} + +template +saturate& +saturate::operator/=(saturate x) +{ + switch (x.i_) + { + case pos_inf: + case neg_inf: + switch (i_) + { + case pos_inf: + case neg_inf: + case nan: + i_ = nan; + break; + default: + i_ = 0; + break; + } + return *this; + case nan: + i_ = nan; + return *this; + case 0: + switch (i_) + { + case pos_inf: + case neg_inf: + case nan: + return *this; + case 0: + i_ = nan; + return *this; + } + if (i_ > 0) + i_ = pos_inf; + else + i_ = neg_inf; + return *this; + } + switch (i_) + { + case 0: + case nan: + return *this; + case pos_inf: + case neg_inf: + if (x.i_ < 0) + i_ = -i_; + return *this; + } + i_ /= x.i_; + return *this; +} + +template +saturate& +saturate::operator%=(saturate x) +{ +// *this -= *this / x * x; // definition + switch (x.i_) + { + case nan: + case neg_inf: + case 0: + case pos_inf: + i_ = nan; + return *this; + } + switch (i_) + { + case neg_inf: + case pos_inf: + i_ = nan; + case nan: + return *this; + } + i_ %= x.i_; + return *this; +} + +// Demo overflow-safe integral durations ranging from picoseconds resolution to millennium resolution +typedef boost::chrono::duration, boost::pico > picoseconds; +typedef boost::chrono::duration, boost::nano > nanoseconds; +typedef boost::chrono::duration, boost::micro > microseconds; +typedef boost::chrono::duration, boost::milli > milliseconds; +typedef boost::chrono::duration > seconds; +typedef boost::chrono::duration, boost::ratio< 60LL> > minutes; +typedef boost::chrono::duration, boost::ratio< 3600LL> > hours; +typedef boost::chrono::duration, boost::ratio< 86400LL> > days; +typedef boost::chrono::duration, boost::ratio< 31556952LL> > years; +typedef boost::chrono::duration, boost::ratio<31556952000LL> > millennium; + +} // User2 + +// Demonstrate custom promotion rules (needed only if there are no implicit conversions) +namespace User2 { namespace detail { + +template ::value> +struct promote_helper; + +template +struct promote_helper, true> // integral +{ + typedef typename boost::common_type::type rep; + typedef User2::saturate type; +}; + +template +struct promote_helper, false> // floating +{ + typedef T1 type; +}; + +} } + +namespace boost +{ + +template +struct common_type, User2::saturate > +{ + typedef typename common_type::type rep; + typedef User2::saturate type; +}; + +template +struct common_type > + : User2::detail::promote_helper > {}; + +template +struct common_type, T2> + : User2::detail::promote_helper > {}; + + +// Demonstrate specialization of duration_values: + +namespace chrono { + +template +struct duration_values > +{ + typedef User2::saturate Rep; +public: + static Rep zero() {return Rep(0);} + static Rep max BOOST_PREVENT_MACRO_SUBSTITUTION () {return Rep(Rep::pos_inf-1);} + static Rep min BOOST_PREVENT_MACRO_SUBSTITUTION () {return -(max) ();} +}; + +} // namespace chrono + +} // namespace boost + + +void testUser2() +{ + std::cout << "*************\n"; + std::cout << "* testUser2 *\n"; + std::cout << "*************\n"; + using namespace User2; + typedef seconds::rep sat; + years yr(sat(100)); + std::cout << "100 years expressed as years = " << yr.count() << '\n'; + nanoseconds ns = yr; + std::cout << "100 years expressed as nanoseconds = " << ns.count() << '\n'; + ns += yr; + std::cout << "200 years expressed as nanoseconds = " << ns.count() << '\n'; + ns += yr; + std::cout << "300 years expressed as nanoseconds = " << ns.count() << '\n'; +// yr = ns; // does not compile + std::cout << "yr = ns; // does not compile\n"; +// picoseconds ps1 = yr; // does not compile, compile-time overflow in ratio arithmetic + std::cout << "ps = yr; // does not compile\n"; + ns = yr; + picoseconds ps = ns; + std::cout << "100 years expressed as picoseconds = " << ps.count() << '\n'; + ps = ns / sat(1000); + std::cout << "0.1 years expressed as picoseconds = " << ps.count() << '\n'; + yr = years(sat(-200000000)); + std::cout << "200 million years ago encoded in years: " << yr.count() << '\n'; + days d = boost::chrono::duration_cast(yr); + std::cout << "200 million years ago encoded in days: " << d.count() << '\n'; + millennium c = boost::chrono::duration_cast(yr); + std::cout << "200 million years ago encoded in millennium: " << c.count() << '\n'; + std::cout << "Demonstrate \"uninitialized protection\" behavior:\n"; + seconds sec; + for (++sec; sec < seconds(sat(10)); ++sec) + ; + std::cout << sec.count() << '\n'; + std::cout << "\n"; +} + +void testStdUser() +{ + std::cout << "***************\n"; + std::cout << "* testStdUser *\n"; + std::cout << "***************\n"; + using namespace boost::chrono; + hours hr = hours(100); + std::cout << "100 hours expressed as hours = " << hr.count() << '\n'; + nanoseconds ns = hr; + std::cout << "100 hours expressed as nanoseconds = " << ns.count() << '\n'; + ns += hr; + std::cout << "200 hours expressed as nanoseconds = " << ns.count() << '\n'; + ns += hr; + std::cout << "300 hours expressed as nanoseconds = " << ns.count() << '\n'; +// hr = ns; // does not compile + std::cout << "hr = ns; // does not compile\n"; +// hr * ns; // does not compile + std::cout << "hr * ns; // does not compile\n"; + duration fs(2.5); + std::cout << "duration has count() = " << fs.count() << '\n'; +// seconds sec = fs; // does not compile + std::cout << "seconds sec = duration won't compile\n"; + seconds sec = duration_cast(fs); + std::cout << "seconds has count() = " << sec.count() << '\n'; + std::cout << "\n"; +} + +// timeval clock demo +// Demonstrate the use of a timeval-like struct to be used as the representation +// type for both duraiton and time_point. + +namespace timeval_demo +{ + +class xtime { +private: + long tv_sec; + long tv_usec; + + void fixup() { + if (tv_usec < 0) { + tv_usec += 1000000; + --tv_sec; + } + } + +public: + + explicit xtime(long sec, long usec) { + tv_sec = sec; + tv_usec = usec; + if (tv_usec < 0 || tv_usec >= 1000000) { + tv_sec += tv_usec / 1000000; + tv_usec %= 1000000; + fixup(); + } + } + + explicit xtime(long long usec) + { + tv_usec = static_cast(usec % 1000000); + tv_sec = static_cast(usec / 1000000); + fixup(); + } + + // explicit + operator long long() const {return static_cast(tv_sec) * 1000000 + tv_usec;} + + xtime& operator += (xtime rhs) { + tv_sec += rhs.tv_sec; + tv_usec += rhs.tv_usec; + if (tv_usec >= 1000000) { + tv_usec -= 1000000; + ++tv_sec; + } + return *this; + } + + xtime& operator -= (xtime rhs) { + tv_sec -= rhs.tv_sec; + tv_usec -= rhs.tv_usec; + fixup(); + return *this; + } + + xtime& operator %= (xtime rhs) { + long long t = tv_sec * 1000000 + tv_usec; + long long r = rhs.tv_sec * 1000000 + rhs.tv_usec; + t %= r; + tv_sec = static_cast(t / 1000000); + tv_usec = static_cast(t % 1000000); + fixup(); + return *this; + } + + friend xtime operator+(xtime x, xtime y) {return x += y;} + friend xtime operator-(xtime x, xtime y) {return x -= y;} + friend xtime operator%(xtime x, xtime y) {return x %= y;} + + friend bool operator==(xtime x, xtime y) + { return (x.tv_sec == y.tv_sec && x.tv_usec == y.tv_usec); } + + friend bool operator<(xtime x, xtime y) { + if (x.tv_sec == y.tv_sec) + return (x.tv_usec < y.tv_usec); + return (x.tv_sec < y.tv_sec); + } + + friend bool operator!=(xtime x, xtime y) { return !(x == y); } + friend bool operator> (xtime x, xtime y) { return y < x; } + friend bool operator<=(xtime x, xtime y) { return !(y < x); } + friend bool operator>=(xtime x, xtime y) { return !(x < y); } + + friend std::ostream& operator<<(std::ostream& os, xtime x) + {return os << '{' << x.tv_sec << ',' << x.tv_usec << '}';} +}; + +class xtime_clock +{ +public: + typedef xtime rep; + typedef boost::micro period; + typedef boost::chrono::duration duration; + typedef boost::chrono::time_point time_point; + + static time_point now(); +}; + +xtime_clock::time_point +xtime_clock::now() +{ + time_point t(duration(xtime(0))); + gettimeofday((timeval*)&t, 0); + return t; +} + +void test_xtime_clock() +{ + using namespace boost::chrono; + std::cout << "timeval_demo system clock test\n"; + std::cout << "sizeof xtime_clock::time_point = " << sizeof(xtime_clock::time_point) << '\n'; + std::cout << "sizeof xtime_clock::duration = " << sizeof(xtime_clock::duration) << '\n'; + std::cout << "sizeof xtime_clock::rep = " << sizeof(xtime_clock::rep) << '\n'; + xtime_clock::duration delay(milliseconds(5)); + xtime_clock::time_point start = xtime_clock::now(); + while (xtime_clock::now() - start <= delay) + { + } + xtime_clock::time_point stop = xtime_clock::now(); + xtime_clock::duration elapsed = stop - start; + std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; +} + +} // timeval_demo + +// Handle duration with resolution not known until run time + +namespace runtime_resolution +{ + +class duration +{ +public: + typedef long long rep; +private: + rep rep_; + + static const double ticks_per_nanosecond; + +public: + typedef boost::chrono::duration tonanosec; + + duration() {} // = default; + explicit duration(const rep& r) : rep_(r) {} + + // conversions + explicit duration(const tonanosec& d) + : rep_(static_cast(d.count() * ticks_per_nanosecond)) {} + + // explicit + operator tonanosec() const {return tonanosec(rep_/ticks_per_nanosecond);} + + // observer + + rep count() const {return rep_;} + + // arithmetic + + duration& operator+=(const duration& d) {rep_ += d.rep_; return *this;} + duration& operator-=(const duration& d) {rep_ += d.rep_; return *this;} + duration& operator*=(rep rhs) {rep_ *= rhs; return *this;} + duration& operator/=(rep rhs) {rep_ /= rhs; return *this;} + + duration operator+() const {return *this;} + duration operator-() const {return duration(-rep_);} + duration& operator++() {++rep_; return *this;} + duration operator++(int) {return duration(rep_++);} + duration& operator--() {--rep_; return *this;} + duration operator--(int) {return duration(rep_--);} + + friend duration operator+(duration x, duration y) {return x += y;} + friend duration operator-(duration x, duration y) {return x -= y;} + friend duration operator*(duration x, rep y) {return x *= y;} + friend duration operator*(rep x, duration y) {return y *= x;} + friend duration operator/(duration x, rep y) {return x /= y;} + + friend bool operator==(duration x, duration y) {return x.rep_ == y.rep_;} + friend bool operator!=(duration x, duration y) {return !(x == y);} + friend bool operator< (duration x, duration y) {return x.rep_ < y.rep_;} + friend bool operator<=(duration x, duration y) {return !(y < x);} + friend bool operator> (duration x, duration y) {return y < x;} + friend bool operator>=(duration x, duration y) {return !(x < y);} +}; + +static +double +init_duration() +{ + //mach_timebase_info_data_t MachInfo; + //mach_timebase_info(&MachInfo); + //return static_cast(MachInfo.denom) / MachInfo.numer; + return static_cast(1) / 1000; // Windows FILETIME is 1 per microsec +} + +const double duration::ticks_per_nanosecond = init_duration(); + +class clock; + +class time_point +{ +public: + typedef runtime_resolution::clock clock; + typedef long long rep; +private: + rep rep_; + + + rep count() const {return rep_;} +public: + + time_point() : rep_(0) {} + explicit time_point(const duration& d) + : rep_(d.count()) {} + + // arithmetic + + time_point& operator+=(const duration& d) {rep_ += d.count(); return *this;} + time_point& operator-=(const duration& d) {rep_ -= d.count(); return *this;} + + friend time_point operator+(time_point x, duration y) {return x += y;} + friend time_point operator+(duration x, time_point y) {return y += x;} + friend time_point operator-(time_point x, duration y) {return x -= y;} + friend duration operator-(time_point x, time_point y) {return duration(x.rep_ - y.rep_);} +}; + +class clock +{ +public: + typedef duration::rep rep; + typedef runtime_resolution::duration duration; + typedef runtime_resolution::time_point time_point; + + static time_point now() + { + timeval tv; + gettimeofday( &tv, 0 ); + return time_point(duration((static_cast(tv.tv_sec)<<32) | tv.tv_usec)); + } +}; + +void test() +{ + using namespace boost::chrono; + std::cout << "runtime_resolution test\n"; + clock::duration delay(boost::chrono::milliseconds(5)); + clock::time_point start = clock::now(); + while (clock::now() - start <= delay) + ; + clock::time_point stop = clock::now(); + clock::duration elapsed = stop - start; + std::cout << "paused " << nanoseconds(duration_cast(duration::tonanosec(elapsed))).count() + << " nanoseconds\n"; +} + +} // runtime_resolution + +// miscellaneous tests and demos: + + +using namespace boost::chrono; + +void physics_function(duration d) +{ + std::cout << "d = " << d.count() << '\n'; +} + +void drive_physics_function() +{ + physics_function(nanoseconds(3)); + physics_function(hours(3)); + physics_function(duration(2./3)); + std::cout.precision(16); + physics_function( hours(3) + nanoseconds(-3) ); +} + +void test_range() +{ + using namespace boost::chrono; + hours h1 = hours(24 * ( 365 * 292 + 292/4)); + nanoseconds n1 = h1 + nanoseconds(1); + nanoseconds delta = n1 - h1; + std::cout << "292 years of hours = " << h1.count() << "hr\n"; + std::cout << "Add a nanosecond = " << n1.count() << "ns\n"; + std::cout << "Find the difference = " << delta.count() << "ns\n"; +} + +void test_extended_range() +{ + using namespace boost::chrono; + hours h1 = hours(24 * ( 365 * 244000 + 244000/4)); + /*auto*/ microseconds u1 = h1 + microseconds(1); + /*auto*/ microseconds delta = u1 - h1; + std::cout << "244,000 years of hours = " << h1.count() << "hr\n"; + std::cout << "Add a microsecond = " << u1.count() << "us\n"; + std::cout << "Find the difference = " << delta.count() << "us\n"; +} + +template +void inspect_duration(boost::chrono::duration d, const std::string& name) +{ + typedef boost::chrono::duration Duration; + std::cout << "********* " << name << " *********\n"; + std::cout << "The period of " << name << " is " << (double)Period::num/Period::den << " seconds.\n"; + std::cout << "The frequency of " << name << " is " << (double)Period::den/Period::num << " Hz.\n"; + std::cout << "The representation is "; + if (boost::is_floating_point::value) + { + std::cout << "floating point\n"; + std::cout << "The precision is the most significant "; + std::cout << std::numeric_limits::digits10 << " decimal digits.\n"; + } + else if (boost::is_integral::value) + { + std::cout << "integral\n"; + d = Duration(Rep(1)); + boost::chrono::duration dsec = d; + std::cout << "The precision is " << dsec.count() << " seconds.\n"; + } + else + { + std::cout << "a class type\n"; + d = Duration(Rep(1)); + boost::chrono::duration dsec = d; + std::cout << "The precision is " << dsec.count() << " seconds.\n"; + } + d = Duration((std::numeric_limits::max)()); + using namespace boost::chrono; + using namespace std; + typedef duration, hours::period>::type> Years; + Years years = d; + std::cout << "The range is +/- " << years.count() << " years.\n"; + std::cout << "sizeof(" << name << ") = " << sizeof(d) << '\n'; +} + +void inspect_all() +{ + using namespace boost::chrono; + std::cout.precision(6); + inspect_duration(nanoseconds(), "nanoseconds"); + inspect_duration(microseconds(), "microseconds"); + inspect_duration(milliseconds(), "milliseconds"); + inspect_duration(seconds(), "seconds"); + inspect_duration(minutes(), "minutes"); + inspect_duration(hours(), "hours"); + inspect_duration(duration(), "duration"); +} + +void test_milliseconds() +{ + using namespace boost::chrono; + milliseconds ms(250); + ms += milliseconds(1); + milliseconds ms2(150); + milliseconds msdiff = ms - ms2; + if (msdiff == milliseconds(101)) + std::cout << "success\n"; + else + std::cout << "failure: " << msdiff.count() << '\n'; +} + + using namespace std; + using namespace boost::chrono; + +// Example round_up utility: converts d to To, rounding up for inexact conversions +// Being able to *easily* write this function is a major feature! +template +To +round_up(duration d) +{ + To result = duration_cast(d); + if (result < d) + ++result; + return result; +} + +// demonstrate interaction with xtime-like facility: + +using namespace boost::chrono; + +struct xtime +{ + long sec; + unsigned long usec; +}; + +template +xtime +to_xtime_truncate(duration d) +{ + xtime xt; + xt.sec = static_cast(duration_cast(d).count()); + xt.usec = static_cast(duration_cast(d - seconds(xt.sec)).count()); + return xt; +} + +template +xtime +to_xtime_round_up(duration d) +{ + xtime xt; + xt.sec = static_cast(duration_cast(d).count()); + xt.usec = static_cast(round_up(d - seconds(xt.sec)).count()); + return xt; +} + +microseconds +from_xtime(xtime xt) +{ + return seconds(xt.sec) + microseconds(xt.usec); +} + +void print(xtime xt) +{ + cout << '{' << xt.sec << ',' << xt.usec << "}\n"; +} + +void test_with_xtime() +{ + cout << "test_with_xtime\n"; + xtime xt = to_xtime_truncate(seconds(3) + milliseconds(251)); + print(xt); + milliseconds ms = duration_cast(from_xtime(xt)); + cout << ms.count() << " milliseconds\n"; + xt = to_xtime_round_up(ms); + print(xt); + xt = to_xtime_truncate(seconds(3) + nanoseconds(999)); + print(xt); + xt = to_xtime_round_up(seconds(3) + nanoseconds(999)); + print(xt); +} + +void test_system_clock() +{ + cout << "system_clock test" << endl; + system_clock::duration delay = milliseconds(5); + system_clock::time_point start = system_clock::now(); + while (system_clock::now() - start <= delay) + ; + system_clock::time_point stop = system_clock::now(); + system_clock::duration elapsed = stop - start; + cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; + start = system_clock::now(); + stop = system_clock::now(); + cout << "system_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n"; +} + +void test_steady_clock() +{ + cout << "steady_clock test" << endl; + steady_clock::duration delay = milliseconds(5); + steady_clock::time_point start = steady_clock::now(); + while (steady_clock::now() - start <= delay) + ; + steady_clock::time_point stop = steady_clock::now(); + steady_clock::duration elapsed = stop - start; + cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; + start = steady_clock::now(); + stop = steady_clock::now(); + cout << "steady_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n"; +} + +void test_hi_resolution_clock() +{ + cout << "high_resolution_clock test" << endl; + high_resolution_clock::duration delay = milliseconds(5); + high_resolution_clock::time_point start = high_resolution_clock::now(); + while (high_resolution_clock::now() - start <= delay) + ; + high_resolution_clock::time_point stop = high_resolution_clock::now(); + high_resolution_clock::duration elapsed = stop - start; + cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; + start = high_resolution_clock::now(); + stop = high_resolution_clock::now(); + cout << "high_resolution_clock resolution estimate: " << nanoseconds(stop-start).count() << " nanoseconds\n"; +} + +//void test_mixed_clock() +//{ +// cout << "mixed clock test" << endl; +// high_resolution_clock::time_point hstart = high_resolution_clock::now(); +// cout << "Add 5 milliseconds to a high_resolution_clock::time_point\n"; +// steady_clock::time_point mend = hstart + milliseconds(5); +// bool b = hstart == mend; +// system_clock::time_point sstart = system_clock::now(); +// std::cout << "Subtracting system_clock::time_point from steady_clock::time_point doesn't compile\n"; +//// mend - sstart; // doesn't compile +// cout << "subtract high_resolution_clock::time_point from steady_clock::time_point" +// " and add that to a system_clock::time_point\n"; +// system_clock::time_point send = sstart + duration_cast(mend - hstart); +// cout << "subtract two system_clock::time_point's and output that in microseconds:\n"; +// microseconds ms = send - sstart; +// cout << ms.count() << " microseconds\n"; +//} +// +//void test_c_mapping() +//{ +// cout << "C map test\n"; +// using namespace boost::chrono; +// system_clock::time_point t1 = system_clock::now(); +// std::time_t c_time = system_clock::to_time_t(t1); +// std::tm* tmptr = std::localtime(&c_time); +// std::cout << "It is now " << tmptr->tm_hour << ':' << tmptr->tm_min << ':' << tmptr->tm_sec << ' ' +// << tmptr->tm_year + 1900 << '-' << tmptr->tm_mon + 1 << '-' << tmptr->tm_mday << '\n'; +// c_time = std::mktime(tmptr); +// system_clock::time_point t2 = system_clock::from_time_t(c_time); +// microseconds ms = t1 - t2; +// std::cout << "Round-tripping through the C interface truncated the precision by " << ms.count() << " microseconds\n"; +//} + +void test_duration_division() +{ + cout << hours(3) / milliseconds(5) << '\n'; + cout << milliseconds(5) / hours(3) << '\n'; + cout << hours(1) / milliseconds(1) << '\n'; +} + +namespace I_dont_like_the_default_duration_behavior +{ + +// Here's how you override the duration's default constructor to do anything you want (in this case zero) + +template +class zero_default +{ +public: + typedef R rep; + +private: + rep rep_; +public: + zero_default(rep i = 0) : rep_(i) {} + operator rep() const {return rep_;} + + zero_default& operator+=(zero_default x) {rep_ += x.rep_; return *this;} + zero_default& operator-=(zero_default x) {rep_ -= x.rep_; return *this;} + zero_default& operator*=(zero_default x) {rep_ *= x.rep_; return *this;} + zero_default& operator/=(zero_default x) {rep_ /= x.rep_; return *this;} + + zero_default operator+ () const {return *this;} + zero_default operator- () const {return zero_default(-rep_);} + zero_default& operator++() {++rep_; return *this;} + zero_default operator++(int) {return zero_default(rep_++);} + zero_default& operator--() {--rep_; return *this;} + zero_default operator--(int) {return zero_default(rep_--);} + + friend zero_default operator+(zero_default x, zero_default y) {return x += y;} + friend zero_default operator-(zero_default x, zero_default y) {return x -= y;} + friend zero_default operator*(zero_default x, zero_default y) {return x *= y;} + friend zero_default operator/(zero_default x, zero_default y) {return x /= y;} + + friend bool operator==(zero_default x, zero_default y) {return x.rep_ == y.rep_;} + friend bool operator!=(zero_default x, zero_default y) {return !(x == y);} + friend bool operator< (zero_default x, zero_default y) {return x.rep_ < y.rep_;} + friend bool operator<=(zero_default x, zero_default y) {return !(y < x);} + friend bool operator> (zero_default x, zero_default y) {return y < x;} + friend bool operator>=(zero_default x, zero_default y) {return !(x < y);} +}; + +typedef boost::chrono::duration, boost::nano > nanoseconds; +typedef boost::chrono::duration, boost::micro > microseconds; +typedef boost::chrono::duration, boost::milli > milliseconds; +typedef boost::chrono::duration > seconds; +typedef boost::chrono::duration, boost::ratio<60> > minutes; +typedef boost::chrono::duration, boost::ratio<3600> > hours; + +void test() +{ + milliseconds ms; + cout << ms.count() << '\n'; +} + +} // I_dont_like_the_default_duration_behavior + +// Build a min for two time_points + +template +void +print_duration(ostream& os, duration d) +{ + os << d.count() << " * " << Period::num << '/' << Period::den << " seconds\n"; +} + +// Example min utility: returns the earliest time_point +// Being able to *easily* write this function is a major feature! +template +inline +typename boost::common_type, + time_point >::type +min BOOST_PREVENT_MACRO_SUBSTITUTION (time_point t1, time_point t2) +{ + return t2 < t1 ? t2 : t1; +} + +void test_min() +{ + typedef time_point::type> T1; + typedef time_point::type> T2; + typedef boost::common_type::type T3; + /*auto*/ T1 t1 = system_clock::now() + seconds(3); + /*auto*/ T2 t2 = system_clock::now() + nanoseconds(3); + /*auto*/ T3 t3 = (min)(t1, t2); + print_duration(cout, t1 - t3); + print_duration(cout, t2 - t3); +} + +void explore_limits() +{ + typedef duration, + hours::period>::type> Years; + steady_clock::time_point t1( Years(250)); + steady_clock::time_point t2(-Years(250)); + // nanosecond resolution is likely to overflow. "up cast" to microseconds. + // The "up cast" trades precision for range. + microseconds d = time_point_cast(t1) - time_point_cast(t2); + cout << d.count() << " microseconds\n"; +} + +void manipulate_clock_object(system_clock clock) +{ + system_clock::duration delay = milliseconds(5); + system_clock::time_point start = clock.now(); + while (clock.now() - start <= delay) + ; + system_clock::time_point stop = clock.now(); + system_clock::duration elapsed = stop - start; + cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; +}; + +template +struct cycle_count +{ + typedef typename boost::ratio_multiply, boost::mega>::type frequency; // Mhz + typedef typename boost::ratio_divide, frequency>::type period; + typedef long long rep; + typedef boost::chrono::duration duration; + typedef boost::chrono::time_point time_point; + + static time_point now() + { + static long long tick = 0; + // return exact cycle count + return time_point(duration(++tick)); // fake access to clock cycle count + } +}; + +template +struct approx_cycle_count +{ + static const long long frequency = speed * 1000000; // MHz + typedef nanoseconds duration; + typedef duration::rep rep; + typedef duration::period period; + static const long long nanosec_per_sec = period::den; + typedef boost::chrono::time_point time_point; + + static time_point now() + { + static long long tick = 0; + // return cycle count as an approximate number of nanoseconds + // compute as if nanoseconds is only duration in the std::lib + return time_point(duration(++tick * nanosec_per_sec / frequency)); + } +}; + +void cycle_count_delay() +{ + { + typedef cycle_count<400> clock; + cout << "\nSimulated " << clock::frequency::num / boost::mega::num << "MHz clock which has a tick period of " + << duration(clock::duration(1)).count() << " nanoseconds\n"; + nanoseconds delayns(500); + clock::duration delay = duration_cast(delayns); + cout << "delay = " << delayns.count() << " nanoseconds which is " << delay.count() << " cycles\n"; + clock::time_point start = clock::now(); + clock::time_point stop = start + delay; + while (clock::now() < stop) // no multiplies or divides in this loop + ; + clock::time_point end = clock::now(); + clock::duration elapsed = end - start; + cout << "paused " << elapsed.count() << " cycles "; + cout << "which is " << duration_cast(elapsed).count() << " nanoseconds\n"; + } + { + typedef approx_cycle_count<400> clock; + cout << "\nSimulated " << clock::frequency / 1000000 << "MHz clock modeled with nanoseconds\n"; + clock::duration delay = nanoseconds(500); + cout << "delay = " << delay.count() << " nanoseconds\n"; + clock::time_point start = clock::now(); + clock::time_point stop = start + delay; + while (clock::now() < stop) // 1 multiplication and 1 division in this loop + ; + clock::time_point end = clock::now(); + clock::duration elapsed = end - start; + cout << "paused " << elapsed.count() << " nanoseconds\n"; + } + { + typedef cycle_count<1500> clock; + cout << "\nSimulated " << clock::frequency::num / boost::mega::num << "MHz clock which has a tick period of " + << duration(clock::duration(1)).count() << " nanoseconds\n"; + nanoseconds delayns(500); + clock::duration delay = duration_cast(delayns); + cout << "delay = " << delayns.count() << " nanoseconds which is " << delay.count() << " cycles\n"; + clock::time_point start = clock::now(); + clock::time_point stop = start + delay; + while (clock::now() < stop) // no multiplies or divides in this loop + ; + clock::time_point end = clock::now(); + clock::duration elapsed = end - start; + cout << "paused " << elapsed.count() << " cycles "; + cout << "which is " << duration_cast(elapsed).count() << " nanoseconds\n"; + } + { + typedef approx_cycle_count<1500> clock; + cout << "\nSimulated " << clock::frequency / 1000000 << "MHz clock modeled with nanoseconds\n"; + clock::duration delay = nanoseconds(500); + cout << "delay = " << delay.count() << " nanoseconds\n"; + clock::time_point start = clock::now(); + clock::time_point stop = start + delay; + while (clock::now() < stop) // 1 multiplication and 1 division in this loop + ; + clock::time_point end = clock::now(); + clock::duration elapsed = end - start; + cout << "paused " << elapsed.count() << " nanoseconds\n"; + } +} + +void test_special_values() +{ + std::cout << "duration::min().count() = " << (duration::min)().count() << '\n'; + std::cout << "duration::zero().count() = " << duration::zero().count() << '\n'; + std::cout << "duration::max().count() = " << (duration::max)().count() << '\n'; + std::cout << "duration::min().count() = " << (duration::min)().count() << '\n'; + std::cout << "duration::zero().count() = " << duration::zero().count() << '\n'; + std::cout << "duration::max().count() = " << (duration::max)().count() << '\n'; +} + +int main() +{ + basic_examples(); + testStdUser(); + testUser1(); + testUser2(); + drive_physics_function(); + test_range(); + test_extended_range(); + inspect_all(); + test_milliseconds(); + test_with_xtime(); + test_system_clock(); + test_steady_clock(); + test_hi_resolution_clock(); + //test_mixed_clock(); + timeval_demo::test_xtime_clock(); + runtime_resolution::test(); + //test_c_mapping(); + test_duration_division(); + I_dont_like_the_default_duration_behavior::test(); + test_min(); + inspect_duration(common_type, hours, microseconds>::type(), + "common_type, hours, microseconds>::type"); + explore_limits(); + manipulate_clock_object(system_clock()); + duration d = milliseconds(3) * 2.5; + inspect_duration(milliseconds(3) * 2.5, "milliseconds(3) * 2.5"); + cout << d.count() << '\n'; +// milliseconds ms(3.5); // doesn't compile + cout << "milliseconds ms(3.5) doesn't compile\n"; + cycle_count_delay(); + test_special_values(); + return 0; +} + diff --git a/src/boost/libs/chrono/example/time2_demo_output.txt b/src/boost/libs/chrono/example/time2_demo_output.txt new file mode 100644 index 000000000..af978e9a8 --- /dev/null +++ b/src/boost/libs/chrono/example/time2_demo_output.txt @@ -0,0 +1,191 @@ +// time2_demo.output ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +Running basic examples +sleep_for 3000000 microseconds +sleep_for 1 microseconds +sleep_until 10:47:17.728293 which is 4499340 microseconds away +try_lock_for 30000 microseconds +try_lock_until 10:47:17.728285 which is 4499303 microseconds away +wait_for 60000000 microseconds +wait_until 10:47:17.728285 which is 4499264 microseconds away +sleep_for 250000 microseconds +sleep_until 10:47:14.729077 which is 1499979 microseconds away +*************** +* testStdUser * +*************** +100 hours expressed as hours = 100 +100 hours expressed as nanoseconds = 360000000000000 +200 hours expressed as nanoseconds = 720000000000000 +300 hours expressed as nanoseconds = 1080000000000000 +hr = ns; // does not compile +hr * ns; // does not compile +duration has count() = 2.5 +seconds sec = duration won't compile +seconds has count() = 2 + +************* +* testUser1 * +************* +Speed = 24.5872 meters/sec +Acceleration = 9.81456 meters/sec^2 +Distance = 13.5204 meters +There are 125/201168 miles/meter which is approximately 0.000621371 +There are 201168/125 meters/mile which is approximately 1609.34 +1 attosecond is 1e-18 seconds +sec = as; // compiles +1 second is 1e+18 attoseconds +as = sec; // compiles + +************* +* testUser2 * +************* +100 years expressed as years = 100 +100 years expressed as nanoseconds = 3155695200000000000 +200 years expressed as nanoseconds = 6311390400000000000 +300 years expressed as nanoseconds = inf +yr = ns; // does not compile +ps = yr; // does not compile +100 years expressed as picoseconds = inf +0.1 years expressed as picoseconds = 3155695200000000000 +200 million years ago encoded in years: -200000000 +200 million years ago encoded in days: -73048500000 +200 million years ago encoded in millennium: -200000 +Demonstrate "uninitialized protection" behavior: +nan + +d = 3e-09 +d = 10800 +d = 0.666667 +d = 10799.999999997 +292 years of hours = 2559672hr +Add a nanosecond = 9214819200000000001ns +Find the difference = 1ns +244,000 years of hours = 2138904000hr +Add a microsecond = 7700054400000000001us +Find the difference = 1us +********* nanoseconds ********* +The period of nanoseconds is 1e-09 seconds. +The frequency of nanoseconds is 1e+09 Hz. +The representation is integral +The precision is 1e-09 seconds. +The range is +/- 292.277 years. +sizeof(nanoseconds) = 8 +********* microseconds ********* +The period of microseconds is 1e-06 seconds. +The frequency of microseconds is 1e+06 Hz. +The representation is integral +The precision is 1e-06 seconds. +The range is +/- 292277 years. +sizeof(microseconds) = 8 +********* milliseconds ********* +The period of milliseconds is 0.001 seconds. +The frequency of milliseconds is 1000 Hz. +The representation is integral +The precision is 0.001 seconds. +The range is +/- 2.92277e+08 years. +sizeof(milliseconds) = 8 +********* seconds ********* +The period of seconds is 1 seconds. +The frequency of seconds is 1 Hz. +The representation is integral +The precision is 1 seconds. +The range is +/- 2.92277e+11 years. +sizeof(seconds) = 8 +********* minutes ********* +The period of minutes is 60 seconds. +The frequency of minutes is 0.0166667 Hz. +The representation is integral +The precision is 60 seconds. +The range is +/- 4083.06 years. +sizeof(minutes) = 4 +********* hours ********* +The period of hours is 3600 seconds. +The frequency of hours is 0.000277778 Hz. +The representation is integral +The precision is 3600 seconds. +The range is +/- 244984 years. +sizeof(hours) = 4 +********* duration ********* +The period of duration is 1 seconds. +The frequency of duration is 1 Hz. +The representation is floating point +The precision is the most significant 15 decimal digits. +The range is +/- 5.69666e+300 years. +sizeof(duration) = 8 +success +test_with_xtime +{3,251000} +3251 milliseconds +{3,251000} +{3,0} +{3,1} +system_clock test +paused 5001000 nanoseconds +system_clock resolution estimate: 0 nanoseconds +monotonic_clock test +paused 5000181 nanoseconds +monotonic_clock resolution estimate: 97 nanoseconds +high_resolution_clock test +paused 5000277 nanoseconds +high_resolution_clock resolution estimate: 96 nanoseconds +mixed clock test +Add 5 milliseconds to a high_resolution_clock::time_point +Subtracting system_clock::time_point from monotonic_clock::time_point doesn't compile +subtract high_resolution_clock::time_point from monotonic_clock::time_point and add that to a system_clock::time_point +subtract two system_clock::time_point's and output that in microseconds: +5000 microseconds +timeval_demo system clock test +sizeof xtime_clock::time_point = 8 +sizeof xtime_clock::duration = 8 +sizeof xtime_clock::rep = 8 +paused 5001000 nanoseconds +runtime_resolution test +paused 5000205 nanoseconds +C map test +It is now 10:47:13 2008-4-22 +Round-tripping through the C interface truncated the precision by 255445 microseconds +2160000 +0 +3600000 +0 +2999998997 * 1/1000000000 seconds +0 * 1/1000000000 seconds +15778476000000000 microseconds +paused 5001000 nanoseconds +********* milliseconds(3) * 2.5 ********* +The period of milliseconds(3) * 2.5 is 0.001 seconds. +The frequency of milliseconds(3) * 2.5 is 1000 Hz. +The representation is floating point +The precision is the most significant 15 decimal digits. +The range is +/- 5.69666e+297 years. +sizeof(milliseconds(3) * 2.5) = 8 +7.5 +milliseconds ms(3.5) doesn't compile + +Simulated 400MHz clock which has a tick period of 2.5 nanoseconds +delay = 500 nanoseconds which is 200 cycles +paused 201 cycles which is 502 nanoseconds + +Simulated 400MHz clock modeled with nanoseconds +delay = 500 nanoseconds +paused 503 nanoseconds + +Simulated 1500MHz clock which has a tick period of 0.666667 nanoseconds +delay = 500 nanoseconds which is 750 cycles +paused 751 cycles which is 500 nanoseconds + +Simulated 1500MHz clock modeled with nanoseconds +delay = 500 nanoseconds +paused 500 nanoseconds +duration::min().count() = 0 +duration::zero().count() = 0 +duration::max().count() = 4294967295 +duration::min().count() = -2147483647 +duration::zero().count() = 0 +duration::max().count() = 2147483647 diff --git a/src/boost/libs/chrono/example/timer.hpp b/src/boost/libs/chrono/example/timer.hpp new file mode 100644 index 000000000..c65930d04 --- /dev/null +++ b/src/boost/libs/chrono/example/timer.hpp @@ -0,0 +1,62 @@ +// boost/chrono/timer.hpp ------------------------------------------------------------// + +// Copyright Beman Dawes 2008 +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +// See http://www.boost.org/libs/system for documentation. + +#ifndef BOOSTEX_CHRONO_TIMER_HPP +#define BOOSTEX_CHRONO_TIMER_HPP + +#include +#include + +namespace boost_ex +{ + namespace chrono + { + +//--------------------------------------------------------------------------------------// +// timer // +//--------------------------------------------------------------------------------------// + + template + class timer + { + public: + typedef Clock clock; + typedef typename Clock::duration duration; + typedef typename Clock::time_point time_point; + + explicit timer( boost::system::error_code & ec = ::boost::throws() ) + { + start(ec); + } + + ~timer() {} // never throws + + void start( boost::system::error_code & ec = ::boost::throws() ) + { + m_start = clock::now( ec ); + } + + duration elapsed( boost::system::error_code & ec = ::boost::throws() ) + { return clock::now( ec ) - m_start; } + + private: + time_point m_start; + }; + + typedef chrono::timer< boost::chrono::system_clock > system_timer; +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + typedef chrono::timer< boost::chrono::steady_clock > steady_timer; +#endif + typedef chrono::timer< boost::chrono::high_resolution_clock > high_resolution_timer; + + } // namespace chrono +} // namespace boost_ex + +#endif diff --git a/src/boost/libs/chrono/example/timeval_demo.cpp b/src/boost/libs/chrono/example/timeval_demo.cpp new file mode 100644 index 000000000..2294489d5 --- /dev/null +++ b/src/boost/libs/chrono/example/timeval_demo.cpp @@ -0,0 +1,237 @@ +// timeval_demo.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba +// Copyright (c) Microsoft Corporation 2014 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ +#define _CRT_SECURE_NO_WARNINGS // disable VC++ foolishness + +#include +#include + +#include + +#if defined(BOOST_CHRONO_MAC_API) +#include //for gettimeofday and timeval +#endif + +#if defined(BOOST_CHRONO_WINDOWS_API) +# include +#endif + +#if defined(BOOST_CHRONO_WINDOWS_API) + +namespace +{ + #if defined UNDER_CE || BOOST_PLAT_WINDOWS_RUNTIME + // Windows CE and Windows store does not define timeval + struct timeval { + long tv_sec; /* seconds */ + long tv_usec; /* and microseconds */ + }; + #endif + + int gettimeofday(struct timeval * tp, void *) + { + FILETIME ft; + #if defined(UNDER_CE) + // Windows CE does not define GetSystemTimeAsFileTime so we do it in two steps. + SYSTEMTIME st; + ::GetSystemTime( &st ); + ::SystemTimeToFileTime( &st, &ft ); + #else + ::GetSystemTimeAsFileTime( &ft ); // never fails + #endif + long long t = (static_cast(ft.dwHighDateTime) << 32) | ft.dwLowDateTime; + # if !defined( BOOST_MSVC ) || BOOST_MSVC > 1300 // > VC++ 7.0 + t -= 116444736000000000LL; + # else + t -= 116444736000000000; + # endif + t /= 10; // microseconds + tp->tv_sec = static_cast( t / 1000000UL); + tp->tv_usec = static_cast( t % 1000000UL); + return 0; + } +} // unnamed namespace + +#endif + +// timeval clock demo +// Demonstrate the use of a timeval-like struct to be used as the representation +// type for both duraiton and time_point. + +namespace timeval_demo +{ + +class xtime { +private: + long tv_sec; + long tv_usec; + + void fixup() { + if (tv_usec < 0) { + tv_usec += 1000000; + --tv_sec; + } + } + +public: + + explicit xtime(long sec, long usec) { + tv_sec = sec; + tv_usec = usec; + if (tv_usec < 0 || tv_usec >= 1000000) { + tv_sec += tv_usec / 1000000; + tv_usec %= 1000000; + fixup(); + } + } + + explicit xtime(long long usec) + { + tv_usec = static_cast(usec % 1000000); + tv_sec = static_cast(usec / 1000000); + fixup(); + } + + // explicit + operator long long() const {return static_cast(tv_sec) * 1000000 + tv_usec;} + + xtime& operator += (xtime rhs) { + tv_sec += rhs.tv_sec; + tv_usec += rhs.tv_usec; + if (tv_usec >= 1000000) { + tv_usec -= 1000000; + ++tv_sec; + } + return *this; + } + + xtime& operator -= (xtime rhs) { + tv_sec -= rhs.tv_sec; + tv_usec -= rhs.tv_usec; + fixup(); + return *this; + } + + xtime& operator %= (xtime rhs) { + long long t = tv_sec * 1000000 + tv_usec; + long long r = rhs.tv_sec * 1000000 + rhs.tv_usec; + t %= r; + tv_sec = static_cast(t / 1000000); + tv_usec = static_cast(t % 1000000); + fixup(); + return *this; + } + + friend xtime operator+(xtime x, xtime y) {return x += y;} + friend xtime operator-(xtime x, xtime y) {return x -= y;} + friend xtime operator%(xtime x, xtime y) {return x %= y;} + + friend bool operator==(xtime x, xtime y) + { return (x.tv_sec == y.tv_sec && x.tv_usec == y.tv_usec); } + + friend bool operator<(xtime x, xtime y) { + if (x.tv_sec == y.tv_sec) + return (x.tv_usec < y.tv_usec); + return (x.tv_sec < y.tv_sec); + } + + friend bool operator!=(xtime x, xtime y) { return !(x == y); } + friend bool operator> (xtime x, xtime y) { return y < x; } + friend bool operator<=(xtime x, xtime y) { return !(y < x); } + friend bool operator>=(xtime x, xtime y) { return !(x < y); } + + friend std::ostream& operator<<(std::ostream& os, xtime x) + {return os << '{' << x.tv_sec << ',' << x.tv_usec << '}';} +}; + +class xtime_clock +{ +public: + typedef xtime rep; + typedef boost::micro period; + typedef boost::chrono::duration duration; + typedef boost::chrono::time_point time_point; + + static time_point now(); +}; + + +xtime_clock::time_point +xtime_clock::now() +{ +#if defined(BOOST_CHRONO_WINDOWS_API) + timeval tv; + gettimeofday(&tv, 0); + xtime xt( tv.tv_sec, tv.tv_usec); + return time_point(duration(xt)); + +#elif defined(BOOST_CHRONO_MAC_API) + + timeval tv; + gettimeofday(&tv, 0); + xtime xt( tv.tv_sec, tv.tv_usec); + return time_point(duration(xt)); + +#elif defined(BOOST_CHRONO_POSIX_API) + //time_point t(0,0); + + timespec ts; + ::clock_gettime( CLOCK_REALTIME, &ts ); + + xtime xt( ts.tv_sec, ts.tv_nsec/1000); + return time_point(duration(xt)); +#endif // POSIX + +} + +void test_xtime_clock() +{ + using namespace boost::chrono; + std::cout << "timeval_demo system clock test\n"; + std::cout << "sizeof xtime_clock::time_point = " << sizeof(xtime_clock::time_point) << '\n'; + std::cout << "sizeof xtime_clock::duration = " << sizeof(xtime_clock::duration) << '\n'; + std::cout << "sizeof xtime_clock::rep = " << sizeof(xtime_clock::rep) << '\n'; + xtime_clock::duration delay(milliseconds(5)); + xtime_clock::time_point start = xtime_clock::now(); + + while (xtime_clock::now() - start <= delay) + { + } + xtime_clock::time_point stop = xtime_clock::now(); + xtime_clock::duration elapsed = stop - start; + std::cout << "paused " << nanoseconds(elapsed).count() << " nanoseconds\n"; +} + +} // timeval_demo + +int main() +{ + timeval_demo::test_xtime_clock(); + return 0; +} + diff --git a/src/boost/libs/chrono/example/xtime.cpp b/src/boost/libs/chrono/example/xtime.cpp new file mode 100644 index 000000000..d53cfa846 --- /dev/null +++ b/src/boost/libs/chrono/example/xtime.cpp @@ -0,0 +1,109 @@ +// xtime.cpp ----------------------------------------------------------// + +// Copyright 2008 Howard Hinnant +// Copyright 2008 Beman Dawes +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +/* +This code was extracted by Vicente J. Botet Escriba from Beman Dawes time2_demo.cpp which +was derived by Beman Dawes 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 to conform to Boost conventions and to section +20.9 Time utilities [time] of the C++ committee's working paper N2798. +See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2798.pdf. + +time2_demo contained this comment: + + Much thanks to Andrei Alexandrescu, + Walter Brown, + Peter Dimov, + Jeff Garland, + Terry Golubiewski, + Daniel Krugler, + Anthony Williams. +*/ + +#include +#include + +#include + +using namespace boost::chrono; + +// Example round_up utility: converts d to To, rounding up for inexact conversions +// Being able to *easily* write this function is a major feature! +template +To +round_up(duration d) +{ + To result = duration_cast(d); + if (result < d) + ++result; + return result; +} + +// demonstrate interaction with xtime-like facility: + +// msvc defines ::xtime in , so we use xtime_ +struct xtime_ +{ + long sec; + unsigned long usec; +}; + +template +xtime_ +to_xtime_truncate(duration d) +{ + xtime_ xt; + xt.sec = static_cast(duration_cast(d).count()); + xt.usec = static_cast(duration_cast(d - seconds(xt.sec)).count()); + return xt; +} + +template +xtime_ +to_xtime_round_up(duration d) +{ + xtime_ xt; + xt.sec = static_cast(duration_cast(d).count()); + xt.usec = static_cast(round_up(d - seconds(xt.sec)).count()); + return xt; +} + +microseconds +from_xtime(xtime_ xt) +{ + return seconds(xt.sec) + microseconds(xt.usec); +} + +void print(xtime_ xt) +{ + std::cout << '{' << xt.sec << ',' << xt.usec << "}\n"; +} + +void test_with_xtime() +{ + std::cout << "test_with_xtime\n"; + xtime_ xt = to_xtime_truncate(seconds(3) + milliseconds(251)); + print(xt); + milliseconds ms = duration_cast(from_xtime(xt)); + std::cout << ms.count() << " milliseconds\n"; + xt = to_xtime_round_up(ms); + print(xt); + xt = to_xtime_truncate(seconds(3) + nanoseconds(999)); + print(xt); + xt = to_xtime_round_up(seconds(3) + nanoseconds(999)); + print(xt); +} + + +int main() +{ + test_with_xtime(); + return 0; +} + diff --git a/src/boost/libs/chrono/index.html b/src/boost/libs/chrono/index.html new file mode 100644 index 000000000..e363e6e07 --- /dev/null +++ b/src/boost/libs/chrono/index.html @@ -0,0 +1,15 @@ + + + + + +Automatic redirection failed, please go to +../../doc/html/chrono.html +

© Copyright 2009-2010 Vicente J. Botet Escribá. +Distributed under the Boost Software +License, Version 1.0. (See accompanying file +LICENSE_1_0.txt or copy at +http://www.boost.org/LICENSE_1_0.txt) +

+ + diff --git a/src/boost/libs/chrono/meta/libraries.json b/src/boost/libs/chrono/meta/libraries.json new file mode 100644 index 000000000..6c3a7df55 --- /dev/null +++ b/src/boost/libs/chrono/meta/libraries.json @@ -0,0 +1,20 @@ +[ + { + "key": "chrono", + "name": "Chrono", + "authors": [ + "Howard Hinnant", + "Beman Dawes", + "Vicente J. Botet Escriba" + ], + "maintainers": [ + "Vicente J. Botet Escriba " + ], + "description": + "Useful time utilities. C++11.", + "std": [ "proposal" ], + "category": [ + "Domain", "System" + ] + } +] diff --git a/src/boost/libs/chrono/perf/Jamfile.v2 b/src/boost/libs/chrono/perf/Jamfile.v2 new file mode 100644 index 000000000..8c68f74f3 --- /dev/null +++ b/src/boost/libs/chrono/perf/Jamfile.v2 @@ -0,0 +1,147 @@ +# Boost Chrono Library test Jamfile + +# Copyright Beman Dawes 2008 +# Copyright Vicente J. Botet Escriba 2009-2010 + +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt + +# See library home page at http://www.boost.org/libs/chrono + +import os ; +import feature ; + +project + : requirements + freebsd:"-lrt" + linux:"-lrt" + pgi:"-lrt" + #single:BOOST_CHRONO_THREAD_DISABLED + msvc:on + BOOST_CHRONO_USES_MPL_ASSERT + sun:BOOST_TYPEOF_EMULATION + all + gcc:-Wextra + gcc:-pedantic + gcc:-Wno-long-long + darwin:-Wextra + darwin:-pedantic + darwin:-Wno-long-long + #pathscale:-Wextra + pathscale:-Wno-long-long + pathscale:-pedantic + clang:-Wextra + clang:-pedantic + clang:-Wno-long-long + gcc-4.5.0,windows:-Wno-missing-field-initializers + gcc-4.5.0,windows:-fdiagnostics-show-option + msvc:/wd4127 +# Note: Some of the remarks from the Intel compiler are disabled +# remark #304: access control not specified ("public" by default) +# remark #383: value copied to temporary, reference to temporary used +# remark #1418: external function definition with no prior declaration + intel:-wd304,383,1418 + BOOST_CHRONO_VERSION=2 + ; + +rule chrono-run ( sources ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + : $(sources[1]:B)_shared ] + [ run $(sources) ../build//boost_chrono/static + : : + : + : $(sources[1]:B)_static ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + : $(sources[1]:B)_header ] + ; +} +rule chrono-run2 ( sources : name ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + : $(name)_shared ] + [ run $(sources) ../build//boost_chrono/static + : : + : + : $(name)_static ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + : $(name)_header ] + ; +} + + +rule chrono-run-mt ( sources ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + : $(sources[1]:B)_shared ] + [ run $(sources) ../build//boost_chrono/static + : : + : + : $(sources[1]:B)_static ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + : $(sources[1]:B)_header ] + ; +} +rule chrono-run2-mt ( sources : name ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + /boost/system//boost_system + : $(name)_shared ] + [ run $(sources) ../build//boost_chrono/static + : : + : + /boost/system//boost_system + : $(name)_static ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + : $(name)_header ] + ; +} +rule chrono-compile ( sources ) +{ + return + [ compile $(sources) + : + : $(sources[1]:B)_lib ] + [ compile $(sources) + : BOOST_CHRONO_HEADER_ONLY + : $(sources[1]:B)_header ] + ; +} + +rule chrono-compile2 ( sources : name ) +{ + return + [ compile $(sources) + : + : $(name)_lib ] + [ compile $(sources) + : BOOST_CHRONO_HEADER_ONLY + : $(name)_header ] + ; +} + + test-suite "perf" + : + [ chrono-run store_now_in_vector.cpp ] + ; + diff --git a/src/boost/libs/chrono/perf/store_now_in_vector.cpp b/src/boost/libs/chrono/perf/store_now_in_vector.cpp new file mode 100644 index 000000000..6c5c4bbaf --- /dev/null +++ b/src/boost/libs/chrono/perf/store_now_in_vector.cpp @@ -0,0 +1,153 @@ +// Copyright 2011 Vicente J. Botet Escriba +// Copyright (c) Microsoft Corporation 2014 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include + +//#define BOOST_CHRONO_HAS_TIMES_AND_CLOCK + +#ifdef BOOST_CHRONO_HAS_TIMES_AND_CLOCK +#include //for gettimeofday and timeval +#include //for times +#include +#endif + + +static const std::size_t size = 1000000; + +typedef boost::chrono::timer Stopwatch; + +template +void perf_constant(std::vector& vec) +{ + for (int i=size-1; i>=0; --i) + { + vec[i]=typename Clock::time_point(); + } +} + +template +void perf(std::vector& vec) +{ + for (int i=size-1; i>=0; --i) + { + vec[i]=Clock::now(); + } +} + +template +void test() +{ + std::vector vec(size); + Stopwatch sw1; + perf_constant(vec); + Stopwatch::duration t1 = sw1.elapsed(); + Stopwatch sw2; + perf(vec); + Stopwatch::duration t2 = sw2.elapsed(); + std::cout <<" "<< (t2-t1) << std::endl; + //std::cout <<" "<< ((t2-t1)/size) << std::endl; + std::size_t cnt=0; + for (int i=size-1; i>0; --i) + { + if (vec[i]!=vec[i-1]) ++cnt; + } + std::cout <<"changes: "<< cnt << std::endl; + +} + + + + + +#ifdef BOOST_CHRONO_HAS_TIMES_AND_CLOCK +void perf2(std::vector& vec) +{ + Stopwatch sw; + for (int i=size-1; i>=0; --i) + { + tms tm; + vec[i]=::times(&tm); + } + std::cout << sw.elapsed() << std::endl; +} + +void perf3(std::vector& vec) +{ + Stopwatch sw; + for (int i=size-1; i>=0; --i) + { + vec[i]=::clock(); + } + std::cout << sw.elapsed() << std::endl; +} + +void test2() +{ + std::vector vec(size); + perf2(vec); + std::size_t cnt=0; + for (int i=10; i>0; --i) + { + if (vec[i]!=vec[i-1]) ++cnt; + std::cout << vec[i] << " " ; + } + std::cout<< std::endl; + std::cout <<"changes: "<< cnt << std::endl; +} + +void test3() +{ + std::vector vec(size); + perf3(vec); + std::size_t cnt=0; + for (int i=10; i>0; --i) + { + if (vec[i]!=vec[i-1]) ++cnt; + std::cout << vec[i] << " " ; + } + std::cout<< std::endl; + std::cout <<"changes: "<< cnt << std::endl; +} + +#endif + +int main() { + + std::cout << "system_clock "; + test(); +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + std::cout << "steady_clock " ; + test(); +#endif + std::cout << "high_resolution_clock " ; + test(); + +#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS) + std::cout << "process_real_cpu_clock "; + test(); +#if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP + std::cout << "process_user_cpu_clock "; + test(); + std::cout << "process_system_cpu_clock " ; + test(); + std::cout << "process_cpu_clock " ; + test(); +#endif +#endif + std::cout << "system_clock "; + test(); +#if 0 + std::cout << "times "; + test2(); + std::cout << "clock "; + test3(); +#endif + return 1; +} diff --git a/src/boost/libs/chrono/src/chrono.cpp b/src/boost/libs/chrono/src/chrono.cpp new file mode 100644 index 000000000..f500a796c --- /dev/null +++ b/src/boost/libs/chrono/src/chrono.cpp @@ -0,0 +1,15 @@ +// chrono.cpp --------------------------------------------------------------// + +// Copyright Beman Dawes 2008 +// Copyright Vicente J. Botet Escriba 2009-2010 + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// define BOOST_CHRONO_SOURCE so that knows +// the library is being built (possibly exporting rather than importing code) + +#define BOOST_CHRONO_SOURCE + +#include + diff --git a/src/boost/libs/chrono/src/process_cpu_clocks.cpp b/src/boost/libs/chrono/src/process_cpu_clocks.cpp new file mode 100644 index 000000000..c21cab3b8 --- /dev/null +++ b/src/boost/libs/chrono/src/process_cpu_clocks.cpp @@ -0,0 +1,18 @@ +// boost process_cpu_clocks.cpp -----------------------------------------------------------// + +// Copyright 2009-2010 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See http://www.boost.org/libs/chrono for documentation. + +//--------------------------------------------------------------------------------------// + +// define BOOST_CHRONO_SOURCE so that knows +// the library is being built (possibly exporting rather than importing code) + +#define BOOST_CHRONO_SOURCE + +#include + diff --git a/src/boost/libs/chrono/src/thread_clock.cpp b/src/boost/libs/chrono/src/thread_clock.cpp new file mode 100644 index 000000000..c21b114c0 --- /dev/null +++ b/src/boost/libs/chrono/src/thread_clock.cpp @@ -0,0 +1,19 @@ +// boost thread_clock.cpp -----------------------------------------------------------// + +// Copyright 2010 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See http://www.boost.org/libs/chrono for documentation. + +//--------------------------------------------------------------------------------------// + + +// define BOOST_CHRONO_SOURCE so that knows +// the library is being built (possibly exporting rather than importing code) + +#define BOOST_CHRONO_SOURCE + +#include + diff --git a/src/boost/libs/chrono/sublibs b/src/boost/libs/chrono/sublibs new file mode 100644 index 000000000..e69de29bb diff --git a/src/boost/libs/chrono/test/Jamfile.v2 b/src/boost/libs/chrono/test/Jamfile.v2 new file mode 100644 index 000000000..7565d27b3 --- /dev/null +++ b/src/boost/libs/chrono/test/Jamfile.v2 @@ -0,0 +1,465 @@ +# Boost Chrono Library test Jamfile + +# Copyright Beman Dawes 2008 +# Copyright Vicente J. Botet Escriba 2009-2010 + +# Distributed under the Boost Software License, Version 1.0. +# See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt + +# See library home page at http://www.boost.org/libs/chrono + +import testing ; +import os ; +import feature ; + +project + : requirements + freebsd:"-lrt" + linux:"-lrt -lpthread" + clang/linux:"-lpthread" + pgi:"-lrt" + #single:BOOST_CHRONO_THREAD_DISABLED + msvc:on + BOOST_CHRONO_USES_MPL_ASSERT + #sun:BOOST_COMMON_TYPE_DONT_USE_TYPEOF + #sun:BOOST_TYPEOF_EMULATION + sun:__typeof__=__typeof__ + all + gcc:-Wextra + #gcc:-pedantic + clang:on + gcc:-Wno-long-long + gcc:-Wno-variadic-macros + darwin:-Wextra + darwin:-pedantic + darwin:-Wno-long-long + darwin:-Wno-variadic-macros + #pathscale:-Wextra + pathscale:-Wno-long-long + pathscale:-pedantic + clang:-Wextra + clang:-pedantic + clang:-Wno-long-long + clang:-Wno-variadic-macros + gcc-4.5.0,windows:-Wno-missing-field-initializers + gcc-4.5.0,windows:-fdiagnostics-show-option + msvc:/wd4127 + msvc:/wd4512 +# Note: Some of the remarks from the Intel compiler are disabled +# remark #193: zero used for undefined preprocessing identifier "XXX" +# remark #304: access control not specified ("public" by default) +# remark #383: value copied to temporary, reference to temporary used +# remark #444: destructor for base class "XXX" (declared at line YYY") is not virtual +# remark #593: variable "XXX" was set but never used +# remark #981: operands are evaluated in unspecified order +# remark #1418: external function definition with no prior declaration +# remark #2415: variable "XXX" of static storage duration was declared but never referenced + + intel:-wd193,304,383,444 + intel:-wd593,981 + intel:-wd1418 + intel:-wd2415 + ; + +rule chrono-run ( sources ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_d ] + #[ run $(sources) ../build//boost_chrono/static + # : : + # : + # : $(sources[1]:B)_s ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_h ] + ; +} + +rule chrono-runXXX ( sources ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_d ] + #[ run $(sources) ../build//boost_chrono/static + # : : + # : + # : $(sources[1]:B)_s ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_h ] + ; +} + + +rule chrono-v1-v2-run ( sources ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_d ] + [ run $(sources) ../build//boost_chrono/static + : : + : + : v1_$(sources[1]:B)_s ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_h ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + #BOOST_CHRONO_VERSION=1 + : v1_$(sources[1]:B)_h ] + ; +} + +rule chrono-run2 ( sources : name ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + BOOST_CHRONO_VERSION=2 + : $(name)_d ] + #[ run $(sources) ../build//boost_chrono/static + # : : + # : + # : $(name)_s ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + BOOST_CHRONO_VERSION=2 + : $(name)_h ] + ; +} + +rule date-run ( sources + ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_d ] + ; +} + +rule date-run-2 ( sources + : name ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + BOOST_CHRONO_VERSION=2 + : $(name)_d ] + ; +} + + +rule chrono-run-mt ( sources ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_d ] + #[ run $(sources) ../build//boost_chrono/static + # : : + # : + # : $(sources[1]:B)_s ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_h ] + ; +} +rule chrono-run2-mt ( sources * : name ) +{ + return + [ run $(sources) ../build//boost_chrono + : : + : + BOOST_CHRONO_VERSION=2 + : $(name)_d ] + #[ run $(sources) ../build//boost_chrono/static + # : : + # : + # : $(name)_s ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + BOOST_CHRONO_VERSION=2 + : $(name)_h ] + ; +} + +rule chrono-run-check ( sources ) +{ + return + [ run $(sources) + : : + : + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_d ] + [ run $(sources) + : : + : + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_s ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_h ] + ; +} + +rule chrono-run-check2 ( sources : name ) +{ + return + [ run $(sources) + : : + : + BOOST_CHRONO_VERSION=2 + : $(name)_d ] + [ run $(sources) + : : + : + BOOST_CHRONO_VERSION=2 + : $(name)_s ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + BOOST_CHRONO_VERSION=2 + : $(name)_h ] + ; +} + +rule chrono-run-header ( sources ) +{ + return + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_h ] + ; +} + +rule chrono-v1-v2-run-header ( sources ) +{ + return + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_h ] + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + : v1_$(sources[1]:B)_h ] + ; +} + +rule chrono-run-header2 ( sources : name ) +{ + return + [ run $(sources) + : : + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + BOOST_CHRONO_VERSION=2 + : $(name)_h ] + ; +} + +rule chrono-compile ( sources ) +{ + return + [ compile $(sources) + : + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_l ] + [ compile $(sources) + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + BOOST_CHRONO_VERSION=2 + : $(sources[1]:B)_h ] + ; +} + +rule chrono-compile2 ( sources : name ) +{ + return + [ compile $(sources) + : + BOOST_CHRONO_VERSION=2 + : $(name)_l ] + [ compile $(sources) + : BOOST_CHRONO_HEADER_ONLY + BOOST_ERROR_CODE_HEADER_ONLY + #BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + BOOST_CHRONO_VERSION=2 + : $(name)_h ] + ; +} + + + test-suite "examples" + : + [ chrono-run-header ../example/cycle_count.cpp ] + [ chrono-run-header ../example/runtime_resolution.cpp ] + [ chrono-run-header ../example/xtime.cpp ] + [ chrono-run-header ../example/saturating.cpp ] + [ chrono-run ../example/min_time_point.cpp ] + [ chrono-run-header ../example/i_dont_like_the_default_duration_behavior.cpp ] + [ chrono-run ../example/simulated_thread_interface_demo.cpp ] + [ chrono-run-header ../example/timeval_demo.cpp ] + [ chrono-run ../example/chrono_unit_test.cpp ] + [ chrono-run-header ../example/explore_limits.cpp ] + [ chrono-run-header ../example/test_duration.cpp ] + [ chrono-run ../example/test_clock.cpp ] + [ chrono-run-header ../example/miscellaneous.cpp ] + [ chrono-run-header ../example/test_special_values.cpp ] + [ chrono-run ../example/manipulate_clock_object.cpp ] + [ chrono-run-mt ../example/test_thread_clock.cpp ] + [ chrono-run-header ../example/rounding.cpp ] + #[ chrono-run ../example/await_keystroke.cpp ] + ; + + test-suite "traits" + : + [ chrono-compile2 traits/common_type_duration_pass.cpp : traits_common_type_duration_p ] + [ chrono-compile2 traits/common_type_time_point_pass.cpp : traits_common_type_time_point_p ] + [ chrono-compile2 traits/treat_as_floating_point_pass.cpp : traits_treat_as_floating_point_p ] + [ chrono-run-header2 traits/duration_values_pass.cpp : traits_duration_values_p ] + ; + + test-suite "duration" + : + [ compile-fail duration/duration_duration_fail.cpp ] + [ compile-fail duration/ratio_fail.cpp ] + [ compile-fail duration/positive_num_fail.cpp ] + [ chrono-compile duration/default_ratio_pass.cpp ] + [ chrono-compile duration/types_pass.cpp ] + [ chrono-compile duration/ratio_alias_pass.cpp ] + [ chrono-compile duration/typedefs_pass.cpp ] + [ chrono-run-header duration/arithmetic_pass.cpp ] + [ chrono-run-header duration/duration_cast_pass.cpp ] + [ compile-fail duration/duration_cast_int_fail.cpp ] + [ chrono-run-header duration/comparisons_pass.cpp ] + [ chrono-run-header duration/constructor_pass.cpp ] + [ compile-fail duration/cons/convert_float_to_int_fail.cpp ] + [ compile-fail duration/cons/convert_inexact_fail.cpp ] + [ compile-fail duration/cons/implicit_constructot_fail.cpp ] + [ compile-fail duration/cons/non_implicit_convertible_rep_fail.cpp ] + [ compile-fail duration/cons/treat_as_floating_point_Rep2_true_fail.cpp ] + [ compile-fail duration/nonmember/divide_rep2_fail.cpp ] + [ compile-fail duration/nonmember/modulus_rep2_fail.cpp ] + [ compile-fail duration/nonmember/times_rep2_lhs_fail.cpp ] + [ compile-fail duration/nonmember/times_rep2_rhs_fail.cpp ] + [ chrono-run-header duration/duration_values_pass.cpp ] + [ chrono-run-header duration/rounding_pass.cpp ] + ; + + test-suite "time_point" + : + [ chrono-compile2 time_point/default_duration_pass.cpp : time_point_default_duration_p ] + [ compile-fail time_point/not_duration_fail.cpp : : time_point_not_duration_f ] + [ chrono-run-header2 time_point/arithmetic_pass.cpp : time_point_arithmetic_p ] + [ chrono-run-header2 time_point/arithmetic_ext_pass.cpp : time_point_arithmetic_ext_p ] + [ chrono-run-header2 time_point/time_point_cast_pass.cpp : time_point_time_point_cast_p ] + [ compile-fail time_point/time_point_cast_int_fail.cpp : : time_point_time_point_cast_int_f ] + [ chrono-run-header2 time_point/comparisons_pass.cpp : time_point_comparisons_p ] + [ compile-fail time_point/comparisons/equal_fail.cpp : : time_point_equal_f ] + [ compile-fail time_point/comparisons/less_fail.cpp : : time_point_less_f ] + [ chrono-run-header2 time_point/constructor_pass.cpp : time_point_constructor_p ] + [ compile-fail time_point/cons/implicit_fail.cpp : : time_point_implicit_f ] + [ compile-fail time_point/cons/non_implicit_convertible_duration_fail.cpp : : time_point_non_implicit_convertible_duration_f ] + [ chrono-run-header2 time_point/min_max_pass.cpp : time_point_min_max_p ] + ; + + test-suite "clock" + : + [ chrono-run2-mt clock/clock_pass.cpp : clock_clock_p ] + [ chrono-run2-mt one_obj.cpp another_obj.cpp : two_obj_p ] + ; + + test-suite "io_ex" + : + [ chrono-v1-v2-run ../example/io_ex1.cpp ] + [ chrono-v1-v2-run-header ../example/io_ex2.cpp ] + [ chrono-v1-v2-run ../example/io_ex3.cpp ] + [ chrono-v1-v2-run ../example/io_ex4.cpp ] + [ chrono-v1-v2-run ../example/io_ex5.cpp ] + [ chrono-v1-v2-run ../example/french.cpp ] + ; + + test-suite "io" + : + [ chrono-v1-v2-run-header io/duration_input.cpp ] + [ chrono-v1-v2-run-header io/duration_output.cpp ] + [ chrono-v1-v2-run-header io/time_point_input.cpp ] + [ chrono-v1-v2-run-header io/time_point_output.cpp ] + [ chrono-run test_7868.cpp ] + [ chrono-run test_11006.cpp ] + [ chrono-run test_11012.cpp ] + [ chrono-runXXX test_12176.cpp ] + ; + + test-suite "win32" + : + [ chrono-run win32_test.cpp ] + ; + + explicit ts_ ; + test-suite ts_ + : + #[ chrono-run test_7868.cpp ] + #[ chrono-run test_9337.cpp ] + #[ chrono-run test_10778.cpp ] + [ chrono-run test_10631.cpp ] + ; + diff --git a/src/boost/libs/chrono/test/another_obj.cpp b/src/boost/libs/chrono/test/another_obj.cpp new file mode 100644 index 000000000..8ebf67720 --- /dev/null +++ b/src/boost/libs/chrono/test/another_obj.cpp @@ -0,0 +1,19 @@ +// boost win32_test.cpp -----------------------------------------------------// + +// Copyright 2010 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See http://www.boost.org/libs/chrono for documentation. +#include +#include +#include + +void another() { + boost::chrono::steady_clock::time_point t1=boost::chrono::steady_clock::now(); + boost::chrono::steady_clock::time_point t2=boost::chrono::steady_clock::now(); + std::cout << t2-t1 << std::endl; + return ; +} + diff --git a/src/boost/libs/chrono/test/clock.h b/src/boost/libs/chrono/test/clock.h new file mode 100644 index 000000000..3fd8eb55b --- /dev/null +++ b/src/boost/libs/chrono/test/clock.h @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#ifndef CLOCK_H +#define CLOCK_H + +#include + +class Clock +{ + typedef boost::chrono::nanoseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef boost::chrono::time_point time_point; + static const bool is_steady = false; + + static time_point now(); +}; + +#endif // CLOCK_H diff --git a/src/boost/libs/chrono/test/clock/clock_pass.cpp b/src/boost/libs/chrono/test/clock/clock_pass.cpp new file mode 100644 index 000000000..d19db1667 --- /dev/null +++ b/src/boost/libs/chrono/test/clock/clock_pass.cpp @@ -0,0 +1,201 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Copyright (c) Microsoft Corporation 2014 +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include +#include + +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +template +void check_clock_invariants() +{ + BOOST_CHRONO_STATIC_ASSERT((boost::is_same::value), NOTHING, ()); + BOOST_CHRONO_STATIC_ASSERT((boost::is_same::value), NOTHING, ()); + BOOST_CHRONO_STATIC_ASSERT((boost::is_same::value), NOTHING, ()); + BOOST_CHRONO_STATIC_ASSERT(Clock::is_steady || !Clock::is_steady, NOTHING, ()); + // to be replaced by has static member bool is_steady +} + +template +void check_clock_now() +{ + typename Clock::time_point t1 = Clock::now(); + (void)t1; +} + +#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + +template +void check_clock_now_ec() +{ + boost::system::error_code ec; + typename Clock::time_point t1 = Clock::now(ec); + (void)t1; + BOOST_TEST(ec.value()==0); +} + +template +void check_clock_now_throws() +{ + typename Clock::time_point t1 = Clock::now(boost::throws()); + (void)t1; +} + +#ifndef BOOST_NO_EXCEPTIONS + +template +void check_clock_now_err(int err) +{ + Clock::set_errno(err); + try { + typename Clock::time_point t1 = Clock::now(); + } catch (boost::system::system_error& ex) { + BOOST_TEST(ex.code().value()==err); +// BOOST_TEST(ex.code().category() == ::boost::system::system_category()); +// BOOST_TEST(std::string(ex.what()) == std::string("errored_clock")); + } + Clock::set_errno(0); +} +#endif + +template +void check_clock_now_ec_err(int err) +{ + Clock::set_errno(err); + boost::system::error_code ec; + typename Clock::time_point t1 = Clock::now(ec); + BOOST_TEST(ec.value()==err); +// BOOST_TEST(ec.category() == ::boost::system::system_category()); + Clock::set_errno(0); +} + +#ifndef BOOST_NO_EXCEPTIONS +template +void check_clock_now_throws_err(int err) +{ + Clock::set_errno(err); + try { + typename Clock::time_point t1 = Clock::now(boost::throws()); + BOOST_TEST(0&&"exception not thown"); + } catch (boost::system::system_error& ex) { + BOOST_TEST(ex.code().value()==err); +// BOOST_TEST(ex.code().category() == ::boost::system::system_category()); +// BOOST_TEST(std::string(ex.what()) == std::string("errored_clock")); + } + Clock::set_errno(0); +} +#endif +#endif + +int main() +{ + check_clock_invariants(); + check_clock_now(); + +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + check_clock_invariants(); + BOOST_CHRONO_STATIC_ASSERT(boost::chrono::steady_clock::is_steady, NOTHING, ()); + check_clock_now(); +#endif + + check_clock_invariants(); + BOOST_CHRONO_STATIC_ASSERT(!boost::chrono::system_clock::is_steady, NOTHING, ()); + check_clock_now(); + { + typedef boost::chrono::system_clock C; + C::time_point t1 = C::from_time_t(C::to_time_t(C::now())); + (void)t1; + } + { + typedef boost::chrono::system_clock C; + std::time_t t1 = C::to_time_t(C::now()); + (void)t1; + + } + { + BOOST_TEST((boost::chrono::system_clock::duration::min)() < + boost::chrono::system_clock::duration::zero()); + + } + +#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) + check_clock_invariants(); + BOOST_CHRONO_STATIC_ASSERT(boost::chrono::thread_clock::is_steady, NOTHING, ()); + check_clock_now(); +#endif + +#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS) + check_clock_invariants(); + BOOST_CHRONO_STATIC_ASSERT(boost::chrono::process_real_cpu_clock::is_steady, NOTHING, ()); + check_clock_now(); + +#if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP + check_clock_invariants(); + BOOST_CHRONO_STATIC_ASSERT(boost::chrono::process_user_cpu_clock::is_steady, NOTHING, ()); + check_clock_now(); + + check_clock_invariants(); + BOOST_CHRONO_STATIC_ASSERT(boost::chrono::process_system_cpu_clock::is_steady, NOTHING, ()); + check_clock_now(); + + check_clock_invariants(); + BOOST_CHRONO_STATIC_ASSERT(boost::chrono::process_cpu_clock::is_steady, NOTHING, ()); + check_clock_now(); +#endif +#endif + + +#if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING + check_clock_now_ec(); + check_clock_now_throws(); + +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + check_clock_now_ec(); + check_clock_now_throws(); +#endif + + check_clock_now_ec(); + check_clock_now_throws(); + +#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) + check_clock_now_ec(); + check_clock_now_throws(); +#endif + +#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS) + check_clock_now_ec(); + check_clock_now_throws(); + +#if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP + check_clock_now_ec(); + check_clock_now_throws(); + + check_clock_now_ec(); + check_clock_now_throws(); + + check_clock_now_ec(); + check_clock_now_throws(); +#endif +#endif + +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/clock/errored_clock.hpp b/src/boost/libs/chrono/test/clock/errored_clock.hpp new file mode 100644 index 000000000..d9e80e87a --- /dev/null +++ b/src/boost/libs/chrono/test/clock/errored_clock.hpp @@ -0,0 +1,62 @@ +// errored_clock.hpp --------------------------------------------------------------// + +// Copyright 2010 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#ifndef BOOST_CHRONO_ERRORED_CLOCKS_HPP +#define BOOST_CHRONO_ERRORED_CLOCKS_HPP + +#include +#include +#include +#include +#include +#include +#include + + class errored_clock + { + public: + typedef boost::chrono::nanoseconds duration; + typedef duration::rep rep; + typedef duration::period period; + typedef boost::chrono::time_point time_point; + static const bool is_steady = true; + static int errno_; + + static void set_errno(int err) { + errno_=err; + } + + // throws on error + static time_point now() { + boost::throw_exception( + boost::system::system_error( + errno_, + ::boost::system::system_category(), + "errored_clock" + ) + ); + return time_point(); + } + // never throws and set ec + static time_point now(boost::system::error_code & ec) { + if (::boost::chrono::is_throws(ec)) + { + boost::throw_exception( + boost::system::system_error( + errno_, + ::boost::system::system_category(), + "errored_clock" + ) + ); + } + ec.assign( errno_, ::boost::system::system_category() ); + return time_point(); + }; + }; + int errored_clock::errno_; + +#endif diff --git a/src/boost/libs/chrono/test/duration/arithmetic_pass.cpp b/src/boost/libs/chrono/test/duration/arithmetic_pass.cpp new file mode 100644 index 000000000..521ca644d --- /dev/null +++ b/src/boost/libs/chrono/test/duration/arithmetic_pass.cpp @@ -0,0 +1,350 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include + +#include +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + +int main() +{ + // Default construct + { + //BOOST_CONSTEXPR + boost::chrono::minutes m; + //BOOST_CONSTEXPR_ASSERT(m.count() == 0); + (void)m; + } + + // UNARY PLUS + { + boost::chrono::minutes m(3); + boost::chrono::minutes m2 = +m; + BOOST_TEST(m.count() == m2.count()); + } + { + BOOST_CONSTEXPR boost::chrono::minutes m(3); + BOOST_CONSTEXPR boost::chrono::minutes m2(+m); + BOOST_CONSTEXPR_ASSERT(m.count() == m2.count()); + } + + // UNARY MINUS + { + boost::chrono::minutes m(3); + boost::chrono::minutes m2 = -m; + BOOST_TEST(m2.count() == -m.count()); + } + { + BOOST_CONSTEXPR boost::chrono::minutes m(3); + BOOST_CONSTEXPR boost::chrono::minutes m2 = -m; + BOOST_CONSTEXPR_ASSERT(m2.count() == -m.count()); + } + // PRE INCREMENT + { + boost::chrono::hours h(3); + boost::chrono::hours& href = ++h; + BOOST_TEST(&href == &h); + BOOST_TEST(h.count() == 4); + } + // POST INCREMENT + { + boost::chrono::hours h(3); + boost::chrono::hours h2 = h++; + BOOST_TEST(h.count() == 4); + BOOST_TEST(h2.count() == 3); + } + // PRE DECREMENT + { + boost::chrono::hours h(3); + boost::chrono::hours& href = --h; + BOOST_TEST(&href == &h); + BOOST_TEST(h.count() == 2); + } + // POST DECREMENT + { + boost::chrono::hours h(3); + boost::chrono::hours h2 = h--; + BOOST_TEST(h.count() == 2); + BOOST_TEST(h2.count() == 3); + } + // PLUS ASSIGN + { + boost::chrono::seconds s(3); + s += boost::chrono::seconds(2); + BOOST_TEST(s.count() == 5); + s += boost::chrono::minutes(2); + BOOST_TEST(s.count() == 125); + } + // MINUS ASSIGN + { + boost::chrono::seconds s(3); + s -= boost::chrono::seconds(2); + BOOST_TEST(s.count() == 1); + s -= boost::chrono::minutes(2); + BOOST_TEST(s.count() == -119); + } + // TIMES ASSIGN + { + boost::chrono::nanoseconds ns(3); + ns *= 5; + BOOST_TEST(ns.count() == 15); + } + // DIVIDE ASSIGN + { + boost::chrono::nanoseconds ns(15); + ns /= 5; + BOOST_TEST(ns.count() == 3); + } + // MODULUS ASSIGN duration + { + boost::chrono::microseconds us(11); + boost::chrono::microseconds us2(3); + us %= us2; + BOOST_TEST(us.count() == 2); + us %= boost::chrono::milliseconds(3); + BOOST_TEST(us.count() == 2); + } + // MODULUS ASSIGN Rep + { + boost::chrono::microseconds us(11); + us %= 3; + BOOST_TEST(us.count() == 2); + } + // PLUS + { + boost::chrono::seconds s1(3); + boost::chrono::seconds s2(5); + boost::chrono::seconds r = s1 + s2; + BOOST_TEST(r.count() == 8); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::seconds s2(5); + BOOST_CONSTEXPR boost::chrono::seconds r = s1 + s2; + BOOST_CONSTEXPR_ASSERT(r.count() == 8); + } + { + boost::chrono::seconds s1(3); + boost::chrono::microseconds s2(5); + boost::chrono::microseconds r = s1 + s2; + BOOST_TEST(r.count() == 3000005); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::microseconds s2(5); + BOOST_CONSTEXPR boost::chrono::microseconds r = s1 + s2; + BOOST_CONSTEXPR_ASSERT(r.count() == 3000005); + } + { + boost::chrono::duration > s1(3); + boost::chrono::duration > s2(5); + boost::chrono::duration > r = s1 + s2; + BOOST_TEST(r.count() == 75); + } + { + BOOST_CONSTEXPR boost::chrono::duration > s1(3); + BOOST_CONSTEXPR boost::chrono::duration > s2(5); + BOOST_CONSTEXPR boost::chrono::duration > r = s1 + s2; + BOOST_CONSTEXPR_ASSERT(r.count() == 75); + } + { + boost::chrono::duration > s1(3); + boost::chrono::duration > s2(5); + boost::chrono::duration > r = s1 + s2; + BOOST_TEST(r.count() == 75); + } + { + BOOST_CONSTEXPR boost::chrono::duration > s1(3); + BOOST_CONSTEXPR boost::chrono::duration > s2(5); + BOOST_CONSTEXPR boost::chrono::duration > r = s1 + s2; + BOOST_CONSTEXPR_ASSERT(r.count() == 75); + } + + // MINUS + { + boost::chrono::seconds s1(3); + boost::chrono::seconds s2(5); + boost::chrono::seconds r = s1 - s2; + BOOST_TEST(r.count() == -2); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::seconds s2(5); + BOOST_CONSTEXPR boost::chrono::seconds r = s1 - s2; + BOOST_CONSTEXPR_ASSERT(r.count() == -2); + } + { + boost::chrono::seconds s1(3); + boost::chrono::microseconds s2(5); + boost::chrono::microseconds r = s1 - s2; + BOOST_TEST(r.count() == 2999995); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::microseconds s2(5); + BOOST_CONSTEXPR boost::chrono::microseconds r = s1 - s2; + BOOST_CONSTEXPR_ASSERT(r.count() == 2999995); + } + { + boost::chrono::duration > s1(3); + boost::chrono::duration > s2(5); + boost::chrono::duration > r = s1 - s2; + BOOST_TEST(r.count() == -15); + } + { + BOOST_CONSTEXPR boost::chrono::duration > s1(3); + BOOST_CONSTEXPR boost::chrono::duration > s2(5); + BOOST_CONSTEXPR boost::chrono::duration > r = s1 - s2; + BOOST_CONSTEXPR_ASSERT(r.count() == -15); + } + { + boost::chrono::duration > s1(3); + boost::chrono::duration > s2(5); + boost::chrono::duration > r = s1 - s2; + BOOST_TEST(r.count() == -15); + } + { + BOOST_CONSTEXPR boost::chrono::duration > s1(3); + BOOST_CONSTEXPR boost::chrono::duration > s2(5); + BOOST_CONSTEXPR boost::chrono::duration > r = s1 - s2; + BOOST_CONSTEXPR_ASSERT(r.count() == -15); + } + + // TIMES rep + { + boost::chrono::nanoseconds ns(3); + boost::chrono::nanoseconds ns2 = ns * 5; + BOOST_TEST(ns2.count() == 15); + boost::chrono::nanoseconds ns3 = 6 * ns2; + BOOST_TEST(ns3.count() == 90); + } + { + BOOST_CONSTEXPR boost::chrono::nanoseconds ns(3); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2 = ns * 5; + BOOST_CONSTEXPR_ASSERT(ns2.count() == 15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns3 = 6 * ns2; + BOOST_CONSTEXPR_ASSERT(ns3.count() == 90); + } + + // DIVIDE duration + { + boost::chrono::nanoseconds ns1(15); + boost::chrono::nanoseconds ns2(5); + BOOST_TEST(ns1 / ns2 == 3); + } + { + BOOST_CONSTEXPR boost::chrono::nanoseconds ns1(15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2(5); + BOOST_CONSTEXPR_ASSERT(ns1 / ns2 == 3); + } + { + boost::chrono::microseconds us1(15); + boost::chrono::nanoseconds ns2(5); + BOOST_TEST(us1 / ns2 == 3000); + } + { + BOOST_CONSTEXPR boost::chrono::microseconds us1(15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2(5); + BOOST_CONSTEXPR_ASSERT(us1 / ns2 == 3000); + } + { + boost::chrono::duration > s1(30); + boost::chrono::duration > s2(5); + BOOST_TEST(s1 / s2 == 6); + } + { + BOOST_CONSTEXPR boost::chrono::duration > s1(30); + BOOST_CONSTEXPR boost::chrono::duration > s2(5); + BOOST_CONSTEXPR_ASSERT(s1 / s2 == 6); + } + { + boost::chrono::duration > s1(30); + boost::chrono::duration > s2(5); + //BOOST_TEST(s1 / s2 == 20. / 3); + BOOST_TEST(3 * s1 == 20 * s2); + } + { + BOOST_CONSTEXPR boost::chrono::duration > s1(30); + BOOST_CONSTEXPR boost::chrono::duration > s2(5); + //BOOST_CONSTEXPR_ASSERT(s1 / s2 == 20. / 3); + BOOST_TEST(3 * s1 == 20 * s2); + } + // DIVIDE rep + { + boost::chrono::nanoseconds ns(15); + boost::chrono::nanoseconds ns2 = ns / 5; + BOOST_TEST(ns2.count() == 3); + } + { + BOOST_CONSTEXPR boost::chrono::nanoseconds ns(15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2 = ns / 5; + BOOST_CONSTEXPR_ASSERT(ns2.count() == 3); + } + + // MODULUS duration + + { + boost::chrono::nanoseconds ns1(15); + boost::chrono::nanoseconds ns2(6); + boost::chrono::nanoseconds r = ns1 % ns2; + BOOST_TEST(r.count() == 3); + } + { + BOOST_CONSTEXPR boost::chrono::nanoseconds ns1(15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2(6); + BOOST_CONSTEXPR boost::chrono::nanoseconds r = ns1 % ns2; + BOOST_CONSTEXPR_ASSERT(r.count() == 3); + } + { + boost::chrono::microseconds us1(15); + boost::chrono::nanoseconds ns2(28); + boost::chrono::nanoseconds r = us1 % ns2; + BOOST_TEST(r.count() == 20); + } + { + BOOST_CONSTEXPR boost::chrono::microseconds us1(15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2(28); + BOOST_CONSTEXPR boost::chrono::nanoseconds r = us1 % ns2; + BOOST_CONSTEXPR_ASSERT(r.count() == 20); + } + { + boost::chrono::duration > s1(6); + boost::chrono::duration > s2(3); + boost::chrono::duration > r = s1 % s2; + BOOST_TEST(r.count() == 24); + } + { + BOOST_CONSTEXPR boost::chrono::duration > s1(6); + BOOST_CONSTEXPR boost::chrono::duration > s2(3); + BOOST_CONSTEXPR boost::chrono::duration > r = s1 % s2; + BOOST_CONSTEXPR_ASSERT(r.count() == 24); + } + // MODULUS rep + { + boost::chrono::nanoseconds ns(15); + boost::chrono::nanoseconds ns2 = ns % 6; + BOOST_TEST(ns2.count() == 3); + } + { + BOOST_CONSTEXPR boost::chrono::nanoseconds ns(15); + BOOST_CONSTEXPR boost::chrono::nanoseconds ns2 = ns % 6; + BOOST_CONSTEXPR_ASSERT(ns2.count() == 3); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/duration/comparisons_pass.cpp b/src/boost/libs/chrono/test/duration/comparisons_pass.cpp new file mode 100644 index 000000000..79deaaa11 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/comparisons_pass.cpp @@ -0,0 +1,222 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + +int main() +{ + { + boost::chrono::seconds s1(3); + boost::chrono::seconds s2(3); + BOOST_TEST(s1 == s2); + BOOST_TEST(! (s1 != s2)); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::seconds s2(3); + BOOST_CONSTEXPR_ASSERT(s1 == s2); + BOOST_CONSTEXPR_ASSERT(!(s1 != s2)); + } + { + boost::chrono::seconds s1(3); + boost::chrono::seconds s2(4); + BOOST_TEST(! (s1 == s2)); + BOOST_TEST(s1 != s2); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::seconds s2(4); + BOOST_CONSTEXPR_ASSERT(! (s1 == s2)); + BOOST_CONSTEXPR_ASSERT(s1 != s2); + } + { + boost::chrono::milliseconds s1(3); + boost::chrono::microseconds s2(3000); + BOOST_TEST(s1 == s2); + BOOST_TEST(! (s1 != s2)); + } + { + BOOST_CONSTEXPR boost::chrono::milliseconds s1(3); + BOOST_CONSTEXPR boost::chrono::microseconds s2(3000); + BOOST_CONSTEXPR_ASSERT(s1 == s2); + BOOST_CONSTEXPR_ASSERT(! (s1 != s2)); + } + { + boost::chrono::milliseconds s1(3); + boost::chrono::microseconds s2(4000); + BOOST_TEST(! (s1 == s2)); + BOOST_TEST(s1 != s2); + } + { + BOOST_CONSTEXPR boost::chrono::milliseconds s1(3); + BOOST_CONSTEXPR boost::chrono::microseconds s2(4000); + BOOST_CONSTEXPR_ASSERT(! (s1 == s2)); + BOOST_CONSTEXPR_ASSERT(s1 != s2); + } + { + boost::chrono::duration > s1(9); + boost::chrono::duration > s2(10); + BOOST_TEST(s1 == s2); + BOOST_TEST(! (s1 != s2)); + } + { + BOOST_CONSTEXPR boost::chrono::duration > s1(9); + BOOST_CONSTEXPR boost::chrono::duration > s2(10); + BOOST_CONSTEXPR_ASSERT(s1 == s2); + BOOST_CONSTEXPR_ASSERT(! (s1 != s2)); + } + { + boost::chrono::duration > s1(10); + boost::chrono::duration > s2(9); + BOOST_TEST(! (s1 == s2)); + BOOST_TEST(s1 != s2); + } + { + BOOST_CONSTEXPR boost::chrono::duration > s1(10); + BOOST_CONSTEXPR boost::chrono::duration > s2(9); + BOOST_CONSTEXPR_ASSERT(! (s1 == s2)); + BOOST_CONSTEXPR_ASSERT(s1 != s2); + } + { + boost::chrono::duration > s1(9); + boost::chrono::duration > s2(10); + BOOST_TEST(s1 == s2); + BOOST_TEST(! (s1 != s2)); + } + { + BOOST_CONSTEXPR boost::chrono::duration > s1(9); + BOOST_CONSTEXPR boost::chrono::duration > s2(10); + BOOST_CONSTEXPR_ASSERT(s1 == s2); + BOOST_CONSTEXPR_ASSERT(! (s1 != s2)); + } + { + boost::chrono::seconds s1(3); + boost::chrono::seconds s2(3); + BOOST_TEST(! (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST( (s1 <= s2)); + BOOST_TEST( (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::seconds s2(3); + BOOST_CONSTEXPR_ASSERT(! (s1 < s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 > s2)); + BOOST_CONSTEXPR_ASSERT( (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT( (s1 >= s2)); + } + { + boost::chrono::seconds s1(3); + boost::chrono::seconds s2(4); + BOOST_TEST( (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST( (s1 <= s2)); + BOOST_TEST(! (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::seconds s1(3); + BOOST_CONSTEXPR boost::chrono::seconds s2(4); + BOOST_CONSTEXPR_ASSERT( (s1 < s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 > s2)); + BOOST_CONSTEXPR_ASSERT( (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 >= s2)); + } + { + boost::chrono::milliseconds s1(3); + boost::chrono::microseconds s2(3000); + BOOST_TEST(! (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST( (s1 <= s2)); + BOOST_TEST( (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::milliseconds s1(3); + BOOST_CONSTEXPR boost::chrono::microseconds s2(3000); + BOOST_CONSTEXPR_ASSERT(! (s1 < s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 > s2)); + BOOST_CONSTEXPR_ASSERT( (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT( (s1 >= s2)); + } + { + boost::chrono::milliseconds s1(3); + boost::chrono::microseconds s2(4000); + BOOST_TEST( (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST( (s1 <= s2)); + BOOST_TEST(! (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::milliseconds s1(3); + BOOST_CONSTEXPR boost::chrono::microseconds s2(4000); + BOOST_CONSTEXPR_ASSERT( (s1 < s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 > s2)); + BOOST_CONSTEXPR_ASSERT( (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 >= s2)); + } + { + boost::chrono::duration > s1(9); + boost::chrono::duration > s2(10); + BOOST_TEST(! (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST( (s1 <= s2)); + BOOST_TEST( (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::duration > s1(9); + BOOST_CONSTEXPR boost::chrono::duration > s2(10); + BOOST_CONSTEXPR_ASSERT(! (s1 < s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 > s2)); + BOOST_CONSTEXPR_ASSERT( (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT( (s1 >= s2)); + } + { + boost::chrono::duration > s1(10); + boost::chrono::duration > s2(9); + BOOST_TEST(! (s1 < s2)); + BOOST_TEST( (s1 > s2)); + BOOST_TEST(! (s1 <= s2)); + BOOST_TEST( (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::duration > s1(10); + BOOST_CONSTEXPR boost::chrono::duration > s2(9); + BOOST_CONSTEXPR_ASSERT(! (s1 < s2)); + BOOST_CONSTEXPR_ASSERT( (s1 > s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT( (s1 >= s2)); + } + { + boost::chrono::duration > s1(9); + boost::chrono::duration > s2(10); + BOOST_TEST(! (s1 < s2)); + BOOST_TEST(! (s1 > s2)); + BOOST_TEST( (s1 <= s2)); + BOOST_TEST( (s1 >= s2)); + } + { + BOOST_CONSTEXPR boost::chrono::duration > s1(9); + BOOST_CONSTEXPR boost::chrono::duration > s2(10); + BOOST_CONSTEXPR_ASSERT(! (s1 < s2)); + BOOST_CONSTEXPR_ASSERT(! (s1 > s2)); + BOOST_CONSTEXPR_ASSERT( (s1 <= s2)); + BOOST_CONSTEXPR_ASSERT( (s1 >= s2)); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/duration/cons/convert_float_to_int_fail.cpp b/src/boost/libs/chrono/test/duration/cons/convert_float_to_int_fail.cpp new file mode 100644 index 000000000..f30240103 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/cons/convert_float_to_int_fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// conversions from floating point to integral durations disallowed + +#include + +void test() +{ + boost::chrono::duration d; + boost::chrono::duration i = d; +} diff --git a/src/boost/libs/chrono/test/duration/cons/convert_inexact_fail.cpp b/src/boost/libs/chrono/test/duration/cons/convert_inexact_fail.cpp new file mode 100644 index 000000000..a912daa05 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/cons/convert_inexact_fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// inexact conversions disallowed for integral reps + +#include + +void test() +{ + boost::chrono::microseconds us(1); + boost::chrono::milliseconds ms = us; +} diff --git a/src/boost/libs/chrono/test/duration/cons/implicit_constructot_fail.cpp b/src/boost/libs/chrono/test/duration/cons/implicit_constructot_fail.cpp new file mode 100644 index 000000000..72ea507b7 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/cons/implicit_constructot_fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// test for explicit + +#include + +#include "../../rep.h" + +void test() +{ + boost::chrono::duration d = 1; +} diff --git a/src/boost/libs/chrono/test/duration/cons/non_implicit_convertible_rep_fail.cpp b/src/boost/libs/chrono/test/duration/cons/non_implicit_convertible_rep_fail.cpp new file mode 100644 index 000000000..0be0a589f --- /dev/null +++ b/src/boost/libs/chrono/test/duration/cons/non_implicit_convertible_rep_fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// Rep2 shall be implicitly convertible to rep + +#include + +#include "../../rep.h" + +void test() +{ + boost::chrono::duration d(1); +} diff --git a/src/boost/libs/chrono/test/duration/cons/treat_as_floating_point_Rep2_true_fail.cpp b/src/boost/libs/chrono/test/duration/cons/treat_as_floating_point_Rep2_true_fail.cpp new file mode 100644 index 000000000..47c8b2e0c --- /dev/null +++ b/src/boost/libs/chrono/test/duration/cons/treat_as_floating_point_Rep2_true_fail.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// treat_as_floating_point::value must be false + +#include + +void test() +{ + boost::chrono::duration d(1.); +} diff --git a/src/boost/libs/chrono/test/duration/constructor_pass.cpp b/src/boost/libs/chrono/test/duration/constructor_pass.cpp new file mode 100644 index 000000000..54b76b701 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/constructor_pass.cpp @@ -0,0 +1,134 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + + +#include +#include + + +#include "../rep.h" +#include + +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + +template +void +check_default() +{ + { + D d; + BOOST_TEST(d.count() == typename D::rep()); + } +} +template +void +check_constexpr() +{ + BOOST_CONSTEXPR D d(0); + BOOST_CONSTEXPR_ASSERT(d.count() == typename D::rep()); +} + +template +void +check_from_rep(R r) +{ + { + D d(r); + BOOST_TEST(d.count() == r); + } +} + +int main() +{ + // exact conversions allowed for integral reps + { + boost::chrono::milliseconds ms(1); + boost::chrono::microseconds us = ms; + BOOST_TEST(us.count() == 1000); + { + BOOST_CONSTEXPR boost::chrono::milliseconds ms(1); + BOOST_CONSTEXPR boost::chrono::microseconds us = ms; + BOOST_CONSTEXPR_ASSERT(us.count() == 1000); + } + } + // inexact conversions allowed for floating point reps + { + boost::chrono::duration us(1); + boost::chrono::duration ms = us; + BOOST_TEST(ms.count() == 1./1000); + { + BOOST_CONSTEXPR boost::chrono::duration us(1); + BOOST_CONSTEXPR boost::chrono::duration ms = us; + BOOST_CONSTEXPR_ASSERT(ms.count() == 1./1000); + } + } + // Convert int to float + { + boost::chrono::duration i(3); + boost::chrono::duration d = i; + BOOST_TEST(d.count() == 3); + { + BOOST_CONSTEXPR boost::chrono::duration i(3); + BOOST_CONSTEXPR boost::chrono::duration d = i; + BOOST_CONSTEXPR_ASSERT(d.count() == 3); + } + } + // default constructor + { + check_default >(); + } + { + check_constexpr >(); + } + // constructor from rep + { + check_from_rep >(5); + { + BOOST_CONSTEXPR boost::chrono::duration d(5); + BOOST_CONSTEXPR_ASSERT(d.count() == 5); + } + check_from_rep > >(5); + { + BOOST_CONSTEXPR boost::chrono::duration > d(5); + BOOST_CONSTEXPR_ASSERT(d.count() == 5); + } + check_from_rep > >(Rep(3)); + { + BOOST_CONSTEXPR boost::chrono::duration > d(Rep(3)); + BOOST_CONSTEXPR_ASSERT(d.count() == Rep(3)); + } + check_from_rep > >(5.5); + { + BOOST_CONSTEXPR boost::chrono::duration > d(5.5); + BOOST_CONSTEXPR_ASSERT(d.count() == 5.5); + } + + + } + // constructor from other rep + { + boost::chrono::duration d(5); + BOOST_TEST(d.count() == 5); + { + BOOST_CONSTEXPR boost::chrono::duration d(5); + BOOST_CONSTEXPR_ASSERT(d.count() == 5); + } + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/duration/default_ratio_pass.cpp b/src/boost/libs/chrono/test/duration/default_ratio_pass.cpp new file mode 100644 index 000000000..1d8ad3a24 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/default_ratio_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// duration +// Test default template arg: + +// template > +// class duration; + +#include +#include +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +BOOST_CHRONO_STATIC_ASSERT((boost::is_same< + boost::chrono::duration >, + boost::chrono::duration +>::value), NOTHING, ()); diff --git a/src/boost/libs/chrono/test/duration/duration_cast_int_fail.cpp b/src/boost/libs/chrono/test/duration/duration_cast_int_fail.cpp new file mode 100644 index 000000000..77b03b74c --- /dev/null +++ b/src/boost/libs/chrono/test/duration/duration_cast_int_fail.cpp @@ -0,0 +1,21 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// ToDuration must be an instantiation of duration. + +#include + +void test() +{ + boost::chrono::duration_cast(boost::chrono::milliseconds(3)); +} diff --git a/src/boost/libs/chrono/test/duration/duration_cast_pass.cpp b/src/boost/libs/chrono/test/duration/duration_cast_pass.cpp new file mode 100644 index 000000000..0364faa36 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/duration_cast_pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + + +template +void +test(const FromDuration& f, const ToDuration& d) +{ +//~ #if defined(BOOST_NO_CXX11_DECLTYPE) + //~ typedef BOOST_TYPEOF_TPL(boost::chrono::duration_cast(f)) R; +//~ #else + //~ typedef decltype(boost::chrono::duration_cast(f)) R; +//~ #endif + //~ BOOST_CHRONO_STATIC_ASSERT((boost::is_same::value), NOTHING, (R, ToDuration)); + BOOST_TEST(boost::chrono::duration_cast(f) == d); +} + +int main() +{ + test(boost::chrono::milliseconds(7265000), boost::chrono::hours(2)); + test(boost::chrono::milliseconds(7265000), boost::chrono::minutes(121)); + test(boost::chrono::milliseconds(7265000), boost::chrono::seconds(7265)); + test(boost::chrono::milliseconds(7265000), boost::chrono::milliseconds(7265000)); + test(boost::chrono::milliseconds(7265000), boost::chrono::microseconds(7265000000LL)); + test(boost::chrono::milliseconds(7265000), boost::chrono::nanoseconds(7265000000000LL)); + test(boost::chrono::milliseconds(7265000), + boost::chrono::duration >(7265./3600)); + test(boost::chrono::duration >(9), + boost::chrono::duration >(10)); + { + BOOST_CONSTEXPR boost::chrono::hours h = boost::chrono::duration_cast(boost::chrono::milliseconds(7265000)); + BOOST_CONSTEXPR_ASSERT(h.count() == 2); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/duration/duration_duration_fail.cpp b/src/boost/libs/chrono/test/duration/duration_duration_fail.cpp new file mode 100644 index 000000000..19e6928ee --- /dev/null +++ b/src/boost/libs/chrono/test/duration/duration_duration_fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// duration +// If a program instantiates duration with a duration type for the template +// argument Rep a diagnostic is required. + +#include + +void test() +{ + typedef boost::chrono::duration D; + D d; +} diff --git a/src/boost/libs/chrono/test/duration/duration_values_pass.cpp b/src/boost/libs/chrono/test/duration/duration_values_pass.cpp new file mode 100644 index 000000000..9d6b84b17 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/duration_values_pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#include "../rep.h" +#if defined BOOST_NO_CXX11_NUMERIC_LIMITS || defined BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + +template +void check_max() +{ + typedef typename D::rep Rep; + Rep max_rep = (boost::chrono::duration_values::max)(); + BOOST_TEST((D::max)().count() == max_rep); + { + typedef typename D::rep Rep; + BOOST_CHRONO_LIB_CONSTEXPR Rep max_rep = (boost::chrono::duration_values::max)(); + BOOST_CONSTEXPR_ASSERT((D::max)().count() == max_rep); + } +} + +template +void check_min() +{ + typedef typename D::rep Rep; + Rep min_rep = (boost::chrono::duration_values::min)(); + BOOST_TEST((D::min)().count() == min_rep); + { + typedef typename D::rep Rep; + BOOST_CHRONO_LIB_CONSTEXPR Rep min_rep = (boost::chrono::duration_values::min)(); + BOOST_CONSTEXPR_ASSERT((D::min)().count() == min_rep); + + } +} + +template +void check_zero() +{ + typedef typename D::rep Rep; + Rep zero_rep = boost::chrono::duration_values::zero(); + BOOST_TEST(D::zero().count() == zero_rep); + { + typedef typename D::rep Rep; + BOOST_CONSTEXPR Rep zero_rep = boost::chrono::duration_values::zero(); + BOOST_CONSTEXPR_ASSERT(D::zero().count() == zero_rep); + + } +} + + +int main() +{ + check_max >(); + check_max >(); + check_min >(); + check_min >(); + check_zero >(); + check_zero >(); + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/duration/nonmember/divide_rep2_fail.cpp b/src/boost/libs/chrono/test/duration/nonmember/divide_rep2_fail.cpp new file mode 100644 index 000000000..649f17ea2 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/nonmember/divide_rep2_fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include + +#include "../../rep.h" + +void test() +{ + boost::chrono::duration d(Rep(15)); + d = d / 5; +} diff --git a/src/boost/libs/chrono/test/duration/nonmember/modulus_rep2_fail.cpp b/src/boost/libs/chrono/test/duration/nonmember/modulus_rep2_fail.cpp new file mode 100644 index 000000000..b5b8c7e4a --- /dev/null +++ b/src/boost/libs/chrono/test/duration/nonmember/modulus_rep2_fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include + +#include "../../rep.h" + +void test() +{ + boost::chrono::duration d(Rep(15)); + d = d % 5; +} diff --git a/src/boost/libs/chrono/test/duration/nonmember/times_rep2_lhs_fail.cpp b/src/boost/libs/chrono/test/duration/nonmember/times_rep2_lhs_fail.cpp new file mode 100644 index 000000000..84c6a405d --- /dev/null +++ b/src/boost/libs/chrono/test/duration/nonmember/times_rep2_lhs_fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include + +#include "../../rep.h" + +void test() +{ + boost::chrono::duration d; + d = 5 * d; +} diff --git a/src/boost/libs/chrono/test/duration/nonmember/times_rep2_rhs_fail.cpp b/src/boost/libs/chrono/test/duration/nonmember/times_rep2_rhs_fail.cpp new file mode 100644 index 000000000..0172b9994 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/nonmember/times_rep2_rhs_fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include + +#include "../../rep.h" + +void test() +{ + boost::chrono::duration d; + d = d * 5; +} diff --git a/src/boost/libs/chrono/test/duration/positive_num_fail.cpp b/src/boost/libs/chrono/test/duration/positive_num_fail.cpp new file mode 100644 index 000000000..fbd25f67b --- /dev/null +++ b/src/boost/libs/chrono/test/duration/positive_num_fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// duration +// Period::num must be positive, diagnostic required. + +#include + +void test() +{ + typedef boost::chrono::duration > D; + D d; +} diff --git a/src/boost/libs/chrono/test/duration/ratio_alias_pass.cpp b/src/boost/libs/chrono/test/duration/ratio_alias_pass.cpp new file mode 100644 index 000000000..a949032ad --- /dev/null +++ b/src/boost/libs/chrono/test/duration/ratio_alias_pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// duration +// Period shall be a specialization of ratio, diagnostic required. + +#include + +void test() +{ + typedef boost::chrono::duration, + boost::ratio<1,3> + > + > D; + D d; + (void)d; +} diff --git a/src/boost/libs/chrono/test/duration/ratio_fail.cpp b/src/boost/libs/chrono/test/duration/ratio_fail.cpp new file mode 100644 index 000000000..5ea4b60b7 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/ratio_fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// duration +// Period shall be a specialization of ratio, diagnostic required. + +#include + +void test() +{ + typedef boost::chrono::duration D; + D d; +} diff --git a/src/boost/libs/chrono/test/duration/rounding_pass.cpp b/src/boost/libs/chrono/test/duration/rounding_pass.cpp new file mode 100644 index 000000000..06a32a1b8 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/rounding_pass.cpp @@ -0,0 +1,105 @@ +// Copyright 2013 Krzysztof Czainski +// Copyright 2013 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +/* + * @file chrono_rounding.cpp + * + * @since 2013-11-22 + * @author Krzysztof Czainski <1czajnik@gmail.com> + */ + +#include +#include +#include +#include + +#include +#include + +using namespace boost::chrono; + +void test_floor() +{ + BOOST_TEST_EQ( seconds(-2), floor( milliseconds(-2000) ) ); + BOOST_TEST_EQ( seconds(-2), floor( milliseconds(-1999) ) ); + BOOST_TEST_EQ( seconds(-2), floor( milliseconds(-1001) ) ); + BOOST_TEST_EQ( seconds(-1), floor( milliseconds(-1000) ) ); + BOOST_TEST_EQ( seconds(-1), floor( milliseconds(-999) ) ); + BOOST_TEST_EQ( seconds(-1), floor( milliseconds(-1) ) ); + BOOST_TEST_EQ( seconds(0), floor( milliseconds(0) ) ); + BOOST_TEST_EQ( seconds(0), floor( milliseconds(1) ) ); + BOOST_TEST_EQ( seconds(0), floor( milliseconds(999) ) ); + BOOST_TEST_EQ( seconds(1), floor( milliseconds(1000) ) ); + BOOST_TEST_EQ( seconds(1), floor( milliseconds(1001) ) ); + BOOST_TEST_EQ( seconds(1), floor( milliseconds(1999) ) ); + BOOST_TEST_EQ( seconds(2), floor( milliseconds(2000) ) ); + + { + // check that int32 isn't overflowed in intermediate calculations: + typedef duration sec32; + typedef duration< boost::int32_t, boost::ratio<999,1000> > sec32_m1ms; + BOOST_TEST_EQ( sec32(-999000000), floor( sec32_m1ms(-1000000000) ) ); + BOOST_TEST_EQ( sec32( 999000000), floor( sec32_m1ms( 1000000000) ) ); + } +} + +void test_ceil() +{ + BOOST_TEST_EQ( seconds(-2), ceil( milliseconds(-2000) ) ); + BOOST_TEST_EQ( seconds(-1), ceil( milliseconds(-1999) ) ); + BOOST_TEST_EQ( seconds(-1), ceil( milliseconds(-1001) ) ); + BOOST_TEST_EQ( seconds(-1), ceil( milliseconds(-1000) ) ); + BOOST_TEST_EQ( seconds(0), ceil( milliseconds(-999) ) ); + BOOST_TEST_EQ( seconds(0), ceil( milliseconds(-1) ) ); + BOOST_TEST_EQ( seconds(0), ceil( milliseconds(0) ) ); + BOOST_TEST_EQ( seconds(1), ceil( milliseconds(1) ) ); + BOOST_TEST_EQ( seconds(1), ceil( milliseconds(999) ) ); + BOOST_TEST_EQ( seconds(1), ceil( milliseconds(1000) ) ); + BOOST_TEST_EQ( seconds(2), ceil( milliseconds(1001) ) ); + BOOST_TEST_EQ( seconds(2), ceil( milliseconds(1999) ) ); + BOOST_TEST_EQ( seconds(2), ceil( milliseconds(2000) ) ); + { + // check that int32 isn't overflowed in intermediate calculations: + typedef duration sec32; + typedef duration< boost::int32_t, boost::ratio<999,1000> > sec32_m1ms; + BOOST_TEST_EQ( sec32(-999000000), ceil( sec32_m1ms(-1000000000) ) ); + BOOST_TEST_EQ( sec32( 999000000), ceil( sec32_m1ms( 1000000000) ) ); + } +} + +void test_round() +{ + // to even on tie + BOOST_TEST_EQ( seconds(-2), round( milliseconds(-2000) ) ); + BOOST_TEST_EQ( seconds(-2), round( milliseconds(-1500) ) ); + BOOST_TEST_EQ( seconds(-1), round( milliseconds(-1499) ) ); + BOOST_TEST_EQ( seconds(-1), round( milliseconds(-1000) ) ); + BOOST_TEST_EQ( seconds(0), round( milliseconds(-500) ) ); + BOOST_TEST_EQ( seconds(0), round( milliseconds(-499) ) ); + BOOST_TEST_EQ( seconds(0), round( milliseconds(0) ) ); + BOOST_TEST_EQ( seconds(0), round( milliseconds(499) ) ); + BOOST_TEST_EQ( seconds(0), round( milliseconds(500) ) ); + BOOST_TEST_EQ( seconds(1), round( milliseconds(1000) ) ); + BOOST_TEST_EQ( seconds(1), round( milliseconds(1499) ) ); + BOOST_TEST_EQ( seconds(2), round( milliseconds(1500) ) ); + BOOST_TEST_EQ( seconds(2), round( milliseconds(2000) ) ); + { + // check that int32 isn't overflowed in intermediate calculations: + typedef duration sec32; + typedef duration< boost::int32_t, boost::ratio<999,1000> > sec32_m1ms; + BOOST_TEST_EQ( sec32(-999000000), round( sec32_m1ms(-1000000000) ) ); + BOOST_TEST_EQ( sec32( 999000000), round( sec32_m1ms( 1000000000) ) ); + } +} + +int main() +{ + test_floor(); + test_ceil(); + test_round(); + return boost::report_errors(); + +} diff --git a/src/boost/libs/chrono/test/duration/typedefs_pass.cpp b/src/boost/libs/chrono/test/duration/typedefs_pass.cpp new file mode 100644 index 000000000..2f9d2ef32 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/typedefs_pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + + +#include +#include +#include + +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +template +void check_duration() +{ + typedef typename D::rep Rep; + typedef typename D::period Period; + BOOST_CHRONO_STATIC_ASSERT(boost::is_signed::value, NOTHING, ()); + BOOST_CHRONO_STATIC_ASSERT(boost::is_integral::value, NOTHING, ()); + BOOST_CHRONO_STATIC_ASSERT(std::numeric_limits::digits >= ExpectedDigits, NOTHING, ()); + BOOST_CHRONO_STATIC_ASSERT((boost::is_same::value), NOTHING, ()); +} + +void test() +{ + check_duration >(); + check_duration >(); + check_duration >(); + check_duration(); + check_duration(); + check_duration(); +} diff --git a/src/boost/libs/chrono/test/duration/types_pass.cpp b/src/boost/libs/chrono/test/duration/types_pass.cpp new file mode 100644 index 000000000..568ce0e29 --- /dev/null +++ b/src/boost/libs/chrono/test/duration/types_pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// duration +// Test nested types + +// typedef Rep rep; +// typedef Period period; + +#include +#include +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +typedef boost::chrono::duration > D; +BOOST_CHRONO_STATIC_ASSERT((boost::is_same::value), NOTHING, ()); +BOOST_CHRONO_STATIC_ASSERT((boost::is_same >::value), NOTHING, ()); diff --git a/src/boost/libs/chrono/test/intmax_c.cpp b/src/boost/libs/chrono/test/intmax_c.cpp new file mode 100644 index 000000000..e3dab7aca --- /dev/null +++ b/src/boost/libs/chrono/test/intmax_c.cpp @@ -0,0 +1,19 @@ +// intmax_c.cpp --------------------------------------------------------------// + +// Copyright 2010 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include + +#ifdef INTMAX_C +#define BOOST_INTMAX_C(a) INTMAX_C(a) +#else +#define BOOST_INTMAX_C(a) a##LL +#endif + +boost::intmax_t i = BOOST_INTMAX_C(1000000000); +int main() { + return (i); +} diff --git a/src/boost/libs/chrono/test/io/duration_input.cpp b/src/boost/libs/chrono/test/io/duration_input.cpp new file mode 100644 index 000000000..1ad8efc51 --- /dev/null +++ b/src/boost/libs/chrono/test/io/duration_input.cpp @@ -0,0 +1,124 @@ +// Distributed under the Boost Software License, Version 1.0. +// Copyright 2011 Vicente J. Botet Escriba +// See http://www.boost.org/LICENSE_1_0.txt + +#include +//#include +#include +#include + + +template +void test_good(const char* str, D res) +{ + std::istringstream in(str); + D d(0); + in >> d; + BOOST_TEST(in.eof()); + BOOST_TEST(!in.fail()); + BOOST_TEST(d == res); + std::cout << str << " " << res << " " << d << std::endl; +} + +template +void test_fail(const char* str, DFail res) +{ + { + std::istringstream in(str); + DFail d = DFail::zero(); + in >> d; + BOOST_TEST(in.fail()); + BOOST_TEST(d == DFail::zero()); + std::cout << str << " " << res << " " << d << std::endl; + } +} + +template +void test_not_eof(const char* str, D res) +{ + { + std::istringstream in(str); + D d = D::zero(); + in >> d; + BOOST_TEST(!in.eof()); + BOOST_TEST(d == res); + std::cout << str << " " << res << " " << d << std::endl; + } +} +int main() +{ + using namespace boost::chrono; + using namespace boost; + + test_good("5000", 5000); + + std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; + test_good("5000 hours", hours(5000)); + std::cerr << __FILE__ << "[" << __LINE__ << "]"<< std::endl; + test_good("5000 minutes", minutes(5000)); + test_good("5000 seconds", seconds(5000)); + test_fail("1.0 second", seconds(1)); + + test_good("1.0 second", duration >(1)); + /* BUG with DURATION_GET +../../../boost/math/common_factor_rt.hpp: In function 'RingType boost::math::detail::gcd_euclidean(RingType, RingType) [with RingType = long double]': +../../../boost/math/common_factor_rt.hpp:122: instantiated from 'IntegerType boost::math::detail::gcd_integer(const IntegerType&, const IntegerType&) [with IntegerType = long double]' +../../../boost/math/common_factor_rt.hpp:240: instantiated from 'T boost::math::detail::gcd_optimal_evaluator_helper_t::operator()(const T&, const T&) [with T = long double]' +../../../boost/math/common_factor_rt.hpp:290: instantiated from 'T boost::math::detail::gcd_optimal_evaluator::operator()(const T&, const T&) [with T = long double]' +../../../boost/math/common_factor_rt.hpp:442: instantiated from 'T boost::math::detail::gcd_optimal(const T&, const T&) [with T = long double]' +../../../boost/math/common_factor_rt.hpp:473: instantiated from 'typename boost::math::gcd_evaluator::result_type boost::math::gcd_evaluator::operator()(const IntegerType&, const IntegerType&) const [with IntegerType = long double]' +../../../boost/math/common_factor_rt.hpp:505: instantiated from 'IntegerType boost::math::gcd(const IntegerType&, const IntegerType&) [with IntegerType = long double]' +../../../boost/chrono/io/duration_get.hpp:239: instantiated from 'InputIterator boost::chrono::duration_get::get(InputIterator, InputIterator, std::ios_base&, std::_Ios_Iostate&, boost::chrono::duration&, const CharT*, const CharT*) const [with Rep = double, Period = boost::ratio<1l, 1l>, CharT = char, InputIterator = std::istreambuf_iterator >]' +../../../boost/chrono/io/duration_get.hpp:294: instantiated from 'InputIterator boost::chrono::duration_get::get(InputIterator, InputIterator, std::ios_base&, std::_Ios_Iostate&, boost::chrono::duration&) const [with Rep = double, Period = boost::ratio<1l, 1l>, CharT = char, InputIterator = std::istreambuf_iterator >]' +../../../boost/chrono/io/duration_io.hpp:593: instantiated from 'std::basic_istream<_CharT, _Traits>& boost::chrono::operator>>(std::basic_istream<_CharT, _Traits>&, boost::chrono::duration&) [with CharT = char, Traits = std::char_traits, Rep = double, Period = boost::ratio<1l, 1l>]' +io/duration_input.cpp:15: instantiated from 'void test_good(const char*, D) [with D = boost::chrono::duration >]' +io/duration_input.cpp:52: instantiated from here +../../../boost/math/common_factor_rt.hpp:102: error: invalid operands of types 'long double' and 'long double' to binary 'operator%' +../../../boost/math/common_factor_rt.hpp:102: error: in evaluation of 'operator%=(long double, long double)' +../../../boost/math/common_factor_rt.hpp:106: error: invalid operands of types 'long double' and 'long double' to binary 'operator%' +../../../boost/math/common_factor_rt.hpp:106: error: in evaluation of 'operator%=(long double, long double)' + * + */ + test_good("1 second", seconds(1)); + test_not_eof("1 second ", seconds(1)); + test_not_eof("1 seconde", seconds(1)); + test_good("1 seconds", seconds(1)); + test_good("0 seconds", seconds(0)); + test_good("-1 seconds", seconds(-1)); + test_good("5000 milliseconds", milliseconds(5000)); + test_good("5000 microseconds", microseconds(5000)); + test_good("5000 nanoseconds", nanoseconds(5000)); + test_good("5000 deciseconds", duration (5000)); + test_good("5000 [1/30]seconds", duration > (5000)); + test_good("5000 [1/30]second", duration > (5000)); + test_good("5000 h", hours(5000)); +#if BOOST_CHRONO_VERSION==2 + test_good("5000 min", minutes(5000)); +#else + test_good("5000 m", minutes(5000)); +#endif + test_good("5000 s", seconds(5000)); + test_good("5000 ms", milliseconds(5000)); + test_good("5000 ns", nanoseconds(5000)); + test_good("5000 ds", duration (5000)); + test_good("5000 [1/30]s", duration > (5000)); + test_not_eof("5000 [1/30]ss", duration > (5000)); + std::cout << __LINE__<< "*****" << std::endl; + test_good("5000 milliseconds", seconds(5)); + test_good("5000 millisecond", seconds(5)); + test_good("5 milliseconds", nanoseconds(5000000)); + std::cout << __LINE__<< "*****" << std::endl; + test_good("4000 ms", seconds(4)); + std::cout << __LINE__<< "*****" << std::endl; + test_fail("3001 ms", seconds(3)); + std::cout << __LINE__<< "*****" << std::endl; + test_fail("3001 ", milliseconds(3001)); + std::cout << __LINE__<< "*****" << std::endl; + test_fail("one ms", milliseconds(1)); + test_fail("5000 millisecon", seconds(5)); + test_not_eof("3001 ms ", milliseconds(3001)); + + return boost::report_errors(); + +} + diff --git a/src/boost/libs/chrono/test/io/duration_output.cpp b/src/boost/libs/chrono/test/io/duration_output.cpp new file mode 100644 index 000000000..e81131532 --- /dev/null +++ b/src/boost/libs/chrono/test/io/duration_output.cpp @@ -0,0 +1,114 @@ +// Copyright 2011 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +template +void test_good_prefix(const char* str, D d) +{ + std::ostringstream out; + out << d; + BOOST_TEST(out.good()); + + BOOST_TEST(out.str() == str); +} + +template +void test_good_symbol(const char* str, D d) +{ + std::ostringstream out; +#if BOOST_CHRONO_VERSION==2 + out << boost::chrono::duration_fmt(boost::chrono::duration_style::symbol) << d; +#else + out << boost::chrono::duration_short << d; +#endif + BOOST_TEST(out.good()); + BOOST_TEST_EQ(out.str(), str); +} +#if BOOST_CHRONO_VERSION==2 + +template +void test_good(const char* str, D d, boost::chrono::duration_style style) +{ + std::ostringstream out; + + out << boost::chrono::duration_fmt(style) << d; + BOOST_TEST(out.good()); + BOOST_TEST(out.str() == str); +} + +template +void test_state_saver(const char* str, const char* str2, D d, boost::chrono::duration_style style) +{ + std::ostringstream out; + { + boost::chrono::duration_style_io_saver ios(out); + out << boost::chrono::duration_fmt(style) << d; + BOOST_TEST(out.good()); + BOOST_TEST(out.str() == str); + } + out << " " << d; + BOOST_TEST(out.good()); + BOOST_TEST(out.str() == str2); +} + +template +void test_state_saver2(const char* str, const char* str2, D d, boost::chrono::duration_style style) +{ + std::ostringstream out; + { + boost::chrono::duration_style_io_saver ios(out, style); + out << d; + BOOST_TEST(out.good()); + BOOST_TEST(out.str() == str); + } + out << " " << d; + BOOST_TEST(out.good()); + BOOST_TEST(out.str() == str2); +} + +#endif + +int main() +{ + using namespace boost::chrono; + using namespace boost; + + test_good_prefix("5000 hours", hours(5000)); + test_good_prefix("5000 minutes", minutes(5000)); + test_good_prefix("5000 seconds", seconds(5000)); + test_good_prefix("0 seconds", seconds(0)); + test_good_prefix("1 second", seconds(1)); + test_good_prefix("-1 second", seconds(-1)); + test_good_prefix("5000 milliseconds", milliseconds(5000)); + test_good_prefix("5000 microseconds", microseconds(5000)); + test_good_prefix("5000 nanoseconds", nanoseconds(5000)); + test_good_prefix("5000 deciseconds", duration (5000)); + test_good_prefix("5000 [1/30]seconds", duration > (5000)); + + test_good_symbol("5000 h", hours(5000)); +#if BOOST_CHRONO_VERSION==2 + test_good_symbol("5000 min", minutes(5000)); +#else + test_good_symbol("5000 m", minutes(5000)); +#endif + test_good_symbol("5000 s", seconds(5000)); + test_good_symbol("5000 ms", milliseconds(5000)); + test_good_symbol("5000 ns", nanoseconds(5000)); + test_good_symbol("5000 ds", duration (5000)); + test_good_symbol("5000 [1/30]s", duration > (5000)); + +#if BOOST_CHRONO_VERSION==2 + test_good("5000 hours", hours(5000), duration_style::prefix); + test_good("5000 h", hours(5000), duration_style::symbol); + test_state_saver("5000 h", "5000 h 5000 hours", hours(5000), duration_style::symbol); + test_state_saver2("5000 h", "5000 h 5000 hours", hours(5000), duration_style::symbol); +#endif + + return boost::report_errors(); + +} + diff --git a/src/boost/libs/chrono/test/io/time_point_input.cpp b/src/boost/libs/chrono/test/io/time_point_input.cpp new file mode 100644 index 000000000..7f0e9348c --- /dev/null +++ b/src/boost/libs/chrono/test/io/time_point_input.cpp @@ -0,0 +1,238 @@ +// Copyright 2011 Vicente J. Botet Escriba +// Copyright (c) Microsoft Corporation 2014 +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include +#include +#if 0 +template +void test_good(std::string str, D res) +{ + typedef typename Clock::time_point clock_time_point; + typedef typename Clock::duration clock_duration; + std::istringstream in(str + boost::chrono::clock_string::since()); + clock_time_point tp; + in >> tp; + BOOST_TEST(in.eof()); + BOOST_TEST(!in.fail()); + std::cout << "Input= " << str << std::endl; + std::cout << "Expected= " << clock_time_point(boost::chrono::duration_cast(res)) << std::endl; + std::cout << "Obtained= " << tp << std::endl; + BOOST_TEST( (tp == clock_time_point(boost::chrono::duration_cast(res)) )); +} + +#else +template +void test_good(std::string str, D res) +{ + typedef boost::chrono::time_point clock_time_point; + //typedef typename Clock::duration clock_duration; + std::istringstream in(str + boost::chrono::clock_string::since()); + clock_time_point tp; + in >> tp; + BOOST_TEST(in.eof()); + BOOST_TEST(!in.fail()); + std::cout << "Input= " << str << std::endl; + std::cout << "Expected= " << clock_time_point(res) << std::endl; + std::cout << "Obtained= " << tp << std::endl; + BOOST_TEST( tp == clock_time_point(res) ); +} + +#endif +#if BOOST_CHRONO_VERSION >= 2 +template +void test_good_system_clock(std::string str, D res) +{ + typedef boost::chrono::system_clock Clock; + + std::istringstream in(str); + boost::chrono::time_point tp; + in >> tp; + BOOST_TEST(in.eof()); + BOOST_TEST(!in.fail()); + std::cout << "Input= " << str << std::endl; + std::cout << "Expected= " << boost::chrono::time_point(res) << std::endl; + std::cout << "Obtained= " << tp << std::endl; + std::cout << "Expected= " << boost::chrono::duration_cast(boost::chrono::time_point(res).time_since_epoch()).count() << std::endl; + std::cout << "Obtained= " << boost::chrono::duration_cast(tp.time_since_epoch()).count() << std::endl; + BOOST_TEST( (tp == boost::chrono::time_point(res))); +} + +template +void test_good_utc_fmt_system_clock(std::string str, std::string fmt, D res) +{ + typedef boost::chrono::system_clock Clock; + + std::istringstream in(str); + boost::chrono::time_point tp; + in >> time_fmt(boost::chrono::timezone::utc, fmt); + in >> tp; + BOOST_TEST(in.eof()); + BOOST_TEST(!in.fail()); + std::cout << "Input= " << str << std::endl; + std::cout << "Expected= " << boost::chrono::time_point(res) << std::endl; + std::cout << "Obtained= " << tp << std::endl; + std::cout << "Expected= " << boost::chrono::duration_cast(boost::chrono::time_point(res).time_since_epoch()).count() << std::endl; + std::cout << "Obtained= " << boost::chrono::duration_cast(tp.time_since_epoch()).count() << std::endl; + BOOST_TEST_EQ( tp , (boost::chrono::time_point(res))); +} +#endif +template +void test_fail(const char* str, D) +{ + std::istringstream in(str + boost::chrono::clock_string::since()); + boost::chrono::time_point tp; + in >> tp; + BOOST_TEST(in.fail()); + BOOST_TEST( (tp == boost::chrono::time_point())); +} + +template +void test_fail_no_epoch(const char* str, D ) +{ + std::istringstream in(str); + boost::chrono::time_point tp; + in >> tp; + BOOST_TEST(in.fail()); + BOOST_TEST( (tp == boost::chrono::time_point())); +} + +template +void test_fail_epoch(const char* str, D) +{ + std::istringstream in(str); + boost::chrono::time_point tp; + in >> tp; + BOOST_TEST(in.fail()); + BOOST_TEST( (tp == boost::chrono::time_point())); +} + +template +void check_all() +{ + using namespace boost::chrono; + using namespace boost; + + test_good ("5000 hours", hours(5000)); + test_good ("5000 minutes", minutes(5000)); + test_good ("5000 seconds", seconds(5000)); + test_good ("1 seconds", seconds(1)); + test_good ("1 second", seconds(1)); + test_good ("-1 seconds", seconds(-1)); + test_good ("0 second", seconds(0)); + test_good ("0 seconds", seconds(0)); + test_good ("5000 milliseconds", milliseconds(5000)); + test_good ("5000 microseconds", microseconds(5000)); + test_good ("5000 nanoseconds", nanoseconds(5000)); + test_good ("5000 deciseconds", duration (5000)); + test_good ("5000 [1/30]seconds", duration > (5000)); + + test_good ("5000 h", hours(5000)); +#if BOOST_CHRONO_VERSION >= 2 + test_good("5000 min", minutes(5000)); +#else + test_good ("5000 m", minutes(5000)); +#endif + test_good ("5000 s", seconds(5000)); + test_good ("5000 ms", milliseconds(5000)); + test_good ("5000 ns", nanoseconds(5000)); + test_good ("5000 ds", duration (5000)); + test_good ("5000 [1/30]s", duration > (5000)); + + test_good ("5000 milliseconds", seconds(5)); + test_good ("5 milliseconds", nanoseconds(5000000)); + test_good ("4000 ms", seconds(4)); + test_fail ("3001 ms", seconds(3)); + test_fail_epoch ("3001 ms", seconds(3)); + test_fail_epoch ("3001 ms since", seconds(3)); + +} + +#if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP +void check_all_process_cpu_clock() +{ + using namespace boost::chrono; + using namespace boost; + //typedef process_cpu_clock Clock; + //test_good ("{5000;0;0} nanoseconds", process_cpu_clock::duration(process_cpu_clock::times(5000,0,0))); +} +#endif + +#if BOOST_CHRONO_VERSION >= 2 +void check_all_system_clock() +{ + using namespace boost::chrono; + using namespace boost; + + test_good_system_clock ("1970-01-01 02:00:00.000000 +0000", hours(2)); + test_good_system_clock ("1970-07-28 08:00:00.000000 +0000", hours(5000)); + test_good_system_clock ("1970-01-04 11:20:00.000000 +0000", minutes(5000)); + test_good_system_clock ("1970-01-01 01:23:20.000000 +0000", seconds(5000)); + test_good_system_clock ("1970-01-01 00:00:01.000000 +0000", seconds(1)); + test_good_system_clock ("1970-01-01 00:00:01.000000 +0000", seconds(1)); + test_good_system_clock ("1969-12-31 23:59:59.000000 +0000", seconds(-1)); + test_good_system_clock ("1970-01-01 00:00:00.000000 +0000", seconds(0)); + test_good_system_clock ("1970-01-01 00:00:00.000000 +0000", seconds(0)); + test_good_system_clock ("1970-01-01 00:00:05.000000 +0000", milliseconds(5000)); + test_good_system_clock ("1970-01-01 00:00:00.005000 +0000", microseconds(5000)); + test_good_system_clock ("1970-01-01 00:00:00.000005 +0000", nanoseconds(5000)); + test_good_system_clock ("1970-01-01 00:08:20.000000 +0000", duration (5000)); + test_good_system_clock ("1970-01-01 00:02:46.666667 +0000", duration > (5000)); + + test_good_utc_fmt_system_clock ("1970-01-01 02:00:00", "%Y-%m-%d %H:%M:%S", hours(2)); + test_good_utc_fmt_system_clock ("1970-01-01 02:00:00", "%F %H:%M:%S", hours(2)); + test_good_utc_fmt_system_clock ("1970-01-01 02", "%Y-%m-%d %H", hours(2)); + test_good_utc_fmt_system_clock ("1970-01-01 02", "%F %H", hours(2)); + test_good_utc_fmt_system_clock ("1970-01-01 02:00:00", "%Y-%m-%d %T", hours(2)); + test_good_utc_fmt_system_clock ("1970-01-01 02:00", "%Y-%m-%d %R", hours(2)); + test_good_utc_fmt_system_clock ("% 1970-01-01 02:00", "%% %Y-%m-%d %R", hours(2)); + //test_good_utc_fmt_system_clock ("1970-01-01 02:00 Thursday January", "%Y-%m-%d %R %A %B", hours(2)); + + +// test_fail ("3001 ms", seconds(3)); +// test_fail_epoch ("3001 ms", seconds(3)); +// test_fail_epoch ("3001 ms since", seconds(3)); + +} +#endif +int main() +{ + std::cout << "high_resolution_clock=" << std::endl; + check_all (); +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + std::cout << "steady_clock=" << std::endl; + check_all (); +#endif + std::cout << "system_clock=" << std::endl; +#if BOOST_CHRONO_VERSION >= 2 && defined BOOST_CHRONO_PROVIDES_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT + check_all_system_clock(); +#else + check_all (); +#endif +#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) + std::cout << "thread_clock="<< std::endl; + check_all(); +#endif + +#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS) + std::cout << "process_real_cpu_clock=" << std::endl; + check_all (); +#if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP + std::cout << "process_user_cpu_clock=" << std::endl; + check_all (); + std::cout << "process_system_cpu_clock=" << std::endl; + check_all (); + std::cout << "process_cpu_clock=" << std::endl; + //check_all_process_cpu_clock(); +#endif +#endif + + return boost::report_errors(); + +} + diff --git a/src/boost/libs/chrono/test/io/time_point_output.cpp b/src/boost/libs/chrono/test/io/time_point_output.cpp new file mode 100644 index 000000000..6d5b021b1 --- /dev/null +++ b/src/boost/libs/chrono/test/io/time_point_output.cpp @@ -0,0 +1,317 @@ +// Copyright 2011 Vicente J. Botet Escriba +// Copyright (c) Microsoft Corporation 2014 +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +template +void test_good_prefix(const char* str, D d) +{ + std::ostringstream out; + boost::chrono::time_point tp(d); + out << tp; + BOOST_TEST(out.good()); + //std::cout << "Expected= " << std::string(str) + boost::chrono::clock_string::since() << std::endl; + //std::cout << "Obtained= " << out.str() << std::endl; + BOOST_TEST( (out.str() == std::string(str) + boost::chrono::clock_string::since())); +} + +template +void test_good_prefix_system_clock(const char* str, D d) +{ + typedef boost::chrono::system_clock Clock; + + std::ostringstream out; + boost::chrono::time_point tp(d); + out << tp; + BOOST_TEST(out.good()); + + std::cout << "Expected= " << str << std::endl; + std::cout << "Obtained= " << out.str() << std::endl; + BOOST_TEST( (out.str() == std::string(str) )); +} + +template +void test_good_symbol(const char* str, D d) +{ + std::ostringstream out; + boost::chrono::time_point tp(d); +#if BOOST_CHRONO_VERSION>=2 + out << boost::chrono::duration_fmt(boost::chrono::duration_style::symbol) << tp; +#else + out << boost::chrono::duration_short << tp; +#endif + BOOST_TEST(out.good()); + BOOST_TEST( (out.str() == std::string(str) + boost::chrono::clock_string::since())); +} + +#if BOOST_CHRONO_VERSION>=2 +template +void test_good_symbol_system_clock(const char* str, D d) +{ + typedef boost::chrono::system_clock Clock; + + std::ostringstream out; + boost::chrono::time_point tp(d); + out << boost::chrono::duration_fmt(boost::chrono::duration_style::symbol) << tp; + BOOST_TEST(out.good()); + std::cout << "Expected= " << str << std::endl; + std::cout << "Obtained= " << out.str() << std::endl; + BOOST_TEST( (out.str() == std::string(str) )); +} + +template +void test_good_utc_fmt_system_clock(const char* str, const char* fmt, D d) +{ + typedef boost::chrono::system_clock Clock; + + std::ostringstream out; + boost::chrono::time_point tp(d); + boost::chrono::time_fmt_io_saver<> fmts(out); + boost::chrono::timezone_io_saver tzs(out); + out << time_fmt(boost::chrono::timezone::utc, fmt) << tp; + BOOST_TEST(out.good()); + std::cout << "Expected= " << str << std::endl; + std::cout << "Obtained= " << out.str() << std::endl; + BOOST_TEST_EQ( out.str() , std::string(str) ); +} + +template +void test_good_utc_fmt_system_clock2(const char* str, const char* fmt, D d) +{ + typedef boost::chrono::system_clock Clock; + + std::ostringstream out; + boost::chrono::time_point tp(d); + boost::chrono::time_fmt_io_saver<> fmts(out, fmt); + boost::chrono::timezone_io_saver tzs(out, boost::chrono::timezone::utc); + out << tp; + BOOST_TEST(out.good()); + std::cout << "Expected= " << str << std::endl; + std::cout << "Obtained= " << out.str() << std::endl; + BOOST_TEST_EQ( out.str() , std::string(str) ); +} + +template +void test_good(const char* str, D d, boost::chrono::duration_style style) +{ + std::ostringstream out; + boost::chrono::time_point tp(d); + out << boost::chrono::duration_fmt(style) << tp; + BOOST_TEST(out.good()); + BOOST_TEST((out.str() == std::string(str)+boost::chrono::clock_string::since())); +} + +template +void test_good_system_clock(const char* str, D d, boost::chrono::duration_style style) +{ + typedef boost::chrono::system_clock Clock; + + std::ostringstream out; + boost::chrono::time_point tp(d); + out << boost::chrono::duration_fmt(style) << tp; + BOOST_TEST(out.good()); + std::cout << "Expected= " << str << std::endl; + std::cout << "Obtained= " << out.str() << std::endl; + BOOST_TEST((out.str() == std::string(str) )); +} +#endif + +template +void check_all() +{ + using namespace boost::chrono; + using namespace boost; + +#if BOOST_CHRONO_VERSION>=2 + test_good("2 hours", hours(2), duration_style::prefix); + test_good("2 h", hours(2), duration_style::symbol); +#endif + + test_good_prefix ("2 hours", hours(2)); + test_good_prefix ("2 minutes", minutes(2)); + test_good_prefix ("2 seconds", seconds(2)); + test_good_prefix ("1 second", seconds(1)); + test_good_prefix ("-1 second", seconds(-1)); + test_good_prefix ("0 seconds", seconds(0)); + test_good_prefix ("2 milliseconds", milliseconds(2)); + test_good_prefix ("2 microseconds", microseconds(2)); + test_good_prefix ("2 nanoseconds", nanoseconds(2)); + test_good_prefix ("2 deciseconds", duration (2)); + test_good_prefix ("2 [1/30]seconds", duration > (2)); + + test_good_symbol ("2 h", hours(2)); +#if BOOST_CHRONO_VERSION>=2 + test_good_symbol("2 min", minutes(2)); +#else + test_good_symbol ("2 m", minutes(2)); +#endif + test_good_symbol ("2 s", seconds(2)); + test_good_symbol ("2 ms", milliseconds(2)); + test_good_symbol ("2 ns", nanoseconds(2)); + test_good_symbol ("2 ds", duration (2)); + test_good_symbol ("2 [1/30]s", duration > (2)); +} + +#if BOOST_CHRONO_VERSION >= 2 +void check_all_system_clock() +{ + using namespace boost::chrono; + using namespace boost; + + test_good_system_clock("1970-01-01 02:00:00.000000000 +0000", hours(2), duration_style::prefix); + test_good_system_clock("1970-01-01 02:00:00.000000000 +0000", hours(2), duration_style::symbol); + + test_good_prefix_system_clock("1970-01-01 02:00:00.000000000 +0000", hours(2)); + test_good_prefix_system_clock("1970-01-01 00:02:00.000000000 +0000", minutes(2)); + test_good_prefix_system_clock("1970-01-01 00:00:02.000000000 +0000", seconds(2)); + test_good_prefix_system_clock("1970-01-01 00:00:01.000000000 +0000", seconds(1)); + test_good_prefix_system_clock("1969-12-31 23:59:59.000000000 +0000", seconds(-1)); + test_good_prefix_system_clock("1970-01-01 00:00:00.000000000 +0000", seconds(0)); + test_good_prefix_system_clock("1970-01-01 00:00:00.002000000 +0000", milliseconds(2)); + test_good_prefix_system_clock("1970-01-01 00:00:00.000002000 +0000", microseconds(2)); + test_good_prefix_system_clock("1970-01-01 00:00:00.000000002 +0000", nanoseconds(2)); + test_good_prefix_system_clock("1970-01-01 00:00:00.200000000 +0000", duration (2)); + test_good_prefix_system_clock("1970-01-01 00:00:00.066666667 +0000", duration > (2)); + + test_good_symbol_system_clock("1970-01-01 02:00:00.000000000 +0000", hours(2)); + test_good_symbol_system_clock("1970-01-01 00:02:00.000000000 +0000", minutes(2)); + test_good_symbol_system_clock("1970-01-01 00:00:02.000000000 +0000", seconds(2)); + test_good_symbol_system_clock("1970-01-01 00:00:00.002000000 +0000", milliseconds(2)); + test_good_symbol_system_clock("1970-01-01 00:00:00.000000002 +0000", nanoseconds(2)); + test_good_symbol_system_clock("1970-01-01 00:00:00.200000000 +0000", duration (2)); + test_good_symbol_system_clock("1970-01-01 00:00:00.066666667 +0000", duration > (2)); + + test_good_utc_fmt_system_clock("1970-01-01 02:00:00", "%Y-%m-%d %H:%M:%S", hours(2)); + test_good_utc_fmt_system_clock("1970-01-01 02", "%Y-%m-%d %H", hours(2)); +#if ! defined(BOOST_CHRONO_WINDOWS_API) + test_good_utc_fmt_system_clock ("1970-01-01 02:00:00", "%Y-%m-%d %T", hours(2)); + test_good_utc_fmt_system_clock ("1970-01-01 02:00", "%Y-%m-%d %R", hours(2)); + test_good_utc_fmt_system_clock ("% 1970-01-01 02:00", "%% %Y-%m-%d %R", hours(2)); + test_good_utc_fmt_system_clock ("1970-01-01 02:00 Thursday January", "%Y-%m-%d %R %A %B", hours(2)); +#endif + test_good_utc_fmt_system_clock2("1970-01-01 02:00:00", "%Y-%m-%d %H:%M:%S", hours(2)); + test_good_utc_fmt_system_clock2("1970-01-01 02", "%Y-%m-%d %H", hours(2)); +#if ! defined(BOOST_CHRONO_WINDOWS_API) + test_good_utc_fmt_system_clock2 ("1970-01-01 02:00:00", "%Y-%m-%d %T", hours(2)); + test_good_utc_fmt_system_clock2 ("1970-01-01 02:00", "%Y-%m-%d %R", hours(2)); + test_good_utc_fmt_system_clock2 ("% 1970-01-01 02:00", "%% %Y-%m-%d %R", hours(2)); + test_good_utc_fmt_system_clock2 ("1970-01-01 02:00 Thursday January", "%Y-%m-%d %R %A %B", hours(2)); +#endif +} + + +#endif +#if defined BOOST_CHRONO_INTERNAL_GMTIME +#elif BOOST_CHRONO_VERSION == 2 +void test_gmtime(std::time_t t) +{ + std::cout << "t " << t << std::endl; + std::puts(ctime(&t)); + std::tm tm; + std::memset(&tm, 0, sizeof(std::tm)); + if (boost::chrono::detail::internal_gmtime(&t, &tm)) + { + tm.tm_isdst = -1; + (void)mktime(&tm); + std::tm tm2; + std::memset(&tm2, 0, sizeof(std::tm)); + if (gmtime_r(&t, &tm2)) + { + tm2.tm_isdst = -1; + (void)mktime(&tm2); + + BOOST_TEST_EQ( tm.tm_year , tm2.tm_year ); + BOOST_TEST_EQ( tm.tm_mon , tm2.tm_mon ); + BOOST_TEST_EQ( tm.tm_mday , tm2.tm_mday ); + BOOST_TEST_EQ( tm.tm_hour , tm2.tm_hour); + BOOST_TEST_EQ( tm.tm_min , tm2.tm_min ); + BOOST_TEST_EQ( tm.tm_sec , tm2.tm_sec ); + BOOST_TEST_EQ( tm.tm_wday , tm2.tm_wday ); + BOOST_TEST_EQ( tm.tm_yday , tm2.tm_yday ); + BOOST_TEST_EQ( tm.tm_isdst , tm2.tm_isdst ); + } + } + +} +#endif + + +int main() +{ +#if defined BOOST_CHRONO_INTERNAL_GMTIME +#elif BOOST_CHRONO_VERSION == 2 + test_gmtime( 0 ); + test_gmtime( -1 ); + test_gmtime( +1 ); + test_gmtime( 0 - (3600 * 24) ); + test_gmtime( -1 - (3600 * 24) ); + test_gmtime( +1 - (3600 * 24) ); + test_gmtime( 0 + (3600 * 24) ); + test_gmtime( -1 + (3600 * 24) ); + test_gmtime( +1 + (3600 * 24) ); + test_gmtime( 0 + 365*(3600 * 24) ); + test_gmtime( 0 + 10LL*365*(3600 * 24) ); + test_gmtime( 0 + 15LL*365*(3600 * 24) ); + test_gmtime( 0 + 17LL*365*(3600 * 24) ); + test_gmtime( 0 + 18LL*365*(3600 * 24) ); + test_gmtime( 0 + 19LL*365*(3600 * 24) ); + test_gmtime( 0 + 19LL*365*(3600 * 24)+ (3600 * 24)); + test_gmtime( 0 + 19LL*365*(3600 * 24)+ 3*(3600 * 24)); + test_gmtime( 0 + 19LL*365*(3600 * 24)+ 4*(3600 * 24)); + test_gmtime( 0 + 20LL*365*(3600 * 24) ); + test_gmtime( 0 + 40LL*365*(3600 * 24) ); +#endif + + std::cout << "high_resolution_clock=" << std::endl; + check_all (); +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + std::cout << "steady_clock=" << std::endl; + check_all (); +#endif + std::cout << "system_clock=" << std::endl; +#if BOOST_CHRONO_VERSION >= 2 && defined BOOST_CHRONO_PROVIDES_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT + check_all_system_clock(); +#else + check_all (); +#endif + +#if defined(BOOST_CHRONO_HAS_THREAD_CLOCK) + std::cout << "thread_clock="<< std::endl; + check_all(); +#endif + +#if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS) + std::cout << "process_real_cpu_clock=" << std::endl; + check_all (); +#if ! BOOST_OS_WINDOWS || BOOST_PLAT_WINDOWS_DESKTOP + std::cout << "process_user_cpu_clock=" << std::endl; + check_all (); + std::cout << "process_system_cpu_clock=" << std::endl; + check_all (); + std::cout << "process_cpu_clock=" << std::endl; + check_all (); +#endif +#endif + +#if defined BOOST_CHRONO_INTERNAL_GMTIME +#elif BOOST_CHRONO_VERSION == 2 + boost::chrono::system_clock::time_point tp = boost::chrono::system_clock::now(); + std::cout << tp << std::endl; + time_t t = boost::chrono::system_clock::to_time_t(tp); + test_gmtime( t ); +#endif + + return boost::report_errors(); + +} + diff --git a/src/boost/libs/chrono/test/one_obj.cpp b/src/boost/libs/chrono/test/one_obj.cpp new file mode 100644 index 000000000..ed8d61a09 --- /dev/null +++ b/src/boost/libs/chrono/test/one_obj.cpp @@ -0,0 +1,23 @@ +// boost win32_test.cpp -----------------------------------------------------// + +// Copyright 2010 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See http://www.boost.org/libs/chrono for documentation. +#include +#include +#include + +void another(); + +int main() +{ + boost::chrono::steady_clock::time_point t1=boost::chrono::steady_clock::now(); + another(); + boost::chrono::steady_clock::time_point t2=boost::chrono::steady_clock::now(); + std::cout << t2-t1 << std::endl; + return 0; +} + diff --git a/src/boost/libs/chrono/test/rep.h b/src/boost/libs/chrono/test/rep.h new file mode 100644 index 000000000..b7e4ca273 --- /dev/null +++ b/src/boost/libs/chrono/test/rep.h @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#ifndef REP_H +#define REP_H + +#include + +class Rep +{ +public: + int data_; + BOOST_CONSTEXPR Rep() : data_() {} + explicit BOOST_CONSTEXPR Rep(int i) : data_(i) {} + + BOOST_CONSTEXPR bool operator==(int i) const {return data_ == i;} + BOOST_CONSTEXPR bool operator==(const Rep& r) const {return data_ == r.data_;} + + Rep& operator*=(Rep x) {data_ *= x.data_; return *this;} + Rep& operator/=(Rep x) {data_ /= x.data_; return *this;} +}; + +#if 0 +namespace std { + + template <> + struct numeric_limits + { + static BOOST_CONSTEXPR Rep max BOOST_PREVENT_MACRO_SUBSTITUTION () + { + return Rep((std::numeric_limits::max)()); + } + + }; +} // namespace std + +namespace boost { +namespace chrono { +template <> +struct duration_values +{ + static BOOST_CONSTEXPR Rep zero() {return Rep(0);} + static BOOST_CONSTEXPR Rep max BOOST_PREVENT_MACRO_SUBSTITUTION () + { + return Rep((std::numeric_limits::max)()); + } + + static BOOST_CONSTEXPR Rep min BOOST_PREVENT_MACRO_SUBSTITUTION () + { + return Rep(detail::numeric_limits::lowest()); + } +}; + +} // namespace chrono +} // namespace boost +#endif +#endif // REP_H diff --git a/src/boost/libs/chrono/test/run_timer_test.cpp b/src/boost/libs/chrono/test/run_timer_test.cpp new file mode 100644 index 000000000..0f14a73e5 --- /dev/null +++ b/src/boost/libs/chrono/test/run_timer_test.cpp @@ -0,0 +1,226 @@ +// boost run_timer_test.cpp -----------------------------------------------------// + +// Copyright Beman Dawes 2006, 2008 +// Copyright 2009 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See http://www.boost.org/libs/chrono for documentation. + +#include +#include +#include // for atol() +#include +#include +#include +#include +#include // for sqrt(), used to burn time + +using boost::chrono::run_timer; +using boost::system::error_code; + +#include + +//#define BOOST_TEST(expr) if (!(expr)) std::cout << "*****ERROR*****\n" + +#define CHECK_REPORT(Timer,String_Stream,R,U,S,Expected_String) \ + check_report(Timer, String_Stream, R, U, S, Expected_String, __LINE__) + + +namespace +{ + typedef boost::chrono::nanoseconds ns; + + bool check_report( run_timer & tmr, std::stringstream & ss, + run_timer::duration r, run_timer::duration u, run_timer::duration s, + const std::string & expected, int line ) + { + tmr.test_report(r,u,s); + bool result(true); + if ( ss.str() != expected ) + { + std::cout << "run_timer_test.cpp(" << line << ") : error: actual output \"" + << ss.str() << "\" != expected \"" << expected << "\"\n"; + result = false; + } + return result; + } + + void run_timer_constructor_overload_test() + { + // exercise each supported combination of constructor arguments + + std::ostream & os = std::cout; + const int pl = 9; + boost::system::error_code ec; + + run_timer t1; + run_timer t2( os ); + run_timer t3( ec ); + run_timer t4( os, ec ); + run_timer t5( pl ); + run_timer t6( os, pl ); + run_timer t7( pl, ec ); + run_timer t8( os, pl, ec ); + run_timer t9( "t9, default places, r %r, c %c, p %p, u %u, s %s\n" ); + run_timer t10( os, "t10, default places, r %r, c %c, p %p, u %u, s %s\n" ); + run_timer t11( "t11, default places, r %r, c %c, p %p, u %u, s %s\n", ec ); + run_timer t12( os, "t12, default places, r %r, c %c, p %p, u %u, s %s\n", ec ); + run_timer t13( pl, "t13, explicitly code places, r %r, c %c, p %p, u %u, s %s\n" ); + run_timer t14( "t14, explicitly code places, r %r, c %c, p %p, u %u, s %s\n", pl ); + run_timer t15( os, pl, "t15, explicitly code places, r %r, c %c, p %p, u %u, s %s\n" ); + run_timer t16( os, "t16, explicitly code places, r %r, c %c, p %p, u %u, s %s\n", pl ); + run_timer t17( pl, "t17, explicitly code places, r %r, c %c, p %p, u %u, s %s\n", ec ); + run_timer t18( "t18, explicitly code places, r %r, c %c, p %p, u %u, s %s\n", pl, ec ); + run_timer t19( os, pl, "t19, explicitly code places, r %r, c %c, p %p, u %u, s %s\n", ec ); + run_timer t20( os, "t20, explicitly code places, r %r, c %c, p %p, u %u, s %s\n", pl, ec ); + + std::cout << "Burn some time so run_timers have something to report..."; + boost::chrono::timer t; + while ( t.elapsed() < boost::chrono::seconds(1) ) {} + std::cout << "\n"; + std::cout << run_timer::default_places() << " default places\n"; + std::cout << pl << " explicitly coded places\n"; + } + + // accuracy test + void accuracy_test( int argc, char * argv[] ) + { + long timeout_in_secs = 1; + if ( argc > 1 ) timeout_in_secs = std::atol( argv[1] ); + std::cout << "accuracy test for " << timeout_in_secs << " second(s)..."; + + std::clock_t timeout_in_clock_t = std::clock(); + timeout_in_clock_t += (timeout_in_secs * CLOCKS_PER_SEC); + + boost::chrono::system_timer sys; +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + boost::chrono::steady_timer mono; +#endif + boost::chrono::high_resolution_timer hires; + boost::chrono::process_timer process; + + std::clock_t now; + do + { + now = std::clock(); + } while ( now < timeout_in_clock_t ); + + boost::chrono::system_timer::duration sys_dur = sys.elapsed(); +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + boost::chrono::steady_timer::duration mono_dur = mono.elapsed(); +#endif + boost::chrono::high_resolution_timer::duration hires_dur = hires.elapsed(); + boost::chrono::process_times times; + process.elapsed( times ); + + std::cout << std::endl; + + ns timeout_in_nanoseconds( static_cast(timeout_in_secs) * 1000000000LL ); + + // Allow 20% leeway. Particularly on Linux, there seems to be a large discrepancy + // between std::clock() and higher resolution clocks. + ns maximum_delta ( static_cast(timeout_in_nanoseconds.count() * 0.20 ) ); + + std::cout << timeout_in_nanoseconds.count() << " timeout_in_nanoseconds\n"; + std::cout << maximum_delta.count() << " maximum_delta\n"; + + std::cout << sys_dur.count() << " sys_dur\n"; + + BOOST_TEST( sys_dur > timeout_in_nanoseconds - maximum_delta + && sys_dur < timeout_in_nanoseconds + maximum_delta ); + +#ifdef BOOST_CHRONO_HAS_CLOCK_STEADY + std::cout << mono_dur.count() << " mono_dur\n"; + + BOOST_TEST( mono_dur > timeout_in_nanoseconds - maximum_delta + && mono_dur < timeout_in_nanoseconds + maximum_delta ); +#endif + + std::cout << hires_dur.count() << " hires_dur\n"; + + BOOST_TEST( hires_dur > timeout_in_nanoseconds - maximum_delta + && hires_dur < timeout_in_nanoseconds + maximum_delta ); + + std::cout << times.real.count() << " times.real\n"; + + BOOST_TEST( times.real > timeout_in_nanoseconds - maximum_delta + && times.real < timeout_in_nanoseconds + maximum_delta ); + } + + // report test + + void report_test() + { + { + std::stringstream ss; + run_timer t(ss); + BOOST_TEST( CHECK_REPORT(t, ss, ns(0), ns(0), ns(0), + "\nreal 0.000s, cpu 0.000s (0.0%), user 0.000s, system 0.000s\n" ) ); + } + + { + std::stringstream ss; + run_timer t(ss); + BOOST_TEST( CHECK_REPORT(t, ss, ns(3000000000LL), ns(2000000000LL), ns(1000000000LL), + "\nreal 3.000s, cpu 3.000s (100.0%), user 2.000s, system 1.000s\n" ) ); + } + + { + std::stringstream ss; + run_timer t( ss, "9 places: r %r, c %c, p %p, u %u, s %s", 9 ); + BOOST_TEST( CHECK_REPORT(t, ss, ns(3000000003LL), ns(2000000002LL), ns(1000000001LL), + "9 places: " + "r 3.000000003, c 3.000000003, p 100.0, u 2.000000002, s 1.000000001" ) ); + } + } + + // process_timer_test + + void process_timer_test() + { + std::cout << "process_timer_test..." << std::flush; + + boost::chrono::process_timer t; + double res=0; // avoids optimization + for (long i = 0; i < 10000000L; ++i) + { + res+=std::sqrt( static_cast(i) ); // avoids optimization + } + + boost::chrono::process_times times; + times.real = times.system = times.user = ns(0); + + BOOST_TEST( times.real == ns(0) ); + BOOST_TEST( times.user == ns(0) ); + BOOST_TEST( times.system == ns(0) ); + + t.elapsed( times ); + std::cout << "\n"; + + std::cout << times.real.count() << " times.real\n"; + std::cout << times.user.count() << " times.user\n"; + std::cout << times.system.count() << " times.system\n"; + std::cout << (times.user+times.system).count() << " times.user+system\n"; + BOOST_TEST( times.real > ns(1) ); + + BOOST_TEST( times.user+times.system > ns(1) ); + + std::cout << "complete " << res << std::endl; + } +} + +int main( int argc, char * argv[] ) +{ + std::locale loc( "" ); // test with appropriate locale + std::cout.imbue( loc ); + + accuracy_test( argc, argv ); + run_timer_constructor_overload_test(); + process_timer_test(); + report_test(); + + return boost::report_errors(); +} + diff --git a/src/boost/libs/chrono/test/test_10631.cpp b/src/boost/libs/chrono/test/test_10631.cpp new file mode 100644 index 000000000..2bce583b6 --- /dev/null +++ b/src/boost/libs/chrono/test/test_10631.cpp @@ -0,0 +1,61 @@ +// Copyright 2015 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt +// See http://www.boost.org/libs/chrono for documentation. + +#define BOOST_CHRONO_VERION 2 +#include +#include +#include + +// a custom clock +// here based on boost's own system_clock +class MyMillenniumClock +{ +public: + typedef boost::chrono::system_clock::rep rep; + typedef boost::chrono::system_clock::period period; + typedef boost::chrono::duration duration; + typedef boost::chrono::time_point time_point; + + BOOST_STATIC_CONSTEXPR bool is_steady = boost::chrono::system_clock::is_steady; + +public: + /// Returns a time_point representing the current value of the clock. + static time_point now() { + return time_point(boost::chrono::system_clock::now().time_since_epoch() - boost::chrono::hours(30*365)); + } +}; + + +namespace boost +{ + namespace chrono + { + template + struct clock_string + { + static std::basic_string name() { + static const CharT a[] = {'M', 'y', 'M', 'i', 'l', 'l', 'e', 'n', 'n', 'i', 'u', 'm', 'C', 'l', 'o', 'c', 'k'}; + return std::basic_string(a, a + sizeof(a)/sizeof(a[0])); + } + static std::basic_string since() { + static const CharT a[] = {' ', 's', 'i', 'n', 'c', 'e', ' ', 'y', 'e', 'a', 'r', ' ', '2', 'k'}; + return std::basic_string(a, a + sizeof(a)/sizeof(a[0])); + } + }; + } +} + +template +std::basic_string get_epoch_custom(MyMillenniumClock, TPUFacet&) +{ + return boost::chrono::clock_string::since(); +} + +int main() +{ + std::cout << boost::chrono::steady_clock::now() << std::endl; + std::cout << MyMillenniumClock::now() << std::endl; + return 0; +} diff --git a/src/boost/libs/chrono/test/test_10778.cpp b/src/boost/libs/chrono/test/test_10778.cpp new file mode 100644 index 000000000..7693cd3fe --- /dev/null +++ b/src/boost/libs/chrono/test/test_10778.cpp @@ -0,0 +1,19 @@ +// Copyright 2015 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt +// See http://www.boost.org/libs/chrono for documentation. + +//#define BOOST_CHRONO_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0 +#include +#include +#include + +void test() +{ + std::atomic ms; // error C2338: atomic requires T to be trivially copyable. +} + +int main() { + test(); + return 1; +} diff --git a/src/boost/libs/chrono/test/test_11006.cpp b/src/boost/libs/chrono/test/test_11006.cpp new file mode 100644 index 000000000..cf40fc051 --- /dev/null +++ b/src/boost/libs/chrono/test/test_11006.cpp @@ -0,0 +1,21 @@ +// Copyright 2015 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt +// See http://www.boost.org/libs/chrono for documentation. + +//#define BOOST_CHRONO_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0 +#define BOOST_CHRONO_VERSION 2 +#include +#include + + +int main() { + { + boost::chrono::time_fmt_io_saver<> tmp(std::cout); + } + { + boost::chrono::time_fmt_io_saver<> tmp(std::cout, "%Y-%m-%d %H:%M:%S"); + } + return 0; +} + diff --git a/src/boost/libs/chrono/test/test_11012.cpp b/src/boost/libs/chrono/test/test_11012.cpp new file mode 100644 index 000000000..249b9b891 --- /dev/null +++ b/src/boost/libs/chrono/test/test_11012.cpp @@ -0,0 +1,27 @@ +// Copyright 2015 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt +// See http://www.boost.org/libs/chrono for documentation. + +//#define BOOST_CHRONO_VERSION 1 +#define BOOST_CHRONO_VERSION 2 +#include +#include +#include +//#define BOOST_CHRONO_DONT_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0 +#include + +int main() +{ + { + typedef boost::chrono::duration RationalSeconds; + RationalSeconds d(0.5); + std::cout << d << std::endl; + } + { + typedef boost::chrono::duration > RationalSeconds; + RationalSeconds d; + std::cout << d << std::endl; + } + return 0; +} diff --git a/src/boost/libs/chrono/test/test_12176.cpp b/src/boost/libs/chrono/test/test_12176.cpp new file mode 100644 index 000000000..253d88a15 --- /dev/null +++ b/src/boost/libs/chrono/test/test_12176.cpp @@ -0,0 +1,11 @@ +// Copyright 2016 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt +// See http://www.boost.org/libs/chrono for documentation. + +#include + +int main() +{ + return 0; +} diff --git a/src/boost/libs/chrono/test/test_7868.cpp b/src/boost/libs/chrono/test/test_7868.cpp new file mode 100644 index 000000000..38f658b8c --- /dev/null +++ b/src/boost/libs/chrono/test/test_7868.cpp @@ -0,0 +1,81 @@ +// Copyright 2013 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt +// See http://www.boost.org/libs/chrono for documentation. + +#define BOOST_CHRONO_VERSION 2 +//#define BOOST_CHRONO_PROVIDES_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT 1 + +#include +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + using namespace boost; + using namespace boost::chrono; + boost::chrono::system_clock::time_point atnow= boost::chrono::system_clock::now(); + { + std::stringstream strm; + std::stringstream strm2; + // does not change anything: strm<>atnow2; + strm2<(atnow2 - atnow).count() <(atnow2 - atnow).count(), 0); + std::stringstream formatted; + formatted << time_fmt(boost::chrono::timezone::utc, "%Y-%m-%d %H:%M:%S"); + formatted << "actual:"<< atnow <>atnow2; + strm2<(atnow2 - atnow).count(), 0); + + } + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/test_9337.cpp b/src/boost/libs/chrono/test/test_9337.cpp new file mode 100644 index 000000000..9f3dd7e09 --- /dev/null +++ b/src/boost/libs/chrono/test/test_9337.cpp @@ -0,0 +1,27 @@ +//#define BOOST_CHRONO_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0 +#include +#include +#include +#include + +using namespace std; +using namespace boost::chrono; + +template +void test() +{ + typename Clock::time_point start=Clock::now(); + sleep(1); + typename Clock::time_point stop=Clock::now(); + cout<(); + test(); + test(); + test(); + return 1; +} diff --git a/src/boost/libs/chrono/test/time_point/arithmetic_ext_pass.cpp b/src/boost/libs/chrono/test/time_point/arithmetic_ext_pass.cpp new file mode 100644 index 000000000..6543ac1eb --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/arithmetic_ext_pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#define BOOST_CHRONO_EXTENSIONS +#include +#include +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + +int main() +{ + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(Duration(3)); + t += 2; + BOOST_TEST(t.time_since_epoch() == Duration(5)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(Duration(3)); + t++; + BOOST_TEST(t.time_since_epoch() == Duration(4)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(Duration(3)); + ++t; + BOOST_TEST(t.time_since_epoch() == Duration(4)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(Duration(3)); + t -= 2; + BOOST_TEST(t.time_since_epoch() == Duration(1)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(Duration(3)); + t--; + BOOST_TEST(t.time_since_epoch() == Duration(2)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(Duration(3)); + --t; + BOOST_TEST(t.time_since_epoch() == Duration(2)); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/time_point/arithmetic_pass.cpp b/src/boost/libs/chrono/test/time_point/arithmetic_pass.cpp new file mode 100644 index 000000000..3cfe2e1fa --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/arithmetic_pass.cpp @@ -0,0 +1,151 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + +int main() +{ + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(Duration(3)); + t += Duration(2); + BOOST_TEST(t.time_since_epoch() == Duration(5)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(Duration(3)); + t -= Duration(2); + BOOST_TEST(t.time_since_epoch() == Duration(1)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration1; + typedef boost::chrono::microseconds Duration2; + boost::chrono::time_point t1(Duration1(3)); + boost::chrono::time_point t2 = t1 - Duration2(5); + BOOST_TEST(t2.time_since_epoch() == Duration2(2995)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration1; + typedef boost::chrono::microseconds Duration2; + BOOST_CONSTEXPR boost::chrono::time_point t1(Duration1(3)); + BOOST_CONSTEXPR boost::chrono::time_point t2 = t1 - Duration2(5); + BOOST_CONSTEXPR_ASSERT(t2.time_since_epoch() == Duration2(2995)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration1; + typedef boost::chrono::microseconds Duration2; + boost::chrono::time_point t1(Duration1(3)); + boost::chrono::time_point t2(Duration2(5)); + BOOST_TEST( (t1 - t2) == Duration2(2995)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration1; + typedef boost::chrono::microseconds Duration2; + BOOST_CONSTEXPR boost::chrono::time_point t1(Duration1(3)); + BOOST_CONSTEXPR boost::chrono::time_point t2(Duration2(5)); + BOOST_CONSTEXPR_ASSERT( (t1 - t2) == Duration2(2995)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration1; + typedef boost::chrono::microseconds Duration2; + boost::chrono::time_point t1(Duration1(3)); + boost::chrono::time_point t2 = t1 + Duration2(5); + BOOST_TEST(t2.time_since_epoch() == Duration2(3005)); + t2 = Duration2(6) + t1; + BOOST_TEST(t2.time_since_epoch() == Duration2(3006)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration1; + typedef boost::chrono::microseconds Duration2; + BOOST_CONSTEXPR boost::chrono::time_point t1(Duration1(3)); + BOOST_CONSTEXPR boost::chrono::time_point t2 = t1 + Duration2(5); + BOOST_CONSTEXPR_ASSERT(t2.time_since_epoch() == Duration2(3005)); + BOOST_CONSTEXPR boost::chrono::time_point t3 = Duration2(6) + t1; + BOOST_CONSTEXPR_ASSERT(t3.time_since_epoch() == Duration2(3006)); + } +#ifdef BOOST_CHRONO_EXTENSIONS + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(Duration(3)); + t += 2; + BOOST_TEST(t.time_since_epoch() == Duration(5)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(Duration(3)); + t++; + BOOST_TEST(t.time_since_epoch() == Duration(4)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(Duration(3)); + ++t; + BOOST_TEST(t.time_since_epoch() == Duration(4)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(Duration(3)); + t -= 2; + BOOST_TEST(t.time_since_epoch() == Duration(1)); + } +#if 0 + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration1; + typedef boost::chrono::microseconds Duration2; + boost::chrono::time_point t1(Duration1(3)); + boost::chrono::time_point t2 = t1 - Duration2(5); + BOOST_TEST(t2.time_since_epoch() == Duration2(2995)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration1; + typedef boost::chrono::microseconds Duration2; + boost::chrono::time_point t1(Duration1(3)); + boost::chrono::time_point t2(Duration2(5)); + BOOST_TEST((t1 - t2) == Duration2(2995)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration1; + typedef boost::chrono::microseconds Duration2; + boost::chrono::time_point t1(Duration1(3)); + boost::chrono::time_point t2 = t1 + Duration2(5); + BOOST_TEST(t2.time_since_epoch() == Duration2(3005)); + t2 = Duration2(6) + t1; + BOOST_TEST(t2.time_since_epoch() == Duration2(3006)); + } +#endif +#endif + + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/time_point/comparisons/equal_fail.cpp b/src/boost/libs/chrono/test/time_point/comparisons/equal_fail.cpp new file mode 100644 index 000000000..39327377c --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/comparisons/equal_fail.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// time_points with different clocks should not compare + +#include + +#include "../../clock.h" + +void test() +{ + typedef boost::chrono::system_clock Clock1; + typedef Clock Clock2; + typedef boost::chrono::milliseconds Duration1; + typedef boost::chrono::microseconds Duration2; + typedef boost::chrono::time_point T1; + typedef boost::chrono::time_point T2; + + T1 t1(Duration1(3)); + T2 t2(Duration2(3000)); + t1 == t2; +} diff --git a/src/boost/libs/chrono/test/time_point/comparisons/less_fail.cpp b/src/boost/libs/chrono/test/time_point/comparisons/less_fail.cpp new file mode 100644 index 000000000..de88234fd --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/comparisons/less_fail.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// time_points with different clocks should not compare + +#include + +#include "../../clock.h" + +void test() +{ + typedef boost::chrono::system_clock Clock1; + typedef Clock Clock2; + typedef boost::chrono::milliseconds Duration1; + typedef boost::chrono::microseconds Duration2; + typedef boost::chrono::time_point T1; + typedef boost::chrono::time_point T2; + + T1 t1(Duration1(3)); + T2 t2(Duration2(3000)); + t1 < t2; +} diff --git a/src/boost/libs/chrono/test/time_point/comparisons_pass.cpp b/src/boost/libs/chrono/test/time_point/comparisons_pass.cpp new file mode 100644 index 000000000..b361c9791 --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/comparisons_pass.cpp @@ -0,0 +1,146 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + + +int main() +{ + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration1; + typedef boost::chrono::microseconds Duration2; + typedef boost::chrono::time_point T1; + typedef boost::chrono::time_point T2; + + { + T1 t1(Duration1(3)); + T1 t2(Duration1(3)); + BOOST_TEST( (t1 == t2)); + BOOST_TEST(! (t1 != t2)); + } + { + BOOST_CONSTEXPR T1 t1(Duration1(3)); + BOOST_CONSTEXPR T1 t2(Duration1(3)); + BOOST_CONSTEXPR_ASSERT( (t1 == t2)); + BOOST_CONSTEXPR_ASSERT(! (t1 != t2)); + } + { + T1 t1(Duration1(3)); + T1 t2(Duration1(4)); + BOOST_TEST(! (t1 == t2)); + BOOST_TEST( (t1 != t2)); + } + { + BOOST_CONSTEXPR T1 t1(Duration1(3)); + BOOST_CONSTEXPR T1 t2(Duration1(4)); + BOOST_CONSTEXPR_ASSERT(! (t1 == t2)); + BOOST_CONSTEXPR_ASSERT( (t1 != t2)); + } + { + T1 t1(Duration1(3)); + T2 t2(Duration2(3000)); + BOOST_TEST( (t1 == t2)); + BOOST_TEST(! (t1 != t2)); + } + { + BOOST_CONSTEXPR T1 t1(Duration1(3)); + BOOST_CONSTEXPR T2 t2(Duration2(3000)); + BOOST_CONSTEXPR_ASSERT( (t1 == t2)); + BOOST_CONSTEXPR_ASSERT(! (t1 != t2)); + } + { + T1 t1(Duration1(3)); + T2 t2(Duration2(3001)); + BOOST_TEST(! (t1 == t2)); + BOOST_TEST( (t1 != t2)); + } + { + BOOST_CONSTEXPR T1 t1(Duration1(3)); + BOOST_CONSTEXPR T2 t2(Duration2(3001)); + BOOST_CONSTEXPR_ASSERT(! (t1 == t2)); + BOOST_CONSTEXPR_ASSERT( (t1 != t2)); + } + { + T1 t1(Duration1(3)); + T1 t2(Duration1(3)); + BOOST_TEST(! (t1 < t2)); + BOOST_TEST(! (t1 > t2)); + BOOST_TEST( (t1 <= t2)); + BOOST_TEST( (t1 >= t2)); + } + { + BOOST_CONSTEXPR T1 t1(Duration1(3)); + BOOST_CONSTEXPR T1 t2(Duration1(3)); + BOOST_CONSTEXPR_ASSERT(! (t1 < t2)); + BOOST_CONSTEXPR_ASSERT(! (t1 > t2)); + BOOST_CONSTEXPR_ASSERT( (t1 <= t2)); + BOOST_CONSTEXPR_ASSERT( (t1 >= t2)); + } + { + T1 t1(Duration1(3)); + T1 t2(Duration1(4)); + BOOST_TEST( (t1 < t2)); + BOOST_TEST(! (t1 > t2)); + BOOST_TEST( (t1 <= t2)); + BOOST_TEST(! (t1 >= t2)); + } + { + BOOST_CONSTEXPR T1 t1(Duration1(3)); + BOOST_CONSTEXPR T1 t2(Duration1(4)); + BOOST_CONSTEXPR_ASSERT( (t1 < t2)); + BOOST_CONSTEXPR_ASSERT(! (t1 > t2)); + BOOST_CONSTEXPR_ASSERT( (t1 <= t2)); + BOOST_CONSTEXPR_ASSERT(! (t1 >= t2)); + } + { + T1 t1(Duration1(3)); + T2 t2(Duration2(3000)); + BOOST_TEST(! (t1 < t2)); + BOOST_TEST(! (t1 > t2)); + BOOST_TEST( (t1 <= t2)); + BOOST_TEST( (t1 >= t2)); + } + { + BOOST_CONSTEXPR T1 t1(Duration1(3)); + BOOST_CONSTEXPR T2 t2(Duration2(3000)); + BOOST_CONSTEXPR_ASSERT(! (t1 < t2)); + BOOST_CONSTEXPR_ASSERT(! (t1 > t2)); + BOOST_CONSTEXPR_ASSERT( (t1 <= t2)); + BOOST_CONSTEXPR_ASSERT( (t1 >= t2)); + } + { + T1 t1(Duration1(3)); + T2 t2(Duration2(3001)); + BOOST_TEST( (t1 < t2)); + BOOST_TEST(! (t1 > t2)); + BOOST_TEST( (t1 <= t2)); + BOOST_TEST(! (t1 >= t2)); + } + { + BOOST_CONSTEXPR T1 t1(Duration1(3)); + BOOST_CONSTEXPR T2 t2(Duration2(3001)); + BOOST_CONSTEXPR_ASSERT( (t1 < t2)); + BOOST_CONSTEXPR_ASSERT(! (t1 > t2)); + BOOST_CONSTEXPR_ASSERT( (t1 <= t2)); + BOOST_CONSTEXPR_ASSERT(! (t1 >= t2)); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/time_point/cons/implicit_fail.cpp b/src/boost/libs/chrono/test/time_point/cons/implicit_fail.cpp new file mode 100644 index 000000000..616ca7e11 --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/cons/implicit_fail.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// test for explicit + +#include + +void test() +{ + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t = Duration(3); +} diff --git a/src/boost/libs/chrono/test/time_point/cons/non_implicit_convertible_duration_fail.cpp b/src/boost/libs/chrono/test/time_point/cons/non_implicit_convertible_duration_fail.cpp new file mode 100644 index 000000000..520ca4d73 --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/cons/non_implicit_convertible_duration_fail.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// Duration2 shall be implicitly convertible to duration. + +#include + +void test() +{ + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration1; + typedef boost::chrono::microseconds Duration2; + { + boost::chrono::time_point t2(Duration2(3)); + boost::chrono::time_point t1 = t2; + } +} diff --git a/src/boost/libs/chrono/test/time_point/constructor_pass.cpp b/src/boost/libs/chrono/test/time_point/constructor_pass.cpp new file mode 100644 index 000000000..62a6ed6bc --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/constructor_pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include "../rep.h" +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + +int main() +{ + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::microseconds Duration1; + typedef boost::chrono::milliseconds Duration2; + boost::chrono::time_point t2(Duration2(3)); + boost::chrono::time_point t1 = t2; + BOOST_TEST(t1.time_since_epoch() == Duration1(3000)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::microseconds Duration1; + typedef boost::chrono::milliseconds Duration2; + BOOST_CONSTEXPR boost::chrono::time_point t2(Duration2(3)); + BOOST_CONSTEXPR boost::chrono::time_point t1 = t2; + BOOST_CONSTEXPR_ASSERT(t1.time_since_epoch() == Duration1(3000)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::duration Duration; + boost::chrono::time_point t; + BOOST_TEST(t.time_since_epoch() == Duration::zero()); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::duration Duration; + BOOST_CONSTEXPR boost::chrono::time_point t; + BOOST_CONSTEXPR_ASSERT(t.time_since_epoch() == Duration::zero()); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(Duration(3)); + BOOST_TEST(t.time_since_epoch() == Duration(3)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + BOOST_CONSTEXPR boost::chrono::time_point t(Duration(3)); + BOOST_CONSTEXPR_ASSERT(t.time_since_epoch() == Duration(3)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + boost::chrono::time_point t(boost::chrono::seconds(3)); + BOOST_TEST(t.time_since_epoch() == Duration(3000)); + } + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + BOOST_CONSTEXPR boost::chrono::time_point t(boost::chrono::seconds(3)); + BOOST_CONSTEXPR_ASSERT(t.time_since_epoch() == Duration(3000)); + } + + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/time_point/default_duration.pass.cpp b/src/boost/libs/chrono/test/time_point/default_duration.pass.cpp new file mode 100644 index 000000000..f816b28fc --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/default_duration.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +void test() +{ + BOOST_CHRONO_STATIC_ASSERT((boost::is_same::duration>::value), NOTHING, ()); +} diff --git a/src/boost/libs/chrono/test/time_point/default_duration_pass.cpp b/src/boost/libs/chrono/test/time_point/default_duration_pass.cpp new file mode 100644 index 000000000..f816b28fc --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/default_duration_pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +void test() +{ + BOOST_CHRONO_STATIC_ASSERT((boost::is_same::duration>::value), NOTHING, ()); +} diff --git a/src/boost/libs/chrono/test/time_point/duration.fail.cpp b/src/boost/libs/chrono/test/time_point/duration.fail.cpp new file mode 100644 index 000000000..b48f48e44 --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/duration.fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// Duration shall be an instance of duration. + +#include + +void test() +{ + typedef boost::chrono::time_point T; + T t; +} diff --git a/src/boost/libs/chrono/test/time_point/min_max_pass.cpp b/src/boost/libs/chrono/test/time_point/min_max_pass.cpp new file mode 100644 index 000000000..74926bddf --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/min_max_pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#if defined BOOST_NO_CXX11_NUMERIC_LIMITS || defined BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + +int main() +{ + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::milliseconds Duration; + typedef boost::chrono::time_point TP; + + BOOST_CONSTEXPR_ASSERT((TP::min)() == TP((Duration::min)())); + BOOST_CONSTEXPR_ASSERT((TP::max)() == TP((Duration::max)())); + + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/time_point/not_duration_fail.cpp b/src/boost/libs/chrono/test/time_point/not_duration_fail.cpp new file mode 100644 index 000000000..b48f48e44 --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/not_duration_fail.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// Duration shall be an instance of duration. + +#include + +void test() +{ + typedef boost::chrono::time_point T; + T t; +} diff --git a/src/boost/libs/chrono/test/time_point/time_point_cast_int_fail.cpp b/src/boost/libs/chrono/test/time_point/time_point_cast_int_fail.cpp new file mode 100644 index 000000000..bf16f9a2a --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/time_point_cast_int_fail.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// ToDuration shall be an instantiation of duration. + +#include + +void test() +{ + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::time_point FromTimePoint; + typedef boost::chrono::time_point ToTimePoint; + boost::chrono::time_point_cast(FromTimePoint(boost::chrono::milliseconds(3))); +} diff --git a/src/boost/libs/chrono/test/time_point/time_point_cast_pass.cpp b/src/boost/libs/chrono/test/time_point/time_point_cast_pass.cpp new file mode 100644 index 000000000..133f94c8b --- /dev/null +++ b/src/boost/libs/chrono/test/time_point/time_point_cast_pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif +#ifdef BOOST_NO_CXX11_CONSTEXPR +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_TEST(C) +#else +#include +#define BOOST_CONSTEXPR_ASSERT(C) BOOST_STATIC_ASSERT(C) +#endif + +template +void +test(const FromDuration& df, const ToDuration& d) +{ + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::time_point FromTimePoint; + typedef boost::chrono::time_point ToTimePoint; + FromTimePoint f(df); + ToTimePoint t(d); +//~ #if defined(BOOST_NO_CXX11_DECLTYPE) + //~ typedef BOOST_TYPEOF_TPL(boost::chrono::time_point_cast(f)) R; +//~ #else + //~ typedef decltype(boost::chrono::time_point_cast(f)) R; +//~ #endif + //~ BOOST_CHRONO_STATIC_ASSERT((boost::is_same::value), NOTHING, ()); + BOOST_TEST(boost::chrono::time_point_cast(f) == t); +} + +int main() +{ + test(boost::chrono::milliseconds(7265000), boost::chrono::hours(2)); + test(boost::chrono::milliseconds(7265000), boost::chrono::minutes(121)); + test(boost::chrono::milliseconds(7265000), boost::chrono::seconds(7265)); + test(boost::chrono::milliseconds(7265000), boost::chrono::milliseconds(7265000)); + test(boost::chrono::milliseconds(7265000), boost::chrono::microseconds(7265000000LL)); + test(boost::chrono::milliseconds(7265000), boost::chrono::nanoseconds(7265000000000LL)); + test(boost::chrono::milliseconds(7265000), + boost::chrono::duration >(7265./3600)); + test(boost::chrono::duration >(9), + boost::chrono::duration >(10)); + { + typedef boost::chrono::system_clock Clock; + typedef boost::chrono::time_point FromTimePoint; + typedef boost::chrono::time_point ToTimePoint; + BOOST_CONSTEXPR FromTimePoint f(boost::chrono::milliseconds(7265000)); + BOOST_CONSTEXPR ToTimePoint tph = boost::chrono::time_point_cast(f); + BOOST_CONSTEXPR_ASSERT(tph.time_since_epoch().count() == 2); + } + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/traits/common_type_duration_pass.cpp b/src/boost/libs/chrono/test/traits/common_type_duration_pass.cpp new file mode 100644 index 000000000..f976635ef --- /dev/null +++ b/src/boost/libs/chrono/test/traits/common_type_duration_pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +template +void +test() +{ + typedef typename boost::common_type::type Dc; + BOOST_CHRONO_STATIC_ASSERT((boost::is_same::value), NOTHING, (D1, D2, Dc, De)); +} + +void testall() +{ + test >, + boost::chrono::duration >, + boost::chrono::duration > >(); + test >, + boost::chrono::duration >, + boost::chrono::duration > >(); + test >, + boost::chrono::duration >, + boost::chrono::duration > >(); + test >, + boost::chrono::duration >, + boost::chrono::duration > >(); +} diff --git a/src/boost/libs/chrono/test/traits/common_type_time_point_pass.cpp b/src/boost/libs/chrono/test/traits/common_type_time_point_pass.cpp new file mode 100644 index 000000000..047f7ff05 --- /dev/null +++ b/src/boost/libs/chrono/test/traits/common_type_time_point_pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +template +void +test() +{ + typedef boost::chrono::system_clock C; + typedef boost::chrono::time_point T1; + typedef boost::chrono::time_point T2; + typedef boost::chrono::time_point Te; + typedef typename boost::common_type::type Tc; + BOOST_CHRONO_STATIC_ASSERT((boost::is_same::value), NOTHING, (T1, T2, Tc, Te)); +} + +void testall() +{ + test >, + boost::chrono::duration >, + boost::chrono::duration > >(); + test >, + boost::chrono::duration >, + boost::chrono::duration > >(); + test >, + boost::chrono::duration >, + boost::chrono::duration > >(); + test >, + boost::chrono::duration >, + boost::chrono::duration > >(); +} diff --git a/src/boost/libs/chrono/test/traits/duration_values_pass.cpp b/src/boost/libs/chrono/test/traits/duration_values_pass.cpp new file mode 100644 index 000000000..9d2c07938 --- /dev/null +++ b/src/boost/libs/chrono/test/traits/duration_values_pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include + +#include "../rep.h" + +int main() +{ + BOOST_TEST((boost::chrono::duration_values::min)() == + (std::numeric_limits::min)()); + BOOST_TEST((boost::chrono::duration_values::min)() == + -(std::numeric_limits::max)()); + BOOST_TEST((boost::chrono::duration_values::min)() == + (std::numeric_limits::min)()); + + BOOST_TEST((boost::chrono::duration_values::max)() == + (std::numeric_limits::max)()); + BOOST_TEST((boost::chrono::duration_values::max)() == + (std::numeric_limits::max)()); + BOOST_TEST((boost::chrono::duration_values::max)() == + (std::numeric_limits::max)()); + + BOOST_TEST(boost::chrono::duration_values::zero() == 0); + BOOST_TEST(boost::chrono::duration_values::zero() == 0); + + return boost::report_errors(); +} diff --git a/src/boost/libs/chrono/test/traits/treat_as_floating_point_pass.cpp b/src/boost/libs/chrono/test/traits/treat_as_floating_point_pass.cpp new file mode 100644 index 000000000..6acd8ed74 --- /dev/null +++ b/src/boost/libs/chrono/test/traits/treat_as_floating_point_pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// Adaptation to Boost of the libcxx +// Copyright 2010 Vicente J. Botet Escriba +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +#include +#include + +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +template +void +test() +{ + BOOST_CHRONO_STATIC_ASSERT((boost::is_base_of, + boost::chrono::treat_as_floating_point >::value), NOTHING, ()); +} + +struct A {}; + +void testall() +{ + test(); + test(); + test(); + test(); + test(); + test(); + test(); + test(); +} diff --git a/src/boost/libs/chrono/test/win32_test.cpp b/src/boost/libs/chrono/test/win32_test.cpp new file mode 100644 index 000000000..8790f69fb --- /dev/null +++ b/src/boost/libs/chrono/test/win32_test.cpp @@ -0,0 +1,149 @@ +// boost win32_test.cpp -----------------------------------------------------// + +// Copyright 2010 Vicente J. Botet Escriba + +// Distributed under the Boost Software License, Version 1.0. +// See http://www.boost.org/LICENSE_1_0.txt + +// See http://www.boost.org/libs/chrono for documentation. +#include +#include +#if defined(BOOST_CHRONO_WINDOWS_API) || defined(__CYGWIN__) + +#include +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) +#define NOTHING "" +#endif + +#include +#include +#undef BOOST_USE_WINDOWS_H +#include +#include +#include + +void test() { + { + boost::winapi::LARGE_INTEGER_ a; + LARGE_INTEGER b; + BOOST_CHRONO_STATIC_ASSERT(( + sizeof(boost::winapi::LARGE_INTEGER_)==sizeof(LARGE_INTEGER) + ), NOTHING, (boost::winapi::LARGE_INTEGER_, LARGE_INTEGER)); + BOOST_TEST(( + sizeof(a.QuadPart)==sizeof(b.QuadPart) + )); + BOOST_CHRONO_STATIC_ASSERT(( + offsetof(boost::winapi::LARGE_INTEGER_, QuadPart)==offsetof(LARGE_INTEGER, QuadPart) + ), NOTHING, (boost::winapi::LARGE_INTEGER_, LARGE_INTEGER)); + BOOST_CHRONO_STATIC_ASSERT(( + boost::is_same< + BOOST_TYPEOF(a.QuadPart), + BOOST_TYPEOF(b.QuadPart) + >::value + ), NOTHING, (boost::winapi::LARGE_INTEGER_, LARGE_INTEGER)); + } + + BOOST_CHRONO_STATIC_ASSERT(( + sizeof(boost::winapi::BOOL_)==sizeof(BOOL) + ), NOTHING, (boost::winapi::BOOL_, BOOL)); + BOOST_CHRONO_STATIC_ASSERT(( + boost::is_same::value + ), NOTHING, (boost::winapi::BOOL_, BOOL)); + + BOOST_CHRONO_STATIC_ASSERT(( + sizeof(boost::winapi::DWORD_)==sizeof(DWORD) + ), NOTHING, (boost::winapi::DWORD_, DWORD)); + BOOST_CHRONO_STATIC_ASSERT(( + boost::is_same::value + ), NOTHING, (boost::winapi::DWORD_, DWORD)); + + BOOST_CHRONO_STATIC_ASSERT(( + sizeof(boost::winapi::HANDLE_)==sizeof(HANDLE) + ), NOTHING, (boost::winapi::HANDLE_, HANDLE)); + BOOST_CHRONO_STATIC_ASSERT(( + boost::is_same::value + ), NOTHING, (boost::winapi::HANDLE_, HANDLE)); + + BOOST_CHRONO_STATIC_ASSERT(( + sizeof(boost::winapi::LONG_)==sizeof(LONG) + ), NOTHING, (boost::winapi::LONG_, LONG)); + BOOST_CHRONO_STATIC_ASSERT(( + boost::is_same::value + ), NOTHING, (boost::winapi::LONG_, LONG)); + + BOOST_CHRONO_STATIC_ASSERT(( + sizeof(boost::winapi::LONGLONG_)==sizeof(LONGLONG) + ), NOTHING, (boost::winapi::LONGLONG_, LONGLONG)); + BOOST_CHRONO_STATIC_ASSERT(( + boost::is_same::value + ), NOTHING, (boost::winapi::LONGLONG_, LONGLONG)); + + BOOST_CHRONO_STATIC_ASSERT(( + sizeof(boost::winapi::ULONG_PTR_)==sizeof(ULONG_PTR) + ), NOTHING, (boost::winapi::ULONG_PTR_, ULONG_PTR)); + BOOST_CHRONO_STATIC_ASSERT(( + boost::is_same::value + ), NOTHING, (boost::winapi::ULONG_PTR_, ULONG_PTR)); + + BOOST_CHRONO_STATIC_ASSERT(( + sizeof(boost::winapi::PLARGE_INTEGER_)==sizeof(PLARGE_INTEGER) + ), NOTHING, (boost::winapi::PLARGE_INTEGER_, PLARGE_INTEGER)); + //~ BOOST_CHRONO_STATIC_ASSERT(( + //~ boost::is_same::value + //~ ), NOTHING, (boost::winapi::PLARGE_INTEGER_, PLARGE_INTEGER)); + + { + BOOST_CHRONO_STATIC_ASSERT(( + sizeof(boost::winapi::FILETIME_)==sizeof(FILETIME) + ), NOTHING, (boost::winapi::FILETIME_, FILETIME)); + + BOOST_CHRONO_STATIC_ASSERT(( + sizeof(boost::winapi::PFILETIME_)==sizeof(PFILETIME) + ), NOTHING, (boost::winapi::PFILETIME_, PFILETIME)); + + + boost::winapi::FILETIME_ a; + FILETIME b; + BOOST_TEST(( + sizeof(a.dwLowDateTime)==sizeof(b.dwLowDateTime) + )); + BOOST_TEST(( + sizeof(a.dwHighDateTime)==sizeof(b.dwHighDateTime) + )); + BOOST_CHRONO_STATIC_ASSERT(( + offsetof(boost::winapi::FILETIME_, dwLowDateTime)==offsetof(FILETIME, dwLowDateTime) + ), NOTHING, (boost::winapi::FILETIME_, FILETIME)); + BOOST_CHRONO_STATIC_ASSERT(( + offsetof(boost::winapi::FILETIME_, dwHighDateTime)==offsetof(FILETIME, dwHighDateTime) + ), NOTHING, (boost::winapi::FILETIME_, FILETIME)); + BOOST_CHRONO_STATIC_ASSERT(( + boost::is_same< + BOOST_TYPEOF(a.dwLowDateTime), + BOOST_TYPEOF(b.dwLowDateTime) + >::value + ), NOTHING, (boost::winapi::FILETIME_, FILETIME)); + BOOST_CHRONO_STATIC_ASSERT(( + boost::is_same< + BOOST_TYPEOF(a.dwHighDateTime), + BOOST_TYPEOF(b.dwHighDateTime) + >::value + ), NOTHING, (boost::winapi::FILETIME_, FILETIME)); + + } + +// BOOST_CHRONO_STATIC_ASSERT(( +// GetLastError==boost::winapi::::GetLastError +// ), NOTHING, ()); + +} +#else +void test() { +} +#endif +int main( ) +{ + test(); + + return boost::report_errors(); +} + -- cgit v1.2.3