char_ptr_ctor.pass.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. // template <class charT>
  9. // explicit bitset(const charT* str,
  10. // typename basic_string<charT>::size_type n = basic_string<charT>::npos,
  11. // charT zero = charT('0'), charT one = charT('1'));
  12. #include <bitset>
  13. #include <cassert>
  14. #include <algorithm> // for 'min' and 'max'
  15. #include <stdexcept> // for 'invalid_argument'
  16. #include "test_macros.h"
  17. #if defined(TEST_COMPILER_C1XX)
  18. #pragma warning(disable: 6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
  19. #endif
  20. template <std::size_t N>
  21. void test_char_pointer_ctor()
  22. {
  23. {
  24. #ifndef TEST_HAS_NO_EXCEPTIONS
  25. try {
  26. std::bitset<N> v("xxx1010101010xxxx");
  27. assert(false);
  28. }
  29. catch (std::invalid_argument&) {}
  30. #endif
  31. }
  32. {
  33. const char str[] ="1010101010";
  34. std::bitset<N> v(str);
  35. std::size_t M = std::min<std::size_t>(N, 10);
  36. for (std::size_t i = 0; i < M; ++i)
  37. assert(v[i] == (str[M - 1 - i] == '1'));
  38. for (std::size_t i = 10; i < N; ++i)
  39. assert(v[i] == false);
  40. }
  41. }
  42. int main(int, char**)
  43. {
  44. test_char_pointer_ctor<0>();
  45. test_char_pointer_ctor<1>();
  46. test_char_pointer_ctor<31>();
  47. test_char_pointer_ctor<32>();
  48. test_char_pointer_ctor<33>();
  49. test_char_pointer_ctor<63>();
  50. test_char_pointer_ctor<64>();
  51. test_char_pointer_ctor<65>();
  52. test_char_pointer_ctor<1000>();
  53. return 0;
  54. }