op_-.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <chrono>
  9. // duration
  10. // constexpr common_type_t<duration> operator-() const;
  11. #include <chrono>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. int main(int, char**)
  15. {
  16. {
  17. const std::chrono::minutes m(3);
  18. std::chrono::minutes m2 = -m;
  19. assert(m2.count() == -m.count());
  20. }
  21. #if TEST_STD_VER >= 11
  22. {
  23. constexpr std::chrono::minutes m(3);
  24. constexpr std::chrono::minutes m2 = -m;
  25. static_assert(m2.count() == -m.count(), "");
  26. }
  27. #endif
  28. // P0548
  29. {
  30. typedef std::chrono::duration<int, std::ratio<10,10> > D10;
  31. typedef std::chrono::duration<int, std::ratio< 1, 1> > D1;
  32. D10 zero(0);
  33. D10 one(1);
  34. static_assert( (std::is_same< decltype(-one), decltype(zero-one) >::value), "");
  35. static_assert( (std::is_same< decltype(zero-one), D1>::value), "");
  36. static_assert( (std::is_same< decltype(-one), D1>::value), "");
  37. static_assert( (std::is_same< decltype(+one), D1>::value), "");
  38. }
  39. return 0;
  40. }