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