error_condition.pass.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. // <functional>
  9. // template <class T>
  10. // struct hash
  11. // : public unary_function<T, size_t>
  12. // {
  13. // size_t operator()(T val) const;
  14. // };
  15. #include <system_error>
  16. #include <cassert>
  17. #include <type_traits>
  18. #include "test_macros.h"
  19. void
  20. test(int i)
  21. {
  22. typedef std::error_condition T;
  23. typedef std::hash<T> H;
  24. static_assert((std::is_same<H::argument_type, T>::value), "" );
  25. static_assert((std::is_same<H::result_type, std::size_t>::value), "" );
  26. ASSERT_NOEXCEPT(H()(T()));
  27. H h;
  28. T ec(i, std::system_category());
  29. const std::size_t result = h(ec);
  30. LIBCPP_ASSERT(result == static_cast<std::size_t>(i));
  31. ((void)result); // Prevent unused warning
  32. }
  33. int main(int, char**)
  34. {
  35. test(0);
  36. test(2);
  37. test(10);
  38. return 0;
  39. }