op_and_eq.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>& operator&=(const bitset<N>& rhs);
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_op_and_eq()
30{
31    std::bitset<N> v1 = make_bitset<N>();
32    std::bitset<N> v2 = make_bitset<N>();
33    std::bitset<N> v3 = v1;
34    v1 &= v2;
35    for (std::size_t i = 0; i < N; ++i)
36        assert(v1[i] == (v3[i] && v2[i]));
37}
38
39int main()
40{
41    test_op_and_eq<0>();
42    test_op_and_eq<1>();
43    test_op_and_eq<31>();
44    test_op_and_eq<32>();
45    test_op_and_eq<33>();
46    test_op_and_eq<63>();
47    test_op_and_eq<64>();
48    test_op_and_eq<65>();
49    test_op_and_eq<1000>();
50}
51