]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/template.bitset/bitset.members/set_one.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / utilities / template.bitset / bitset.members / set_one.pass.cpp
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>& set(size_t pos, bool val = true);
11
12 #include <bitset>
13 #include <cassert>
14
15 #include "test_macros.h"
16
17 template <std::size_t N>
18 void test_set_one(bool test_throws)
19 {
20     std::bitset<N> v;
21 #ifdef TEST_HAS_NO_EXCEPTIONS
22     if (test_throws) return;
23 #else
24     try
25 #endif
26     {
27         v.set(50);
28         if (50 >= v.size())
29             assert(false);
30         assert(v[50]);
31         assert(!test_throws);
32     }
33 #ifndef TEST_HAS_NO_EXCEPTIONS
34     catch (std::out_of_range&)
35     {
36         assert(test_throws);
37     }
38     try
39 #endif
40     {
41         v.set(50, false);
42         if (50 >= v.size())
43             assert(false);
44         assert(!v[50]);
45         assert(!test_throws);
46     }
47 #ifndef TEST_HAS_NO_EXCEPTIONS
48     catch (std::out_of_range&)
49     {
50         assert(test_throws);
51     }
52 #endif
53 }
54
55 int main()
56 {
57     test_set_one<0>(true);
58     test_set_one<1>(true);
59     test_set_one<31>(true);
60     test_set_one<32>(true);
61     test_set_one<33>(true);
62     test_set_one<63>(false);
63     test_set_one<64>(false);
64     test_set_one<65>(false);
65     test_set_one<1000>(false);
66 }