op_not.pass.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. // test bitset<N> operator^(const bitset<N>& lhs, const bitset<N>& rhs);
  9. #include <bitset>
  10. #include <cstdlib>
  11. #include <cassert>
  12. #include "test_macros.h"
  13. #if defined(TEST_COMPILER_CLANG)
  14. #pragma clang diagnostic ignored "-Wtautological-compare"
  15. #elif defined(TEST_COMPILER_C1XX)
  16. #pragma warning(disable: 6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
  17. #endif
  18. template <std::size_t N>
  19. std::bitset<N>
  20. make_bitset()
  21. {
  22. std::bitset<N> v;
  23. for (std::size_t i = 0; i < N; ++i)
  24. v[i] = static_cast<bool>(std::rand() & 1);
  25. return v;
  26. }
  27. template <std::size_t N>
  28. void test_op_not()
  29. {
  30. std::bitset<N> v1 = make_bitset<N>();
  31. std::bitset<N> v2 = make_bitset<N>();
  32. std::bitset<N> v3 = v1;
  33. assert((v1 ^ v2) == (v3 ^= v2));
  34. }
  35. int main(int, char**)
  36. {
  37. test_op_not<0>();
  38. test_op_not<1>();
  39. test_op_not<31>();
  40. test_op_not<32>();
  41. test_op_not<33>();
  42. test_op_not<63>();
  43. test_op_not<64>();
  44. test_op_not<65>();
  45. test_op_not<1000>();
  46. return 0;
  47. }