Standard library header <bitset> - cppreference.com

From cppreference.com

This header is part of the

general utility

library.

Includes

<string>

std::basic_string

class template

[edit]

<iosfwd>

Forward declarations of all classes in the input/output library

[edit]

Classes

bitset

implements constant length bit array
(class template)

[edit]

std::hash<std::bitset>

(C++11)

hash support for

std::bitset

(class template specialization)

[edit]

Forward declarations Defined in header

<functional>

hash

(C++11)

hash function object
(class template)

[edit]

Functions

operator&operator|operator^

performs binary logic operations on bitsets
(function template)

[edit]

operator<<operator>>

performs stream input and output of bitsets
(function template)

[edit]

Synopsis

#include<string>#include<iosfwd> // for istream, ostreamnamespacestd{template<size_tN>classbitset;// bitset operatorstemplate<size_tN>constexprbitset<N>operator&(constbitset<N>&,constbitset<N>&)noexcept;template<size_tN>constexprbitset<N>operator|(constbitset<N>&,constbitset<N>&)noexcept;template<size_tN>constexprbitset<N>operator^(constbitset<N>&,constbitset<N>&)noexcept;template<classCharT,classTraits,size_tN>basic_istream<CharT,Traits>&operator>>(basic_istream<CharT,Traits>&is,bitset<N>&x);template<classCharT,classTraits,size_tN>basic_ostream<CharT,Traits>&operator<<(basic_ostream<CharT,Traits>&os,constbitset<N>&x);}Class template

std::bitset

namespacestd{template<size_tN>classbitset{public:// bit referenceclassreference{public:constexprreference(constreference&)=default;constexpr~reference();constexprreference&operator=(boolx)noexcept;// for b[i] = x;constexprreference&operator=(constreference&)noexcept;// for b[i] = b[j];constexprbooloperator~()constnoexcept;// flips the bitconstexproperatorbool()constnoexcept;// for x = b[i];constexprreference&flip()noexcept;// for b[i].flip();};// constructorsconstexprbitset()noexcept;constexprbitset(unsignedlonglongval)noexcept;template<classCharT,classTraits,classAllocator>constexprexplicitbitset(constbasic_string<CharT,Traits,Allocator>&str,typenamebasic_string<CharT,Traits,Allocator>::size_typepos=0,typenamebasic_string<CharT,Traits,Allocator>::size_typen=basic_string<CharT,Traits,Allocator>::npos,CharTzero=CharT('0'),CharTone=CharT('1'));template<classCharT,classTraits>constexprexplicitbitset(basic_string_view<CharT,Traits>str,typenamebasic_string_view<CharT,Traits>::size_typepos=0,typenamebasic_string_view<CharT,Traits>::size_typen=basic_string_view<CharT,Traits>::npos,CharTzero=CharT('0'),CharTone=CharT('1'));template<classCharT>constexprexplicitbitset(constCharT*str,typenamebasic_string_view<CharT>::size_typen=basic_string_view<CharT>::npos,CharTzero=CharT('0'),CharTone=CharT('1'));// bitset operationsconstexprbitset&operator&=(constbitset&rhs)noexcept;constexprbitset&operator|=(constbitset&rhs)noexcept;constexprbitset&operator^=(constbitset&rhs)noexcept;constexprbitset&operator<<=(size_tpos)noexcept;constexprbitset&operator>>=(size_tpos)noexcept;constexprbitsetoperator<<(size_tpos)constnoexcept;constexprbitsetoperator>>(size_tpos)constnoexcept;constexprbitset&set()noexcept;constexprbitset&set(size_tpos,boolval=true);constexprbitset&reset()noexcept;constexprbitset&reset(size_tpos);constexprbitsetoperator~()constnoexcept;constexprbitset&flip()noexcept;constexprbitset&flip(size_tpos);// element accessconstexprbooloperator[](size_tpos)const;constexprreferenceoperator[](size_tpos);constexprunsignedlongto_ulong()const;constexprunsignedlonglongto_ullong()const;template<classCharT=char,classTraits=char_traits<CharT>,classAllocator=allocator<CharT>>constexprbasic_string<CharT,Traits,Allocator>to_string(CharTzero=CharT('0'),CharTone=CharT('1'))const;// observersconstexprsize_tcount()constnoexcept;constexprsize_tsize()constnoexcept;constexprbooloperator==(constbitset&rhs)constnoexcept;constexprbooltest(size_tpos)const;constexprboolall()constnoexcept;constexprboolany()constnoexcept;constexprboolnone()constnoexcept;};// hash supporttemplate<classT>structhash;template<size_tN>structhash<bitset<N>>;}Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior

LWG 4140

C++98 the synopsis contains a declaration of the default
constructor of std::bitset<N>::referenceremoved the
declaration