thread_id.pass.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. //
  9. // UNSUPPORTED: libcpp-has-no-threads
  10. // <thread>
  11. // template <class T>
  12. // struct hash
  13. // : public unary_function<T, size_t>
  14. // {
  15. // size_t operator()(T val) const;
  16. // };
  17. // Not very portable
  18. #include <thread>
  19. #include <cassert>
  20. #include "test_macros.h"
  21. int main(int, char**)
  22. {
  23. std::thread::id id1;
  24. std::thread::id id2 = std::this_thread::get_id();
  25. typedef std::hash<std::thread::id> H;
  26. static_assert((std::is_same<typename H::argument_type, std::thread::id>::value), "" );
  27. static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
  28. ASSERT_NOEXCEPT(H()(id2));
  29. H h;
  30. assert(h(id1) != h(id2));
  31. return 0;
  32. }