Epic
Epic

Reputation: 622

How to get std::chrono::time_point clock type

I have a class with a std::chrono::time_point member. In one of the class functions I want to create another time_point with the same clock type.

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 '.'

Upvotes: 3

Views: 515

Answers (1)

SergeyA
SergeyA

Reputation: 62573

std::chrono::time_point is a template, not a type. 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:

using clock_t = decltype(m_time_point)::clock;

Upvotes: 5

Related Questions