resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmDuration.cxx
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #define CMDURATION_CPP
4 #include "cmDuration.h"
5
6 template <typename T>
7 T cmDurationTo(const cmDuration& duration)
8 {
9   /* This works because the comparison operators for duration rely on
10    * std::common_type.
11    * So for example duration<int>::max() gets promoted to a duration<double>,
12    * which can then be safely compared.
13    */
14   if (duration >= std::chrono::duration<T>::max()) {
15     return std::chrono::duration<T>::max().count();
16   }
17   if (duration <= std::chrono::duration<T>::min()) {
18     return std::chrono::duration<T>::min().count();
19   }
20   // Ensure number of seconds by defining ratio<1>
21   return std::chrono::duration_cast<std::chrono::duration<T, std::ratio<1>>>(
22            duration)
23     .count();
24 }
25
26 template int cmDurationTo<int>(const cmDuration&);
27 template unsigned int cmDurationTo<unsigned int>(const cmDuration&);