4 ms·
Hard disagree. There are times when nobody, really nobody, cares about a given type. See the example of std::chrono::steady_clock::now over at cppreference.co
by guenthert 10mo ago
Hard disagree. There are times when nobody, really nobody, cares about a given type. See the example of std::chrono::steady_clock::now over at cppreference.com. There you have
const auto start = std::chrono::steady_clock::now();
do_some_work(size);
const auto end = std::chrono::steady_clock::now();
const std::chrono::duration<double> diff = end - start;
std::cout << "diff = " << diff << "; size = " << size << '\n';
Looking up the (current standard's) return type of std::chrono::steady_clock::now() and spelling it out would serve no purpose here.
- cjfd 10mo agoWith 'auto' it is so very verbose. It can be shorter. Let us put "using TP = std::chrono::steady_clock::time_point;" in some header file to be used in many places. Now you can write TP start = TP::clock::now(); do_some_work(size); TP end = TP::clock::now();
- UncleMeat 10mo agoSome organizations don't like putting using declarations in headers since now you've got a global uniqueness requirement for the name "TP."
- dosshell 10mo agoYou put the using as class member (private) or as local in the function.
- moregrist 10mo agoI prefer to put the `using` in the block where you need the std::chrono code, which keeps it local and tidy. Putting it in a header is declaring a global type and asking for trouble; at least bound it in a namespace or a class.
- gpderetta 10mo agohow is TP more descriptive than auto here?
- am17an 10mo agoI agree, this would be in the same vein as "STL returns a verbose type, it's okay to use auto here because no-one cares"