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 //===----------------------------------------------------------------------===// 8 9 // test: 10 11 // template <class charT, class traits, size_t N> 12 // basic_istream<charT, traits>& 13 // operator>>(basic_istream<charT, traits>& is, bitset<N>& x); 14 15 #include <bitset> 16 #include <sstream> 17 #include <cassert> 18 #include "test_macros.h" 19 20 int main(int, char**) 21 { 22 { 23 std::istringstream in("01011010"); 24 std::bitset<8> b; 25 in >> b; 26 assert(b.to_ulong() == 0x5A); 27 } 28 #ifndef TEST_HAS_NO_EXCEPTIONS 29 { 30 std::stringbuf sb; 31 std::istream is(&sb); 32 is.exceptions(std::ios::failbit); 33 34 bool threw = false; 35 try { 36 std::bitset<8> b; 37 is >> b; 38 } catch (std::ios::failure const&) { 39 threw = true; 40 } 41 42 assert(!is.bad()); 43 assert(is.fail()); 44 assert(is.eof()); 45 assert(threw); 46 } 47 { 48 std::stringbuf sb; 49 std::istream is(&sb); 50 is.exceptions(std::ios::eofbit); 51 52 bool threw = false; 53 try { 54 std::bitset<8> b; 55 is >> b; 56 } catch (std::ios::failure const&) { 57 threw = true; 58 } 59 60 assert(!is.bad()); 61 assert(is.fail()); 62 assert(is.eof()); 63 assert(threw); 64 } 65 #endif // TEST_HAS_NO_EXCEPTIONS 66 67 return 0; 68 } 69