简体   繁体   English

如何获取std :: chrono :: time_point时钟类型

[英]How to get std::chrono::time_point clock type

I have a class with a std::chrono::time_point member. 我有一个带有std :: chrono :: time_point成员的类。 In one of the class functions I want to create another time_point with the same clock type. 在一个类函数中,我想创建另一个具有相同时钟类型的time_point。

How do I take the clock type from my member? 如何从会员那里获取时钟类型?

I tried doing: 我试着做:

std::chrono::time_point<std::chrono::system_clock> m_time_point;
std::chrono::time_point<m_time_point.clock> new_tp(some_duration)

but this results with an error: cannot refer to type member 'clock' in 'std::chrono::time_point' with '.' 但这会导致错误:无法用'。'引用'std :: chrono :: time_point'中的类型成员'clock'。

std::chrono::time_point is a template, not a type. std::chrono::time_point是模板,而不是类型。 So you can't have a member with this type, it has to be instantiated with some type of the clock. 因此,您不能拥有这种类型的成员,必须使用某种类型的时钟实例化它。 Assuming you have it, and you member name is m_time_point , getting to clock is trivial: 假设您拥有它,并且您的成员名称是m_time_point ,那么开始计时很简单:

using clock_t = decltype(m_time_point)::clock;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从std :: chrono :: system_clock :: time_point.time_since_epoch()。count()获取std :: chrono :: system_clock :: time_point? - How to get std::chrono::system_clock::time_point from std::chrono::system_clock::time_point.time_since_epoch().count()? 二进制&#39;&gt; =&#39;:&#39;std :: chrono :: system_clock :: time_point&#39; - binary '>=': 'std::chrono::system_clock::time_point' boost :: serialize和std :: chrono :: system_clock :: time_point - boost::serialize and std::chrono::system_clock::time_point 持久性 std::chrono time_point<steady_clock></steady_clock> - Persistent std::chrono time_point<steady_clock> 是 std::atomic <std::optional<std::chrono::time_point<std::chrono::system_clock> &gt;&gt; 有效/安全? </std::optional<std::chrono::time_point<std::chrono::system_clock> - Is std::atomic<std::optional<std::chrono::time_point<std::chrono::system_clock>>> valid/safe? 如何正确地将字符串转换为 std::chrono::system_clock::time_point? - How to properly convert string to std::chrono::system_clock::time_point? std :: string到std :: chrono time_point - std::string to std::chrono time_point 如何从boost :: chrono :: hight_resolution_clock :: time_point获得纳秒? - How to get nanoseconds from boost::chrono::hight_resolution_clock::time_point? std :: chrono :: time_point设置为现在 - std::chrono::time_point set to now std :: chrono :: time_point无效值 - std::chrono::time_point invalid value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM