BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsl::bitset< N > Class Template Reference

#include <bslstl_bitset.h>

Inheritance diagram for bsl::bitset< N >:
bsl::Bitset_ImpBase< N ?(N - 1)/(CHAR_BIT *sizeof(int))+1 :1 >

Classes

class  reference
 

Public Member Functions

BSLS_KEYWORD_CONSTEXPR bitset () BSLS_KEYWORD_NOEXCEPT
 Create a bitset with all bits initialized to 0.
 
BSLS_KEYWORD_CONSTEXPR bitset (unsigned long long val) BSLS_KEYWORD_NOEXCEPT
 
template<class CHAR_TYPE , class TRAITS , class ALLOCATOR >
 bitset (const std::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR > &str, typename std::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR >::size_type pos=0, typename std::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR >::size_type n=std::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR >::npos, CHAR_TYPE zeroChar=CHAR_TYPE('0'), CHAR_TYPE oneChar=CHAR_TYPE('1'))
 
template<class CHAR_TYPE , class TRAITS , class ALLOCATOR >
 bitset (const bsl::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR > &str, typename bsl::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR >::size_type pos=0, typename bsl::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR >::size_type n=bsl::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR >::npos, CHAR_TYPE zeroChar=CHAR_TYPE('0'), CHAR_TYPE oneChar=CHAR_TYPE('1'))
 
bitsetoperator&= (const bitset &rhs) BSLS_KEYWORD_NOEXCEPT
 
bitsetoperator|= (const bitset &rhs) BSLS_KEYWORD_NOEXCEPT
 
bitsetoperator^= (const bitset &rhs) BSLS_KEYWORD_NOEXCEPT
 
bitsetoperator<<= (std::size_t pos) BSLS_KEYWORD_NOEXCEPT
 
bitsetoperator>>= (std::size_t pos) BSLS_KEYWORD_NOEXCEPT
 
bitsetflip () BSLS_KEYWORD_NOEXCEPT
 
bitsetflip (std::size_t pos)
 
bitsetreset () BSLS_KEYWORD_NOEXCEPT
 
bitsetreset (std::size_t pos)
 
bitsetset () BSLS_KEYWORD_NOEXCEPT
 
bitsetset (std::size_t pos, int val=true)
 
reference operator[] (std::size_t pos)
 
bitset operator<< (std::size_t pos) const BSLS_KEYWORD_NOEXCEPT
 
bitset operator>> (std::size_t pos) const BSLS_KEYWORD_NOEXCEPT
 
bitset operator~ () const BSLS_KEYWORD_NOEXCEPT
 
BSLS_KEYWORD_CONSTEXPR bool operator[] (std::size_t pos) const
 Return the value of the bit position at the specified pos.
 
bool operator== (const bitset &rhs) const BSLS_KEYWORD_NOEXCEPT
 
bool operator!= (const bitset &rhs) const BSLS_KEYWORD_NOEXCEPT
 
bool all () const BSLS_KEYWORD_NOEXCEPT
 
bool any () const BSLS_KEYWORD_NOEXCEPT
 
bool none () const BSLS_KEYWORD_NOEXCEPT
 
std::size_t count () const BSLS_KEYWORD_NOEXCEPT
 Return the number of bits in this bitset that have the value of 1.
 
BSLS_KEYWORD_CONSTEXPR std::size_t size () const BSLS_KEYWORD_NOEXCEPT
 Return the number of bits this bitset holds.
 
bool test (size_t pos) const
 
template<class CHAR_TYPE , class TRAITS , class ALLOCATOR >
basic_string< CHAR_TYPE, TRAITS, ALLOCATOR > to_string (CHAR_TYPE zero=CHAR_TYPE('0'), CHAR_TYPE one=CHAR_TYPE('1')) const
 
unsigned long to_ulong () const
 

Friends

class reference
 

Detailed Description

template<std::size_t N>
class bsl::bitset< N >

This class template provides an STL-compliant bitset. For the requirements of a bitset class, consult the second revision of the ISO/IEC 14882 Programming Language c++ (2011).

In addition to the methods defined in the standard, this class also provides an extra constructor that takes a bsl::basic_string. This extra constructor provides the capability to construct a bitset from a bsl::basic_string, in addition to a std::basic_string.

Constructor & Destructor Documentation

◆ bitset() [1/4]

template<std::size_t N>
BSLS_KEYWORD_CONSTEXPR bsl::bitset< N >::bitset ( )
inline

