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