Debian Codegraph @

libcxx/test/std/utilities/template.bitset/bitset.members/index_const.pass.cpp

raw
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
9 // constexpr bool operator[](size_t pos) const; // constexpr since C++23
10
11 #include <bitset>
12 #include <cassert>
13 #include <cstddef>
14 #include <vector>
15
16 #include "../bitset_test_cases.h"
17 #include "test_macros.h"
18
19 template <std::size_t N>
20 TEST_CONSTEXPR_CXX23 void test_index_const() {
21 std::vector<std::bitset<N> > const cases = get_test_cases<N>();
22 for (std::size_t c = 0; c != cases.size(); ++c) {
23 std::bitset<N> const v = cases[c];
24 if (v.size() > 0) {
25 assert(v[N/2] == v.test(N/2));
26 }
27 }
28 #if !defined(_LIBCPP_VERSION) || defined(_LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL)
29 ASSERT_SAME_TYPE(decltype(cases[0][0]), bool);
30 #else
31 ASSERT_SAME_TYPE(decltype(cases[0][0]), typename std::bitset<N>::const_reference);
32 #endif
33 }
34
35 TEST_CONSTEXPR_CXX23 bool test() {
36 test_index_const<0>();
37 test_index_const<1>();
38 test_index_const<31>();
39 test_index_const<32>();
40 test_index_const<33>();
41 test_index_const<63>();
42 test_index_const<64>();
43 test_index_const<65>();
44
45 std::bitset<1> set_;
46 set_[0] = false;
47 const auto& set = set_;
48 auto b = set[0];
49 set_[0] = true;
50 #if !defined(_LIBCPP_VERSION) || defined(_LIBCPP_ABI_BITSET_VECTOR_BOOL_CONST_SUBSCRIPT_RETURN_BOOL)
51 assert(!b);
52 #else
53 assert(b);
54 #endif
55
56 return true;
57 }
58
59 int main(int, char**) {
60 test();
61 test_index_const<1000>(); // not in constexpr because of constexpr evaluation step limits
62 #if TEST_STD_VER > 20
63 static_assert(test());
64 #endif
65
66 return 0;
67 }