◆ bitset() [2/4]

template<std::size_t N>
BSLS_KEYWORD_CONSTEXPR bsl::bitset< N >::bitset ( unsigned long long  val)

Create a bitset with its first M bit positions correspond to bit values in the specified val. M is the smaller of the parameterized N and 8 * sizeof(unsigned long long). If M < N, the remaining bit positions are initialized to 0.

◆ bitset() [3/4]

template<std::size_t N>
template<class CHAR_TYPE , class TRAITS , class ALLOCATOR >
bsl::bitset< N >::bitset ( const std::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR > &  str,
typename std::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR >::size_type  pos = 0,
typename std::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR >::size_type  n = std::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>::npos,
CHAR_TYPE  zeroChar = CHAR_TYPE('0'),
CHAR_TYPE  oneChar = CHAR_TYPE('1') 
)
inlineexplicit

Create a bitset with its first M bit positions corresponding to the characters in the specified pos of the specified str. M is the smaller of the parameterized N and str.length(). If M < N, the remaining bit positions are initialized to 0. Characters with the value zeroChar correspond to an unset bit and characters with the value oneChar correspond to a set bit. The behavior is undefined if any characters in str is neither the specified zeroChar nor the specified oneChar.

◆ bitset() [4/4]

template<std::size_t N>
template<class CHAR_TYPE , class TRAITS , class ALLOCATOR >
bsl::bitset< N >::bitset ( const bsl::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR > &  str,
typename bsl::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR >::size_type  pos = 0,
typename bsl::basic_string< CHAR_TYPE, TRAITS, ALLOCATOR >::size_type  n = bsl::basic_string<CHAR_TYPE, TRAITS, ALLOCATOR>::npos,
CHAR_TYPE  zeroChar = CHAR_TYPE('0'),
CHAR_TYPE  oneChar = CHAR_TYPE('1') 
)
inlineexplicit

Create a bitset with its first M bit positions corresponding to 0 the characters in the specified pos of the specified str. M is the smaller of the parameterized N and str.length(). If M < N, the remaining bit positions are initialized to 0. Characters with the value zeroChar correspond to an unset bit and characters with the value oneChar correspond to a set bit. The behavior is undefined if the characters in the specified str is not the specified zeroChar and not the specified oneChar

Member Function Documentation

◆ all()

template<std::size_t N>
bool bsl::bitset< N >::all ( ) const

Return true if all of the bits in this bitset have the value of 1 and false otherwise. Note that all() and none() are both true for bitsets of size 0.

◆ any()

template<std::size_t N>
bool bsl::bitset< N >::any ( ) const

Return true if one or more of the bits in this bitset has the value of 1 and false otherwise.

◆ count()

template<std::size_t N>
std::size_t bsl::bitset< N >::count ( ) const

◆ flip() [1/2]

template<std::size_t N>
bitset< N > & bsl::bitset< N >::flip ( )

Toggle all bits of this bitset and return a reference to this modifiable bitset.

◆ flip() [2/2]

template<std::size_t N>
bitset< N > & bsl::bitset< N >::flip ( std::size_t  pos)
inline

Toggle the bit at the specified pos of this bitset and return a reference to this modifiable bitset.

◆ none()

template<std::size_t N>
bool bsl::bitset< N >::none ( ) const
inline

Return true if all the bits in this bitset has the value of 0 and false otherwise. Note that all() and none() are both true for bitsets of size 0.

◆ operator!=()

template<std::size_t N>
bool bsl::bitset< N >::operator!= ( const bitset< N > &  rhs) const
inline

Return true if the specified rhs do not have the same value as this bitset and false otherwise. Two bitset do not have the same value when either the sequence or the value of bits they hold are not the same.

◆ operator&=()

template<std::size_t N>
bitset< N > & bsl::bitset< N >::operator&= ( const bitset< N > &  rhs)

Clear each bit of this bitset for each corresponding bit that is 0 in the specified rhs, and leaves all other bits unchanged. Return a reference to this modifiable bitset. Note that this is equivalent to a bitwise OR.

◆ operator<<()

template<std::size_t N>
bitset< N > bsl::bitset< N >::operator<< ( std::size_t  pos) const
inline

Return a bitset constructed from shifting this bitset left by the specified pos.

◆ operator<<=()

template<std::size_t N>
bitset< N > & bsl::bitset< N >::operator<<= ( std::size_t  pos)

