hash_shared_ptr.pass.cpp 1.1 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. // <memory>
  9. // template <class T>
  10. // struct hash<shared_ptr<T>>
  11. // {
  12. // typedef shared_ptr<T> argument_type;
  13. // typedef size_t result_type;
  14. // size_t operator()(const shared_ptr<T>& p) const;
  15. // };
  16. #include <memory>
  17. #include <cassert>
  18. #if TEST_STD_VER >= 11
  19. #include "poisoned_hash_helper.h"
  20. #include "test_macros.h"
  21. struct A {};
  22. #endif
  23. int main(int, char**)
  24. {
  25. {
  26. int* ptr = new int;
  27. std::shared_ptr<int> p(ptr);
  28. std::hash<std::shared_ptr<int> > f;
  29. std::size_t h = f(p);
  30. assert(h == std::hash<int*>()(ptr));
  31. }
  32. #if TEST_STD_VER >= 11
  33. {
  34. test_hash_enabled_for_type<std::shared_ptr<int>>();
  35. test_hash_enabled_for_type<std::shared_ptr<A>>();
  36. }
  37. #endif
  38. return 0;
  39. }