How can I find out what type the compiler deduced when using the auto keyword?
Example 1: Simpler
auto tickTime = 0.001;
W
This SO answer gives a nice function for printing out the name of a type (actually a couple of implementations).
Additionally this free, open-source, header-only library gives a nice way to print out the value and type of chrono::durations.
Putting these two utilities together:
#include "chrono_io.h"
#include "type_name.h"
#include
#include
int
main()
{
using namespace date;
typedef std::ratio<1, 1> sec;
std::chrono::duration timePerTick2{0.001};
auto nextTickTime = std::chrono::high_resolution_clock::now() + timePerTick2;
std::cout << type_name() << '\n';
std::cout << std::setprecision(12) << nextTickTime.time_since_epoch() << '\n';
}
This output for me:
std::__1::chrono::time_point > >
4.8530542088e+14ns