jam@DESKTOP-SJO8SMG:/mnt/c/Users/samu$ g++ -o version version.cpp -I . jam@DESKTOP-SJO8SMG:/mnt/c/Users/samu$ ./version 107100 1_71 linux GNU C++ version 9.3.0 GNU libstdc++ version 20200808
doubleelapsed_max()const// return estimated maximum value for elapsed() // Portability warning: elapsed_max() may return too high a value on systems // where std::clock_t overflows or resets at surprising values. { return (double((std::numeric_limits<std::clock_t>::max)()) - double(_start_time)) / double(CLOCKS_PER_SEC); }
doubleelapsed_min()const// return minimum value for elapsed() { returndouble(1)/double(CLOCKS_PER_SEC); }
jam@DESKTOP-SJO8SMG:/mnt/c/Users/samu$ g++ timerp.cpp -o timerp In file included from /usr/include/boost/config/header_deprecated.hpp:18, from /usr/include/boost/timer.hpp:20, from timerp.cpp:2: /usr/include/boost/timer.hpp:21:1: note: #pragma message: This header is deprecated. Use the facilities in <boost/timer/timer.hpp> instead. 21 | BOOST_HEADER_DEPRECATED( "the facilities in <boost/timer/timer.hpp>" ) | ^~~~~~~~~~~~~~~~~~~~~~~ jam@DESKTOP-SJO8SMG:/mnt/c/Users/samu$ ./timerp 最大时间间隔: 2.56205e+09h 最小时间间隔:1e-06s 时间过去了0.000287s 巴拉巴拉巴拉巴 重启后现在时间过去了4e-06s
classprogress_timer : public timer, private noncopyable { public: explicitprogress_timer( std::ostream & os = std::cout ) // os is hint; implementation may ignore, particularly in embedded systems : timer(), noncopyable(), m_os(os) {} ~progress_timer() { // A) Throwing an exception from a destructor is a Bad Thing. // B) The progress_timer destructor does output which may throw. // C) A progress_timer is usually not critical to the application. // Therefore, wrap the I/O in a try block, catch and ignore all exceptions. try { // use istream instead of ios_base to workaround GNU problem (Greg Chicares) std::istream::fmtflags old_flags = m_os.setf( std::istream::fixed, std::istream::floatfield ); std::streamsize old_prec = m_os.precision( 2 ); m_os << elapsed() << " s\n"// "s" is System International d'Unites std << std::endl; m_os.flags( old_flags ); m_os.precision( old_prec ); }
catch (...) {} // eat any exceptions } // ~progress_timer
template<classT, classcalendar, classduration_type_> classBOOST_SYMBOL_VISIBLE date : private boost::less_than_comparable<T, boost::equality_comparable<T> > { public: typedef T date_type; typedef calendar calendar_type; typedeftypename calendar::date_traits_type traits_type; typedef duration_type_ duration_type; typedeftypename calendar::year_type year_type; typedeftypename calendar::month_type month_type; typedeftypename calendar::day_type day_type; typedeftypename calendar::ymd_type ymd_type; typedeftypename calendar::date_rep_type date_rep_type; typedeftypename calendar::date_int_type date_int_type; typedeftypename calendar::day_of_week_type day_of_week_type; date(year_type y, month_type m, day_type d) : days_(calendar::day_number(ymd_type(y, m, d))){} date(const ymd_type& ymd) : days_(calendar::day_number(ymd)){} //let the compiler write copy, assignment, and destructor year_type year()const month_type month()const day_type day()const day_of_week_type day_of_week()const ymd_type year_month_day()const booloperator<(const date_type& rhs)const booloperator==(const date_type& rhs) const //! check to see if date is a special value boolis_special()const //! check to see if date is not a value boolis_not_a_date() const //! check to see if date is one of the infinity values boolis_infinity() const //! check to see if date is greater than all possible dates boolis_pos_infinity() const //! check to see if date is greater than all possible dates boolis_neg_infinity() const //! return as a special value or a not_special if a normal date special_values as_special() const duration_type operator-(const date_type& d) const
//see reference protected: /*! This is a private constructor which allows for the creation of new dates. It is not exposed to users since that would require class users to understand the inner workings of the date class. */ explicitdate(date_int_type days) : days_(days) explicitdate(date_rep_type days) : days_(days.as_number()) date_int_type days_; };
//定义时间点 date d1(2021, 12, 14); date d2(1997, Apr, 10); date d3 = from_string("2000-0-0"); date d4( from_string("2004-8-11") ); date d5 = from_undelimited_string("20160913");
//输出时间点 cout << d1 << endl; cout << "Today is the " << d1.day_of_week() << "th day in the week." << endl; cout << "This week is the " << d1.week_number() << "th week in this year." << endl;
[root@DESKTOP-SJO8SMG samu]# g++ timerp.cpp -o timerp /usr/local/lib/libboost_date_time.a [root@DESKTOP-SJO8SMG samu]# ./timerp terminate called after throwing an instance of 'boost::wrapexcept<boost::gregorian::bad_day_of_month>' what(): Day of month value is out of range 1..31 Aborted (core dumped)
[root@DESKTOP-SJO8SMG samu]# g++ timerp.cpp -o timerp /usr/local/lib/libboost_date_time.a#有资料说不需要-l参数,直接链接即可,加上反而出错 [root@DESKTOP-SJO8SMG samu]# ./timerp 2021-Dec-14 2021-Dec-14 2021-Dec-14 Today is the Tue day in the week. This week is the 50th week in this year. -infinity +infinity 9999-Dec-31 1400-Jan-01
template<classT, typename rep_type> classBOOST_SYMBOL_VISIBLE time_duration : private boost::less_than_comparable<T, boost::equality_comparable<T> > /* dividable, addable, and subtractable operator templates * won't work with this class (MSVC++ 6.0). return type * from '+=' is different than expected return type * from '+'. multipliable probably wont work * either (haven't tried) */ { public: // A tag for type categorization. Can be used to detect Boost.DateTime duration types in generic code. typedefvoid _is_boost_date_time_duration; typedef T duration_type; //the subclass typedef rep_type traits_type; typedeftypename rep_type::day_type day_type; typedeftypename rep_type::hour_type hour_type; typedeftypename rep_type::min_type min_type; typedeftypename rep_type::sec_type sec_type; typedeftypename rep_type::fractional_seconds_type fractional_seconds_type; typedeftypename rep_type::tick_type tick_type; typedeftypename rep_type::impl_type impl_type;
time_duration() : ticks_(0) {} time_duration(hour_type hours_in, min_type minutes_in, sec_type seconds_in=0, fractional_seconds_type frac_sec_in = 0) : ticks_(rep_type::to_tick_count(hours_in,minutes_in,seconds_in,frac_sec_in)) {} // copy constructor required for dividable<> //! Construct from another time_duration (Copy constructor) time_duration(const time_duration<T, rep_type>& other) : ticks_(other.ticks_) {} //! Construct from special_values time_duration(special_values sv) : ticks_(impl_type::from_special(sv)) {} //! Returns smallest representable duration static duration_type unit() //! Return the number of ticks in a second static tick_type ticks_per_second() //! Provide the resolution of this duration type static time_resolutions resolution() //! Returns number of hours in the duration hour_type hours()const //! Returns normalized number of minutes min_type minutes()const //! Returns normalized number of seconds (0..60) sec_type seconds()const //! Returns total number of seconds truncating any fractional seconds sec_type total_seconds()const //! Returns total number of milliseconds truncating any fractional seconds tick_type total_milliseconds()const //! Returns total number of nanoseconds truncating any sub millisecond values tick_type total_nanoseconds()const //! Returns total number of microseconds truncating any sub microsecond values tick_type total_microseconds()const //! Returns count of fractional seconds at given resolution fractional_seconds_type fractional_seconds()const //! Returns number of possible digits in fractional seconds staticunsignedshortnum_fractional_digits() duration_type invert_sign()const boolis_negative()const booloperator<(const time_duration& rhs)const booloperator==(const time_duration& rhs) const //! unary- Allows for time_duration td = -td1 duration_type operator-()const duration_type operator-(const duration_type& d) const duration_type operator+(const duration_type& d) const duration_type operator/(int divisor) const duration_type operator-=(const duration_type& d) duration_type operator+=(const duration_type& d) //! Division operations on a duration with an integer. duration_type operator/=(int divisor) //! Multiplication operations an a duration with an integer duration_type operator*(int rhs) const duration_type operator*=(int divisor) tick_type ticks() const //! Is ticks_ a special value? boolis_special()const //! Is duration pos-infinity boolis_pos_infinity()const //! Is duration neg-infinity boolis_neg_infinity()const //! Is duration not-a-date-time boolis_not_a_date_time()const //! Used for special_values output impl_type get_rep()const