1 /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 file Copyright.txt or https://cmake.org/licensing for details. */
4 #include "cmDuration.h"
7 T cmDurationTo(const cmDuration& duration)
9 /* This works because the comparison operators for duration rely on
11 * So for example duration<int>::max() gets promoted to a duration<double>,
12 * which can then be safely compared.
14 if (duration >= std::chrono::duration<T>::max()) {
15 return std::chrono::duration<T>::max().count();
17 if (duration <= std::chrono::duration<T>::min()) {
18 return std::chrono::duration<T>::min().count();
20 // Ensure number of seconds by defining ratio<1>
21 return std::chrono::duration_cast<std::chrono::duration<T, std::ratio<1>>>(
26 template int cmDurationTo<int>(const cmDuration&);
27 template unsigned int cmDurationTo<unsigned int>(const cmDuration&);