error_condition.pass.cpp 1.1 KB

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