summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/utilities/template.bitset/bitset.members/reset_one.pass.cpp
blob: 1abb4914bfa301f8d6415e374de10fe64eb026a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// test bitset<N>& reset(size_t pos);

#include <bitset>
#include <cassert>
#include <stdexcept>

#include "test_macros.h"

template <std::size_t N>
void test_reset_one(bool test_throws)
{
    std::bitset<N> v;
#ifdef TEST_HAS_NO_EXCEPTIONS
    if (test_throws) return;
#else
    try
    {
#endif
        v.set();
        v.reset(50);
        if (50 >= v.size())
            assert(false);
        for (unsigned i = 0; i < v.size(); ++i)
            if (i == 50)
                assert(!v[i]);
            else
                assert(v[i]);
        assert(!test_throws);
#ifndef TEST_HAS_NO_EXCEPTIONS
    }
    catch (std::out_of_range&)
    {
        assert(test_throws);
    }
#endif
}

int main(int, char**)
{
    test_reset_one<0>(true);
    test_reset_one<1>(true);
    test_reset_one<31>(true);
    test_reset_one<32>(true);
    test_reset_one<33>(true);
    test_reset_one<63>(false);
    test_reset_one<64>(false);
    test_reset_one<65>(false);
    test_reset_one<1000>(false);

  return 0;
}
OpenPOWER on IntegriCloud