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 size_t count() const; 11 12#include <bitset> 13#include <cstdlib> 14#include <cassert> 15 16#if defined(__clang__) 17#pragma clang diagnostic ignored "-Wtautological-compare" 18#endif 19 20template <std::size_t N> 21std::bitset<N> 22make_bitset() 23{ 24 std::bitset<N> v; 25 for (std::size_t i = 0; i < N; ++i) 26 v[i] = static_cast<bool>(std::rand() & 1); 27 return v; 28} 29 30template <std::size_t N> 31void test_count() 32{ 33 const std::bitset<N> v = make_bitset<N>(); 34 std::size_t c1 = v.count(); 35 std::size_t c2 = 0; 36 for (std::size_t i = 0; i < N; ++i) 37 if (v[i]) 38 ++c2; 39 assert(c1 == c2); 40} 41 42int main() 43{ 44 test_count<0>(); 45 test_count<1>(); 46 test_count<31>(); 47 test_count<32>(); 48 test_count<33>(); 49 test_count<63>(); 50 test_count<64>(); 51 test_count<65>(); 52 test_count<1000>(); 53} 54