#include <bool_array.h>
Collaboration diagram for bool_array:

Public Member Functions | |
| bool_array () | |
| bool_array (unsigned long __size) | |
| Constructs the packed boolean array with a specific size. | |
| ~bool_array () | |
| bool | create (unsigned long __size) |
| Creates the packed boolean array with a specific size. | |
| void | initialize (bool __value) |
| Initializes all array elements to a specific value optimally. | |
| _Element | operator[] (unsigned long __idx) |
| Creates a reference to an array element. | |
| bool | at (unsigned long __idx) const |
| Reads the boolean value of an array element via an index. | |
| void | reset (unsigned long __idx) |
Resets an array element to false via an index. | |
| void | set (unsigned long __idx) |
Sets an array element to true via an index. | |
| unsigned long | size () const |
| unsigned long | count () const |
Counts elements with a true value. | |
| unsigned long | count (unsigned long __beg, unsigned long __end) const |
Counts elements with a true value in a specified range. | |
| void | flip () |
Changes all true elements to false, and false ones to true. | |
Classes | |
| class | _Element |
| Class to represent a reference to an array element. | |
This was first written in April 1995, before I knew of any existing implementation of this kind of classes. Of course, the C++ Standard Template Library now demands an implementation of packed boolean array as `vector<bool>', but the code here should still be useful for the following three reasons: (1) STL support of MSVC 6 did not implement this specialization (nor did it have a `bit_vector'); (2) I incorporated some useful member functions from the STL bitset into this `bool_array', including `reset', `set', `flip', and `count'; (3) In my tests under MSVC 6 and GCC 2.95.3/3.2.3 my code is really FASTER than vector<bool> or the normal boolean array.
| bool_array::bool_array | ( | ) | [inline] |
| bool_array::bool_array | ( | unsigned long | __size | ) | [inline, explicit] |
Constructs the packed boolean array with a specific size.
| __size | size of the array |
| std::out_of_range | if __size equals 0 | |
| std::bad_alloc | if memory is insufficient |
| bool_array::~bool_array | ( | ) | [inline] |
| bool bool_array::create | ( | unsigned long | __size | ) |
Creates the packed boolean array with a specific size.
| __size | size of the array |
false if __size equals 0 or is too big, or if memory is insufficient; true if __size has a suitable value and memory allocation is successful. | void bool_array::initialize | ( | bool | __value | ) |
Initializes all array elements to a specific value optimally.
| __value | the boolean value to assign to all elements |
| bool_array::_Element bool_array::operator[] | ( | unsigned long | __idx | ) | [inline] |
Creates a reference to an array element.
| __idx | index of the array element to access |
| bool bool_array::at | ( | unsigned long | __idx | ) | const [inline] |
Reads the boolean value of an array element via an index.
| __idx | index of the array element to access |
| std::out_of_range | when the index is too big |
| void bool_array::reset | ( | unsigned long | __idx | ) | [inline] |
Resets an array element to false via an index.
| __idx | index of the array element to access |
| std::out_of_range | when the index is too big |
| void bool_array::set | ( | unsigned long | __idx | ) | [inline] |
Sets an array element to true via an index.
| __idx | index of the array element to access |
| std::out_of_range | when the index is too big |
| unsigned long bool_array::size | ( | ) | const [inline] |
| unsigned long bool_array::count | ( | ) | const |
Counts elements with a true value.
true elements | unsigned long bool_array::count | ( | unsigned long | __beg, | |
| unsigned long | __end | |||
| ) | const |
Counts elements with a true value in a specified range.
| __beg | beginning of the range | |
| __end | end of the range (exclusive) |
true elements | void bool_array::flip | ( | ) |
Changes all true elements to false, and false ones to true.
1.5.1