std::chrono...::time_point(3)
okay bestie, welcome to std::chrono...::time_point(3) from the C++ Standard Libary manual β yes, the manual name is folded in right here, and we are keeping the typo iconic. π
π NAME π
std::chrono::time_point::time_point β that's the constructor, and its name is literally std::chrono::time_point::time_point, repeated like a queen. π
π¦ Synopsis π¦
the synopsis, with all the (since C++11) and (constexpr since C++14) receipts:
time_point(); (1) (since C++11) (constexpr since C++14)
explicit time_point( const duration& d ); (2) (since C++11) (constexpr since C++14)
template< class Duration2 >
time_point( const time_point<Clock, Duration2>& t ); (3) (since C++11) (constexpr since C++14)
Constructs a new time_point from one of several optional data sources. β¨
- Default constructor β creates a
time_pointrepresenting theClock's epoch (i.e.,time_since_epoch()is zero). π°οΈ - Constructs a
time_pointatClock's epoch plusd. β - Constructs a
time_pointby convertingttoduration. This constructor only participates in overload resolution ifDuration2is implicitly convertible toduration. π§
πΈ Parameters πΈ
dβ adurationto copy from. π«tβ atime_pointto convert from. π¦
β¨ Example β¨
the page literally says // Run this code, so here's the whole thing, bestie β no cap:
#include <chrono>
#include <iostream>
using Clock = std::chrono::steady_clock;
using TimePoint = std::chrono::time_point<Clock>;
void print_ms(const TimePoint& point)
{
using Ms = std::chrono::milliseconds;
const Clock::duration since_epoch = point.time_since_epoch();
std::cout << std::chrono::duration_cast<Ms>(since_epoch) << '\n';
}
int main()
{
const TimePoint default_value = TimePoint(); // (1)
print_ms(default_value); // 0ms
const Clock::duration duration_4_seconds = std::chrono::seconds(4);
const TimePoint time_point_4_seconds(duration_4_seconds); // (2)
// 4 seconds from start of epoch
print_ms(time_point_4_seconds); // 4000ms
const TimePoint time_point_now = Clock::now(); // (3)
print_ms(time_point_now); // 212178842ms
}
π Possible output: π
0ms
4000ms
212178842ms
π See also π
- constructor β constructs new
duration(public member function ofstd::chrono::duration<Rep,Period>). π duration_castβ converts adurationto another, with a different tick interval (C++11) (function template). β
mwah π β source/version: http://cppreference.com, date: 2024.06.10, and yeah, this was std::chrono...::time_point(3). π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms