Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

Why the need for a sub-namespace std::chrono?

$
0
0

I've taken this example from B.Stroustrup's new book "TCPL" at page 119.

#include <iostream>
#include <thread>
//#include <chrono>
//using namespace std::chrono; // see §35.2
int main()
{
    auto t0 = std::chrono::high_resolution_clock::now();
    std::this_thread::sleep_for(std::chrono::milliseconds{20});
    auto t1 = std::chrono::high_resolution_clock::now();
    std::cout << std::chrono::duration_cast<std::chrono::nanoseconds>(t1-t0).count() << " nanoseconds passed\n";
}

I have two questions about this code:

  1. Why the need for a sub-namespace std::chrono?
  2. In clang and gcc the output is about 20.1 millions nanoseconds. For VS2013 is 27.2 millions nanoseconds. Any explanation for such a big difference?

Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>