According to the reference, when you call count()
on a std::chrono::seconds
variable, you get the result as the data type rep
. Rep
is short for "representation".
#include <chrono>
#include <thread>
int main()
{
using namespace std::chrono_literals;
std::chrono::time_point<std::chrono::steady_clock> t1 = std::chrono::steady_clock::now();
std::this_thread::sleep_for(2s);
std::chrono::time_point<std::chrono::steady_clock> t2 = std::chrono::steady_clock::now();
auto count = std::chrono::duration_cast<std::chrono::seconds>(t2 - t1).count();
auto sizeInBytes = sizeof(count);
size_t countCasted = count; // The warning is produced for this line
return 0;
}
When I compile this with C++14 for x86, I get following warning:
warning C4244: "Initialization": Conversion from "_Rep" to size_t, possible loss of data
sizeInBytes
on x86: 8sizeInBytes
on x64: 8
Is sizeof(count)
always 8? Why doesn't count()
return size_t
?