bitset.pass.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 <bitset>
  16. #include <cassert>
  17. #include <type_traits>
  18. #include "test_macros.h"
  19. template <std::size_t N>
  20. void
  21. test()
  22. {
  23. typedef std::bitset<N> T;
  24. typedef std::hash<T> H;
  25. static_assert((std::is_same<typename H::argument_type, T>::value), "" );
  26. static_assert((std::is_same<typename H::result_type, std::size_t>::value), "" );
  27. ASSERT_NOEXCEPT(H()(T()));
  28. H h;
  29. T bs(static_cast<unsigned long long>(N));
  30. const std::size_t result = h(bs);
  31. LIBCPP_ASSERT(result == N);
  32. ((void)result); // Prevent unused warning
  33. }
  34. int main(int, char**)
  35. {
  36. test<0>();
  37. test<10>();
  38. test<100>();
  39. test<1000>();
  40. return 0;
  41. }