diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 | 
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 | 
| commit | b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d (patch) | |
| tree | 13f237c02db4d1894ab06884d1b739344766bede /test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp | |
| parent | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (diff) | |
Notes
Diffstat (limited to 'test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp')
| -rw-r--r-- | test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp | 50 | 
1 files changed, 50 insertions, 0 deletions
diff --git a/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp b/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp new file mode 100644 index 000000000000..ec32c37a9423 --- /dev/null +++ b/test/std/utilities/time/time.duration/time.duration.alg/abs.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +//                     The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// UNSUPPORTED: c++03, c++11, c++14 + +// <chrono> + +// abs + +// template <class Rep, class Period> +//   constexpr duration<Rep, Period> abs(duration<Rep, Period> d) + +#include <chrono> +#include <type_traits> +#include <cassert> + +template <class Duration> +void +test(const Duration& f, const Duration& d) +{ +    { +    typedef decltype(std::chrono::abs(f)) R; +    static_assert((std::is_same<R, Duration>::value), ""); +    assert(std::chrono::abs(f) == d); +    } +} + +int main() +{ +//  7290000ms is 2 hours, 1 minute, and 30 seconds +    test(std::chrono::milliseconds( 7290000), std::chrono::milliseconds( 7290000)); +    test(std::chrono::milliseconds(-7290000), std::chrono::milliseconds( 7290000)); +    test(std::chrono::minutes( 122), std::chrono::minutes( 122)); +    test(std::chrono::minutes(-122), std::chrono::minutes( 122)); +    test(std::chrono::hours(0), std::chrono::hours(0)); + +    { +//  9000000ms is 2 hours and 30 minutes +    constexpr std::chrono::hours h1 = std::chrono::abs(std::chrono::hours(-3)); +    static_assert(h1.count() == 3, ""); +    constexpr std::chrono::hours h2 = std::chrono::abs(std::chrono::hours(3)); +    static_assert(h2.count() == 3, ""); +    } +}  | 
