**Module:** Essential Tools Module **Group:** Traditional Collection

Does not inherit

- Local Index
- Synopsis
- Description
- Persistence
- Example
- Public Constructors
- Assignment Operators
- Bitwise Operators
- Logical Operators
- Public Member Functions

#include <rw/tbitvec.h> RWTBitVec<22> // A 22 bit long vector

** RWTBitVec<Size>** is a parameterized bit vector of fixed length

Bits are numbered from 0 through `size-1`, inclusive.

The copy constructor and assignment operator use *copy* semantics.

None

In this example, a bit vector 24 bits long is exercised:

#include <rw/tbitvec.h> int main() { RWTBitVec<24> a, b; // Allocate two vectors. a(2) = TRUE; // Set bit 2 (the third bit) of a on. b(3) = TRUE; // Set bit 3 (the fourth bit) of b on. RWTBitVec<24> c = a ^ b; // Set c to the XOR of a and b. }

RWTBitVec<Size>();

Constructs an instance with all bits set to `FALSE`.

RWTBitVec<Size>(RWBoolean val);

Constructs an instance with all bits set to `val`.

RWTBitVec<Size>&operator=(const RWTBitVec<Size>& v);

Sets self to a copy of `v`.

RWTBitVec&operator=(RWBoolean val);

Sets all bits in self to the value `val`.

RWTBitVec&operator&=(const RWTBitVec& v); RWTBitVec&operator^=(const RWTBitVec& v); RWTBitVec&operator|=(const RWTBitVec& v);

Logical assignments. Sets each bit of self to the logical `AND`, `XOR`, or `OR`, respectively, of self and the corresponding bit in `v`.

RWBitRefoperator[](size_t i);

Returns a reference to the `i`th bit of self. This reference can be used as an lvalue. The index `i` must be between `0` and `size-1`, inclusive. Bounds checking will occur.

RWBitRefoperator()(size_t i);

Returns a reference to the `i`^{th} bit of self. This reference can be used as an lvalue. The index `i` must be between `0` and `size-1`, inclusive. No bounds checking is done.

RWTBitVec<N>operator&(const RWTBitVec<N>& v2) const; RWTBitVec<N>operator^(const RWTBitVec<N>& v2) const; RWTBitVec<N>operator|(const RWTBitVec<N>& v2) const;

Return the logical `AND`, `XOR`, and `OR`, respectively, of self and `v2`.

RWBooleanoperator==(RWBoolean b) const;

Returns `TRUE` if every bit of self is set to the value `b`. Otherwise, returns `FALSE`.

RWBooleanoperator!=(RWBoolean b) const;

Returns `TRUE` if any bit of self is not set to the value `b`. Otherwise, returns `FALSE`.

RWBooleanoperator==(const RWTBitVec& v) const;

Returns `TRUE` if each bit of self is set to the same value as the corresponding bit in `v`. Otherwise, returns `FALSE`.

RWBooleanoperator!=(const RWTBitVec& v) const;

Returns `TRUE` if any bit of self is not set to the same value as the corresponding bit in `v`. Otherwise, returns `FALSE`.

voidclearBit(size_t i);

Clears (i.e., sets to `FALSE`) the bit with index `i`. The index `i` must be between `0` and `size-1`. No bounds checking is performed. The following two lines are equivalent, although `clearBit(size_t)` is slightly smaller and faster than using `operator()(size_t)`:

a(i) = FALSE; a.clearBit(i);

const RWByte*data() const;

Returns a `const` pointer to the raw data of self. Should be used with care.

size_tfirstFalse() const;

Returns the index of the first `OFF` (False) bit in self. Returns `RW_NPOS` if there is no `OFF` bit.

size_tfirstTrue() const;

Returns the index of the first `ON` (True) bit in self. Returns `RW_NPOS` if there is no `ON` bit.

voidsetBit(size_t i);

Sets (i.e., sets to `TRUE`) the bit with index `i`. The index `i` must be between `0` and `size-1`. No bounds checking is performed. The following two lines are equivalent, although `setBit(size_t)` is slightly smaller and faster than using `operator()(size_t)`.

a(i) = TRUE; a.setBit(i);

RWBooleantestBit(size_t i) const;

Tests the bit with index `i`. The index `i` must be between `0` and `size-1`. No bounds checking is performed. The following are equivalent, although `testBit(size_t)` is slightly smaller and faster than using `operator()(size_t)`:

if( a(i) ) doSomething(); if( a.testBit(i) ) doSomething();

©2004 Copyright Quovadx, Inc. All Rights Reserved.

Rogue Wave and SourcePro are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.

Contact Rogue Wave about documentation or support issues.