op_+.pass.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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(m.count() == m2.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(m.count() == m2.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. }
  38. return 0;
  39. }