Shift the bits of this bitset left (towards the most significant bit) by the specified pos and return a reference to this modifiable bitset. For all bits with position I where I <= pos, the new value is 0. The behavior is undefined unless pos <= N.

◆ operator==()

template<std::size_t N>
bool bsl::bitset< N >::operator== ( const bitset< N > &  rhs) const
inline

Return true if the specified rhs has the same value as this bitset and false otherwise. Two bitsets have the same value when the sequence and value of bits they hold are the same.

◆ operator>>()

template<std::size_t N>
bitset< N > bsl::bitset< N >::operator>> ( std::size_t  pos) const
inline

Return a bitset constructed from shifting this bitset right by the specified pos.

◆ operator>>=()

template<std::size_t N>
bitset< N > & bsl::bitset< N >::operator>>= ( std::size_t  pos)

Shift the bits of this bitset right (towards the least significant bit) by the specified pos and return a reference to this modifiable bitset. For all bits with position I where I > N - pos, the new value is 0. The behavior is undefined unless pos <= N.

◆ operator[]() [1/2]

template<std::size_t N>
bitset< N >::reference bsl::bitset< N >::operator[] ( std::size_t  pos)
inline

Return a reference to the modifiable bit position at the specified pos.

◆ operator[]() [2/2]

template<std::size_t N>
BSLS_KEYWORD_CONSTEXPR bool bsl::bitset< N >::operator[] ( std::size_t  pos) const
inline

◆ operator^=()

template<std::size_t N>
bitset< N > & bsl::bitset< N >::operator^= ( const bitset< N > &  rhs)

Toggle each bit of this bitset for each corresponding bit that is 1 in the specified rhs, and leaves all other bits unchanged. Return a reference to this modifiable bitset. Note that this is equivalent to a bitwise XOR.

◆ operator|=()

template<std::size_t N>
bitset< N > & bsl::bitset< N >::operator|= ( const bitset< N > &  rhs)

Set each bit of this bitset for each corresponding bit that is 1 in the specified rhs, and leaves all other bits unchanged. Return a reference to this modifiable bitset. Note that this is equivalent to a bitwise AND.

◆ operator~()

template<std::size_t N>
bitset< N > bsl::bitset< N >::operator~ ( ) const
inline

Toggle all bits of this bitset and return a reference to this modifiable bitset.

◆ reset() [1/2]

template<std::size_t N>
bitset< N > & bsl::bitset< N >::reset ( )
inline

Set all bits of this bitset to 0 and return a reference to this modifiable bitset.

◆ reset() [2/2]

template<std::size_t N>
bitset< N > & bsl::bitset< N >::reset ( std::size_t  pos)
inline

Set the bit at the specified pos of this bitset to 0 and return a reference to this modifiable bitset.

◆ set() [1/2]

template<std::size_t N>
bitset< N > & bsl::bitset< N >::set ( )
inline

Set all bits of this bitset to 1 and return a reference to this modifiable bitset.

◆ set() [2/2]

template<std::size_t N>
bitset< N > & bsl::bitset< N >::set ( std::size_t  pos,
int  val = true 
)

Set the bit at the specified pos of this bitset to 1 and return a reference to this modifiable bitset. Optionally specify val as the value to set the bit. If val is non-zero, the bit is set to 1, otherwise the bit is set to 0.

◆ size()

template<std::size_t N>
BSLS_KEYWORD_CONSTEXPR std::size_t bsl::bitset< N >::size ( ) const
inline

◆ test()

template<std::size_t N>
bool bsl::bitset< N >::test ( size_t  pos) const
inline

Return true if the bit at the specified pos has the value of 1 and false otherwise.

◆ to_string()

template<std::size_t N>
template<class CHAR_TYPE , class TRAITS , class ALLOCATOR >
basic_string< CHAR_TYPE, TRAITS, ALLOCATOR > bsl::bitset< N >::to_string ( CHAR_TYPE  zero = CHAR_TYPE('0'),
CHAR_TYPE  one = CHAR_TYPE('1') 
) const

◆ to_ulong()

template<std::size_t N>
unsigned long bsl::bitset< N >::to_ulong ( ) const

Return an unsigned long value that has the same bit value as the bitset. Note that the behavior is undefined if the bitset cannot be represented as an unsigned long.

Friends And Related Symbol Documentation

◆ reference

template<std::size_t N>
friend class reference
friend

The documentation for this class was generated from the following file: