vector_bool.pass.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // Not very portable
  16. #include <vector>
  17. #include <cassert>
  18. #include <type_traits>
  19. #include "test_macros.h"
  20. #include "min_allocator.h"
  21. int main(int, char**)
  22. {
  23. {
  24. typedef std::vector<bool> T;
  25. typedef std::hash<T> H;
  26. static_assert((std::is_same<H::argument_type, T>::value), "" );
  27. static_assert((std::is_same<H::result_type, std::size_t>::value), "" );
  28. ASSERT_NOEXCEPT(H()(T()));
  29. bool ba[] = {true, false, true, true, false};
  30. T vb(std::begin(ba), std::end(ba));
  31. H h;
  32. assert(h(vb) != 0);
  33. }
  34. #if TEST_STD_VER >= 11
  35. {
  36. typedef std::vector<bool, min_allocator<bool>> T;
  37. typedef std::hash<T> H;
  38. static_assert((std::is_same<H::argument_type, T>::value), "" );
  39. static_assert((std::is_same<H::result_type, std::size_t>::value), "" );
  40. ASSERT_NOEXCEPT(H()(T()));
  41. bool ba[] = {true, false, true, true, false};
  42. T vb(std::begin(ba), std::end(ba));
  43. H h;
  44. assert(h(vb) != 0);
  45. }
  46. #endif
  47. return 0;
  48. }