1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// UNSUPPORTED: c++98, c++03, c++11, c++14
11
12// <chrono>
13
14// abs
15
16// template <class Rep, class Period>
17//   constexpr duration<Rep, Period> abs(duration<Rep, Period> d)
18
19#include <chrono>
20#include <type_traits>
21#include <cassert>
22
23template <class Duration>
24void
25test(const Duration& f, const Duration& d)
26{
27    {
28    typedef decltype(std::chrono::abs(f)) R;
29    static_assert((std::is_same<R, Duration>::value), "");
30    assert(std::chrono::abs(f) == d);
31    }
32}
33
34int main()
35{
36//  7290000ms is 2 hours, 1 minute, and 30 seconds
37    test(std::chrono::milliseconds( 7290000), std::chrono::milliseconds( 7290000));
38    test(std::chrono::milliseconds(-7290000), std::chrono::milliseconds( 7290000));
39    test(std::chrono::minutes( 122), std::chrono::minutes( 122));
40    test(std::chrono::minutes(-122), std::chrono::minutes( 122));
41    test(std::chrono::hours(0), std::chrono::hours(0));
42
43    {
44//  9000000ms is 2 hours and 30 minutes
45    constexpr std::chrono::hours h1 = std::chrono::abs(std::chrono::hours(-3));
46    static_assert(h1.count() == 3, "");
47    constexpr std::chrono::hours h2 = std::chrono::abs(std::chrono::hours(3));
48    static_assert(h2.count() == 3, "");
49    }
50}
51