ull_ctor.pass.cpp 1.5 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(unsigned long long val);
  9. #include <bitset>
  10. #include <cassert>
  11. #include <algorithm> // for 'min' and 'max'
  12. #include <cstddef>
  13. #include "test_macros.h"
  14. #if defined(TEST_COMPILER_C1XX)
  15. #pragma warning(disable: 6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
  16. #endif
  17. template <std::size_t N>
  18. void test_val_ctor()
  19. {
  20. {
  21. TEST_CONSTEXPR std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL);
  22. assert(v.size() == N);
  23. std::size_t M = std::min<std::size_t>(N, 64);
  24. for (std::size_t i = 0; i < M; ++i)
  25. assert(v[i] == ((i & 1) != 0));
  26. for (std::size_t i = M; i < N; ++i)
  27. assert(v[i] == false);
  28. }
  29. #if TEST_STD_VER >= 11
  30. {
  31. constexpr std::bitset<N> v(0xAAAAAAAAAAAAAAAAULL);
  32. static_assert(v.size() == N, "");
  33. }
  34. #endif
  35. }
  36. int main(int, char**)
  37. {
  38. test_val_ctor<0>();
  39. test_val_ctor<1>();
  40. test_val_ctor<31>();
  41. test_val_ctor<32>();
  42. test_val_ctor<33>();
  43. test_val_ctor<63>();
  44. test_val_ctor<64>();
  45. test_val_ctor<65>();
  46. test_val_ctor<1000>();
  47. return 0;
  48. }