index.pass.cpp revision 97ecd6491374d756bd9c6da9ef84ab173f5049d6
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// test bitset<N>::reference operator[](size_t pos); 11 12#include <bitset> 13#include <cstdlib> 14#include <cassert> 15 16#pragma clang diagnostic ignored "-Wtautological-compare" 17 18template <std::size_t N> 19std::bitset<N> 20make_bitset() 21{ 22 std::bitset<N> v; 23 for (std::size_t i = 0; i < N; ++i) 24 v[i] = static_cast<bool>(std::rand() & 1); 25 return v; 26} 27 28template <std::size_t N> 29void test_index_const() 30{ 31 std::bitset<N> v1 = make_bitset<N>(); 32 if (N > 0) 33 { 34 assert(v1[N/2] == v1.test(N/2)); 35 typename std::bitset<N>::reference r = v1[N/2]; 36 assert(r == v1.test(N/2)); 37 typename std::bitset<N>::reference r2 = v1[N/2]; 38 r = r2; 39 assert(r == v1.test(N/2)); 40 r = false; 41 assert(r == false); 42 assert(v1.test(N/2) == false); 43 r = true; 44 assert(r == true); 45 assert(v1.test(N/2) == true); 46 bool b = ~r; 47 assert(r == true); 48 assert(v1.test(N/2) == true); 49 assert(b == false); 50 r.flip(); 51 assert(r == false); 52 assert(v1.test(N/2) == false); 53 } 54} 55 56int main() 57{ 58 test_index_const<0>(); 59 test_index_const<1>(); 60 test_index_const<31>(); 61 test_index_const<32>(); 62 test_index_const<33>(); 63 test_index_const<63>(); 64 test_index_const<64>(); 65 test_index_const<65>(); 66 test_index_const<1000>(); 67} 68