Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::chrono::clock_time_conversion

      From cppreference.com
      <cpp‎ |chrono
       
       
      Date and time library
      Time point
      (C++11)
      clock_time_conversion
      (C++20)  
      (C++20)
      Duration
      (C++11)
      Clocks
      (C++20)
      (C++20)
      (C++20)
      (C++20)
      (C++20)
      (C++20)
      Time of day
      (C++20)(C++20)
      (C++20)(C++20)
      (C++20)
       
      Defined in header<chrono>
      template<class Dest,class Source>
      struct clock_time_conversion{};
      (since C++20)

      std::chrono::clock_time_conversion is a trait that specifies how to convert astd::chrono::time_point of theSource clock to that of theDest clock. It does so by providing a const-callableoperator() that accepts an argument of typestd::chrono::time_point<Source, Duration> and returns astd::chrono::time_point<Dest, OtherDuration> that represents an equivalent point in time. The duration of the returned time point is computed from the source duration in a manner that varies for each specialization.clock_time_conversion is normally only used indirectly, viastd::chrono::clock_cast.

      A program may specializeclock_time_conversion if at least one of the template parameters is a user-defined clock type.

      The primary template is an empty struct. The standard defines the following specializations:

      template<class Clock>
      struct clock_time_conversion<Clock, Clock>;
      (1)(since C++20)
      template<>
      struct clock_time_conversion<std::chrono::system_clock,std::chrono::system_clock>;
      (2)(since C++20)
      template<>
      struct clock_time_conversion<std::chrono::utc_clock,std::chrono::utc_clock>;
      (3)(since C++20)
      template<>
      struct clock_time_conversion<std::chrono::system_clock,std::chrono::utc_clock>;
      (4)(since C++20)
      template<>
      struct clock_time_conversion<std::chrono::utc_clock,std::chrono::system_clock>;
      (5)(since C++20)
      template<class Clock>
      struct clock_time_conversion<Clock,std::chrono::system_clock>;
      (6)(since C++20)
      template<class Clock>
      struct clock_time_conversion<std::chrono::system_clock, Clock>;
      (7)(since C++20)
      template<class Clock>
      struct clock_time_conversion<Clock,std::chrono::utc_clock>;
      (8)(since C++20)
      template<class Clock>
      struct clock_time_conversion<std::chrono::utc_clock, Clock>;
      (9)(since C++20)
      1-3) Identity conversion:operator() returns a copy of the argument.
      4,5) Conversions betweenstd::chrono::sys_time andstd::chrono::utc_time:operator() callsstd::chrono::utc_clock::to_sys andstd::chrono::utc_clock::from_sys, respectively.
      6,7) Conversions to and fromstd::chrono::sys_time whenClock supportsfrom_sys andto_sys:operator() callsClock::to_sys andClock::from_sys, respectively.
      8,9) Conversions to and fromstd::chrono::utc_time whenClock supportsfrom_utc andto_utc:operator() callsClock::to_utc andClock::from_utc, respectively.

      Contents

      [edit]Member functions

      Each specialization has an implicitly-declared default constructor, copy constructor, move constructor, copy assignment operator, move assignment operator, and destructor.

      std::chrono::clock_time_conversion::operator()

      template<class Duration>

      std::chrono::time_point<Clock, Duration>

          operator()(conststd::chrono::time_point<Clock, Duration>& t)const;
      (1)(member of specialization(1))
      template<class Duration>

      std::chrono::sys_time<Duration>

          operator()(conststd::chrono::sys_time<Duration>& t)const;
      (2)(member of specialization(2))
      template<class Duration>

      std::chrono::utc_time<Duration>

          operator()(conststd::chrono::utc_time<Duration>& t)const;
      (3)(member of specialization(3))
      template<class Duration>

      std::chrono::sys_time<Duration>

          operator()(conststd::chrono::utc_time<Duration>& t)const;
      (4)(member of specialization(4))
      template<class Duration>

      std::chrono::utc_time<Duration>

          operator()(conststd::chrono::sys_time<Duration>& t)const;
      (5)(member of specialization(5))
      template<class Duration>

      auto operator()(conststd::chrono::sys_time<Duration>& t)const

         -> decltype(Clock::from_sys(t));
      (6)(member of specialization(6))
      template<class Duration>

      auto operator()(conststd::chrono::time_point<SourceClock, Duration>& t)const

         -> decltype(Clock::to_sys(t));
      (7)(member of specialization(7))
      template<class Duration>

      auto operator()(conststd::chrono::utc_time<Duration>& t)const

         -> decltype(Clock::from_utc(t));
      (8)(member of specialization(8))
      template<class Duration>

      auto operator()(conststd::chrono::time_point<Clock, Duration>& t)const

         -> decltype(Clock::to_utc(t));
      (9)(member of specialization(9))

      Converts the argumentstd::chrono::time_point to the destination clock.

      1-3) Identity conversion. Returnst unchanged.
      6) ReturnsClock::from_sys(t). This overload participates in overload resolution only if the expressionClock::from_sys(t) is well-formed. The program is ill-formed ifClock::from_sys(t) does not returnstd::chrono::time_point<Clock, Duration> whereDuration is some valid specialization ofstd::chrono::duration.
      7) ReturnsClock::to_sys(t). This overload participates in overload resolution only if the expressionClock::to_sys(t) is well-formed. The program is ill-formed ifClock::to_sys(t) does not returnstd::chrono::sys_time<Duration> whereDuration is some valid specialization ofstd::chrono::duration.
      8) ReturnsClock::from_utc(t). This overload participates in overload resolution only if the expressionClock::from_utc(t) is well-formed. The program is ill-formed ifClock::from_utc(t) does not returnstd::chrono::time_point<Clock, Duration> whereDuration is some valid specialization ofstd::chrono::duration.
      9) ReturnsClock::to_utc(t). This overload participates in overload resolution only if the expressionClock::to_utc(t) is well-formed. The program is ill-formed ifClock::to_utc(t) does not returnstd::chrono::utc_time<Duration> whereDuration is some valid specialization ofstd::chrono::duration.

      Parameters

      t - time point to convert

      Return value

      The result of the conversion as described above:

      1-3)t.
      6)Clock::from_sys(t).
      7)Clock::to_sys(t).
      8)Clock::from_utc(t).
      9)Clock::to_utc(t).

      [edit]See also

      (C++20)
      convert time points of one clock to another
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/chrono/clock_time_conversion&oldid=157493"

      [8]ページ先頭

      ©2009-2025 Movatter.jp