[OpenACC] Create AST nodes for 'data' constructs
[llvm-project.git] / libcxx / test / std / utilities / template.bitset / bitset.cons / char_ptr_ctor.pass.cpp
blob86b144ed87b70250b76e4916827e950341a505d3
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 //===----------------------------------------------------------------------===//
9 // template <class charT>
10 // explicit bitset(const charT* str,
11 // typename basic_string_view<charT>::size_type n = basic_string_view<charT>::npos, // s/string/string_view since C++26
12 // charT zero = charT('0'), charT one = charT('1')); // constexpr since C++23
14 #include <bitset>
15 #include <algorithm> // for 'min' and 'max'
16 #include <cassert>
17 #include <stdexcept> // for 'invalid_argument'
18 #include <type_traits>
20 #include "test_macros.h"
22 TEST_MSVC_DIAGNOSTIC_IGNORED(6294) // Ill-defined for-loop: initial condition does not satisfy test. Loop body not executed.
24 template <std::size_t N>
25 TEST_CONSTEXPR_CXX23 void test_char_pointer_ctor()
27 #ifndef TEST_HAS_NO_EXCEPTIONS
28 if (!TEST_IS_CONSTANT_EVALUATED) {
29 try {
30 std::bitset<N> v("xxx1010101010xxxx");
31 assert(false);
33 catch (std::invalid_argument&) {}
35 #endif
37 static_assert(!std::is_convertible<const char*, std::bitset<N> >::value, "");
38 static_assert(std::is_constructible<std::bitset<N>, const char*>::value, "");
40 const char s[] = "1010101010";
41 std::bitset<N> v(s);
42 std::size_t M = std::min<std::size_t>(v.size(), 10);
43 for (std::size_t i = 0; i < M; ++i)
44 assert(v[i] == (s[M - 1 - i] == '1'));
45 for (std::size_t i = 10; i < v.size(); ++i)
46 assert(v[i] == false);
49 const char s[] = "1010101010";
50 std::bitset<N> v(s, 10);
51 std::size_t M = std::min<std::size_t>(v.size(), 10);
52 for (std::size_t i = 0; i < M; ++i)
53 assert(v[i] == (s[M - 1 - i] == '1'));
54 for (std::size_t i = 10; i < v.size(); ++i)
55 assert(v[i] == false);
58 const char s[] = "1a1a1a1a1a";
59 std::bitset<N> v(s, 10, 'a');
60 std::size_t M = std::min<std::size_t>(v.size(), 10);
61 for (std::size_t i = 0; i < M; ++i)
62 assert(v[i] == (s[M - 1 - i] == '1'));
63 for (std::size_t i = 10; i < v.size(); ++i)
64 assert(v[i] == false);
67 const char s[] = "bababababa";
68 std::bitset<N> v(s, 10, 'a', 'b');
69 std::size_t M = std::min<std::size_t>(v.size(), 10);
70 for (std::size_t i = 0; i < M; ++i)
71 assert(v[i] == (s[M - 1 - i] == 'b'));
72 for (std::size_t i = 10; i < v.size(); ++i)
73 assert(v[i] == false);
77 TEST_CONSTEXPR_CXX23 bool test() {
78 test_char_pointer_ctor<0>();
79 test_char_pointer_ctor<1>();
80 test_char_pointer_ctor<31>();
81 test_char_pointer_ctor<32>();
82 test_char_pointer_ctor<33>();
83 test_char_pointer_ctor<63>();
84 test_char_pointer_ctor<64>();
85 test_char_pointer_ctor<65>();
86 test_char_pointer_ctor<1000>();
88 return true;
91 int main(int, char**)
93 test();
94 #if TEST_STD_VER > 20
95 static_assert(test());
96 #endif
98 return 0;