[flang][OpenMP] Use range-for to iterate over SymbolSourceMap, NFC
[llvm-project.git] / libcxx / test / std / utilities / template.bitset / bitset.operators / stream_in.pass.cpp
blobe04b38f58932c8fb32809a65a77e2be36f9e9af5
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: no-localization
11 // test:
13 // template <class charT, class traits, size_t N>
14 // basic_istream<charT, traits>&
15 // operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
17 #include <bitset>
18 #include <sstream>
19 #include <cassert>
20 #include "test_macros.h"
22 int main(int, char**)
25 std::istringstream in("01011010");
26 std::bitset<8> b;
27 in >> b;
28 assert(b.to_ulong() == 0x5A);
31 // Make sure that input-streaming an empty bitset does not cause the
32 // failbit to be set (LWG 3199).
33 std::istringstream in("01011010");
34 std::bitset<0> b;
35 in >> b;
36 assert(b.to_string() == "");
37 assert(!in.bad());
38 assert(!in.fail());
39 assert(!in.eof());
40 assert(in.good());
42 #ifndef TEST_HAS_NO_EXCEPTIONS
44 std::stringbuf sb;
45 std::istream is(&sb);
46 is.exceptions(std::ios::failbit);
48 bool threw = false;
49 try {
50 std::bitset<8> b;
51 is >> b;
52 } catch (std::ios::failure const&) {
53 threw = true;
56 assert(!is.bad());
57 assert(is.fail());
58 assert(is.eof());
59 assert(threw);
62 std::stringbuf sb;
63 std::istream is(&sb);
64 is.exceptions(std::ios::eofbit);
66 bool threw = false;
67 try {
68 std::bitset<8> b;
69 is >> b;
70 } catch (std::ios::failure const&) {
71 threw = true;
74 assert(!is.bad());
75 assert(is.fail());
76 assert(is.eof());
77 assert(threw);
79 #endif // TEST_HAS_NO_EXCEPTIONS
81 return 0;