xtd 0.2.0
xtd::collections::bit_array Class Reference
Inheritance diagram for xtd::collections::bit_array:
xtd::object xtd::iequatable< bit_array > xtd::collections::generic::icollection< bool > xtd::iclonable xtd::interface xtd::extensions::equality_operators< type_t, equatable_t > xtd::collections::generic::ienumerable< type_t > xtd::collections::generic::extensions::collection_operators< type_t, collection_t > xtd::interface xtd::interface xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > > xtd::collections::generic::extensions::enumerable< ienumerable< type_t >, type_t >

Definition

Manages a compact array of bit values, which are represented as booleans, where true indicates that the bit is on (1) and false indicates the bit is off (0).

Manages a compact array of bit values, which are represented as booleans, where true indicates that t...
Definition bit_array.hpp:40
Defines methods to manipulate generic collections.
Definition icollection.hpp:45
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
Definition iclonable.hpp:21
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
Supports all classes in the xtd class hierarchy and provides low-level services to derived classes....
Definition object.hpp:43
#define core_export_
Define shared library export.
Definition core_export.hpp:13
Header
#include <xtd/collections/bit_array>
Namespace
xtd::collections
Library
xtd.core
Examples
The following code example shows how to create and initialize a xtd::collections::bit_array and how to print out its values.
#include <xtd/collections/bit_array>
#include <xtd/console>
#include <xtd/startup>
using namespace xtd;
using namespace xtd::collections;
using namespace xtd::collections::generic;
class program {
public:
static auto main() -> void {
// Creates and initializes several bit_arrays.
auto my_ba1 = bit_array(5_z);
auto my_ba2 = bit_array(5_z, false);
auto my_bytes = array {1_u8, 2_u8, 3_u8, 4_u8, 5_u8};
auto my_ba3 = bit_array(my_bytes);
auto my_bools = array {true, false, true, true, false};
auto my_ba4 = bit_array(my_bools);
auto my_ints = array {6, 7, 8, 9, 10};
auto my_ba5 = bit_array(my_ints);
// Displays the properties and values of the bit_arrays.
console::write_line("my_ba1");
console::write_line(" count: {0}", my_ba1.count());
console::write_line(" length: {0}", my_ba1.length());
console::write_line(" values:");
print_values(my_ba1, 8);
console::write_line("my_ba2");
console::write_line(" count: {0}", my_ba2.count());
console::write_line(" length: {0}", my_ba2.length());
console::write_line(" values:");
print_values(my_ba2, 8);
console::write_line("my_ba3");
console::write_line(" count: {0}", my_ba3.count());
console::write_line(" length: {0}", my_ba3.length());
console::write_line(" values:");
print_values(my_ba3, 8);
console::write_line("my_ba4");
console::write_line(" count: {0}", my_ba4.count());
console::write_line(" length: {0}", my_ba4.length());
console::write_line(" values:");
print_values(my_ba4, 8);
console::write_line("my_ba5");
console::write_line(" count: {0}", my_ba5.count());
console::write_line(" length: {0}", my_ba5.length());
console::write_line(" values:");
print_values(my_ba5, 8);
}
template<class object_t>
static void print_values(const ienumerable<object_t>& my_list, int my_width ) {
auto i = my_width;
for (auto obj : my_list) {
if (i <= 0) {
i = my_width;
console::write_line();
}
i--;
console::write("{,8}", obj);
}
console::write_line();
}
};
startup_(program::main);
// This code produces the following output :
//
// my_ba1
// count: 5
// length: 5
// values:
// false false false false false
// my_ba2
// count: 5
// length: 5
// values:
// false false false false false
// my_ba3
// count: 40
// length: 40
// values:
// true false false false false false false false
// false true false false false false false false
// true true false false false false false false
// false false true false false false false false
// true false true false false false false false
// my_ba4
// count: 5
// length: 5
// values:
// true false true true false
// my_ba5
// count: 160
// length: 160
// values:
// false true true false false false false false
// false false false false false false false false
// false false false false false false false false
// false false false false false false false false
// true true true false false false false false
// false false false false false false false false
// false false false false false false false false
// false false false false false false false false
// false false false true false false false false
// false false false false false false false false
// false false false false false false false false
// false false false false false false false false
// true false false true false false false false
// false false false false false false false false
// false false false false false false false false
// false false false false false false false false
// false true false true false false false false
// false false false false false false false false
// false false false false false false false false
// false false false false false false false false
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:61
Exposes the enumerator, which supports a simple iteration over a collection of a specified type.
Definition ienumerable.hpp:36
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:167
@ i
The I key.
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10

Public Aliases

using value_type = bool
 Represents the list value type.
 
using allocator_type = typename xtd::collections::generic::list< int32 >::allocator_type
 Represents the list allocator type.
 
using base_type = typename xtd::collections::generic::list< int32 >
 Represents the list base type.
 
using size_type = xtd::size
 Represents the list size type (usually xtd::size).
 
using difference_type = xtd::ptrdiff
 Represents the list difference type (usually xtd::ptrdiff).
 
using reference = value_type &
 Represents the reference of list value type.
 
using const_reference = const value_type &
 Represents the const reference of list value type.
 
using pointer = value_type *
 Represents the pointer of list value type.
 
using const_pointer = const value_type *
 Represents the const pointer of list value type.
 
using iterator = typename xtd::collections::generic::ienumerable< bool >::iterator
 Represents the iterator of list value type.
 
using const_iterator = typename xtd::collections::generic::ienumerable< bool >::const_iterator
 Represents the const iterator of list value type.
 

Public Constructors

 bit_array (xtd::size length) noexcept
 Initializes a new instance of the xtd::collections::bit_array class that can hold the specified number of bit values, which are initially set to false.
 
 bit_array (xtd::size length, bool defaultValue) noexcept
 Initializes a new instance of the xtd::collections::bit_array class that can hold the specified number of bit values, which are initially set to the specified value.
 
 bit_array (std::initializer_list< bool > il) noexcept
 Initializes a new instance of the xtd::collections::bit_array class that contains bit values copied from the specified initializer list of booleans.
 
 bit_array (const xtd::array< bool > &values) noexcept
 Initializes a new instance of the xtd::collections::bit_array class that contains bit values copied from the specified array of booleans.
 
 bit_array (const xtd::array< xtd::byte > &values) noexcept
 Initializes a new instance of the xtd::collections::bit_array class that contains bit values copied from the specified array of bytes.
 
 bit_array (const xtd::array< int32 > &values) noexcept
 Initializes a new instance of the xtd::collections::bit_array class that contains bit values copied from the specified array of 32-bit integers.
 
template<xtd::size length>
 bit_array (const std::bitset< length > &bit_set) noexcept
 Initializes a new instance of the xtd::collections::bit_array class that contains bit values copied from the specified bitset.
 
 bit_array (const std::vector< bool > &booleans) noexcept
 Initializes a new instance of the xtd::collections::bit_array class that contains bit values copied from the specified std::vector<bool>.
 

Public Properties

const_iterator begin () const noexcept override
 Returns an iterator to the first element of the enumarable.
 
iterator begin () noexcept override
 Returns an iterator to the first element of the enumarable.
 
template<xtd::size length>
std::bitset< lengthbits () const noexcept
 Returns a std::bitset object containing the Booleans contained in the current xtd::collections::bit_array.
 
std::vector< bool > bits () const noexcept
 Returns a std::vector<bool> object containing the Booleans contained in the current xtd::collections::bit_array.
 
const_iterator cbegin () const noexcept override
 Returns an iterator to the first element of the enumarable.
 
const_iterator cend () const noexcept override
 Returns an iterator to the element following the last element of the enumarable.
 
xtd::size count () const noexcept override
 Gets the number of elements contained in the xtd::collections::bit_array.
 
virtual bool empty () const noexcept
 Checks if the container has no elements, i.e. whether xtd::collections::bit_array::begin() == xtd::collections::bit_array::end().
 
const_iterator end () const noexcept override
 Returns an iterator to the element following the last element of the enumarable.
 
iterator end () noexcept override
 Returns an iterator to the element following the last element of the enumarable.
 
xtd::size length () const noexcept
 Gets the number of elements contained in the xtd::collections::bit_array.
 
void length (xtd::size value)
 Sets the number of elements contained in the xtd::collections::bit_array.
 
bool is_read_only () const noexcept override
 Gets a value indicating whether the xtd::collections::bit_array is read-only.
 
bool is_synchronized () const noexcept override
 Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is synchronized (thread safe).
 
const objectsync_root () const noexcept override
 Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollection <type_t>.
 

Public Methods

const bit_arrayand_ (const bit_array &value)
 Performs the bitwise AND operation on the elements in the current xtd::collections::bit_array against the corresponding elements in the specified xtd::collections::bit_array.
 
bool at (xtd::size index) const
 Gets the value of the bit at a specific position in the xtd::collections::bit_array.
 
bool & at (xtd::size index)
 Gets the value of the bit at a specific position in the xtd::collections::bit_array.
 
xtd::uptr< xtd::objectclone () const override
 Creates a new object that is a copy of the current instance.
 
void copy_to (xtd::array< bool > &array, xtd::size index) const override
 Copies the elements of the xtd::collections::bit_array to an xtd::array, starting at a particular xtd::array index.
 
bool equals (const bit_array &value) const noexcept override
 Determines whether this instance of xtd::collections::bit_array and a specified object, which must also be a xtd::collections::bit_array object, have the same value.
 
bool equals (const object &obj) const noexcept override
 Determines whether this instance of xtd::collections::bit_array and a specified object, which must also be a xtd::collections::bit_array object, have the same value.
 
bool get (xtd::size index) const
 Gets the value of the bit at a specific position in the xtd::collections::bit_array.
 
bool & get (xtd::size index)
 Gets the value of the bit at a specific position in the xtd::collections::bit_array.
 
xtd::collections::generic::enumerator< bool > get_enumerator () const override
 Returns an enumerator that iterates through a collection.
 
bool has_all_set () const noexcept
 Determines whether all bits in the xtd::collections::bit_array are set to true.
 
bool has_any_set () const noexcept
 Determines whether any bit in the xtd::collections::bit_array is set to true.
 
bit_arrayleft_shift (xtd::size count) noexcept
 Shifts all the bit values of the current xtd::collections::bit_array to the left on count bits.
 
const bit_arraynot_ ()
 Inverts all the bit values in the current xtd::collections::bit_array, so that elements set to true are changed to false, and elements set to false are changed to true.
 
const bit_arrayor_ (const bit_array &value)
 Performs the bitwise OR operation on the elements in the current xtd::collections::bit_array against the corresponding elements in the specified xtd::collections::bit_array.
 
bit_arrayright_shift (xtd::size count) noexcept
 Shifts all the bit values of the current xtd::collections::bit_array to the right on count bits.
 
void set (xtd::size index, bool value)
 Sets the value of the bit at a specific position in the xtd::collections::bit_array.
 
void set_all (bool value)
 Sets all bits in the xtd::collections::bit_array to the specified value.
 
xtd::string to_string () const noexcept override
 Returns a xtd::string that represents the current object.
 
const bit_arrayxor_ (const bit_array &value)
 Performs the bitwise exclusive OR operation on the elements in the current xtd::collections::bit_array against the corresponding elements in the specified xtd::collections::bit_array.
 

Public Operators

const bool & operator[] (xtd::size index) const
 Gets the element at the specified index.
 
bool & operator[] (xtd::size index)
 Gets or Sets the element at the specified index.
 
bit_array operator>> (xtd::size count) const noexcept
 The right shift operator shifts all the bit values of the current xtd::collections::bit_array to the right on count bits.
 
bit_arrayoperator>>= (xtd::size count) noexcept
 The right shift operator shifts all the bit values of the current xtd::collections::bit_array to the right on count bits.
 
bit_array operator<< (xtd::size count) const noexcept
 The left shift operator shifts all the bit values of the current xtd::collections::bit_array to the left on count bits.
 
bit_arrayoperator<<= (xtd::size count) noexcept
 The left shift operator shifts all the bit values of the current xtd::collections::bit_array to the left on count bits.
 

Additional Inherited Members

- Public Types inherited from xtd::collections::generic::icollection< bool >
using value_type = typename xtd::collections::generic::ienumerable< bool >::value_type
 Represents the xtd::collections::generic::icollection value type.
 
using iterator = typename xtd::collections::generic::ienumerable< bool >::iterator
 Represents the iterator of xtd::collections::generic::ienumerable value type.
 
using const_iterator = typename xtd::collections::generic::ienumerable< bool >::const_iterator
 Represents the const iterator of xtd::collections::generic::ienumerable value type.
 
- Public Types inherited from xtd::collections::generic::ienumerable< type_t >
using value_type = type_t
 Represents the xtd::collections::generic::ienumerable value type.
 
using iterator = typename xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >::iterator
 Represents the iterator of xtd::collections::generic::ienumerable value type.
 
using const_iterator = typename xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >::const_iterator
 Represents the const iterator of xtd::collections::generic::ienumerable value type.
 
- Public Types inherited from xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >
using iterator = enumerable_iterator
 Represents the iterator of enumarable value type.
 
using const_iterator = const enumerable_iterator
 Represents the const iterator of enumarable value type.
 
- Public Types inherited from xtd::collections::generic::extensions::enumerable< ienumerable< type_t >, type_t >
using enumerable_type = ienumerable< type_t >
 Represents the ienumerable enumerable type.
 
using source_type = type_t
 Represents the ienumerable source type.
 
using ienumerable = typename xtd::linq::enumerable::ienumerable< type_t >
 Represents the ienumerable value type.
 
using list = typename xtd::linq::enumerable::list< type_t >
 Represents the list value type.
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual xtd::size get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
virtual type_object get_type () const noexcept
 Gets the type of the current instance.
 
template<class object_t >
xtd::uptr< object_t > memberwise_clone () const
 Creates a shallow copy of the current object.
 
- Public Member Functions inherited from xtd::iequatable< bit_array >
virtual bool equals (const bit_array &) const noexcept=0
 Indicates whether the current object is equal to another object of the same type.
 
- Public Member Functions inherited from xtd::collections::generic::icollection< bool >
- Public Member Functions inherited from xtd::collections::generic::ienumerable< type_t >
- Public Member Functions inherited from xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >
- Public Member Functions inherited from xtd::collections::generic::extensions::enumerable< ienumerable< type_t >, type_t >
type_t aggregate (const std::function< type_t(const type_t &, const type_t &)> &func) const
 Applies an accumulator function over a sequence.
 
type_t aggregate (const type_t &seed, const std::function< type_t(const type_t &, const type_t &)> &func) const
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
 
accumulate_t aggregate (const accumulate_t &seed, const std::function< accumulate_t(const type_t &, const accumulate_t &)> &func) const
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
 
type_t aggregate (const type_t &seed, const std::function< type_t(const type_t &, const type_t &)> &func, const std::function< type_t(const type_t &)> &result_selector) const
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
 
result_t aggregate (const accumulate_t &seed, const std::function< accumulate_t(const type_t &, const accumulate_t &)> &func, const std::function< result_t(const accumulate_t &)> &result_selector) const
 Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
 
bool all (const std::function< bool(const type_t &)> &predicate) const
 Determines whether all elements of a sequence satisfy a condition.
 
bool any () const noexcept
 Determines whether a sequence contains any elements.
 
bool any (const std::function< bool(const type_t &)> &predicate) const
 Determines whether any element of a sequence satisfies a condition.
 
const ienumerable< type_t > & append (const type_t &element) const noexcept
 Appends a value to the end of the sequence.
 
const ienumerable< type_t > & as_enumerable () const noexcept
 Returns the input typed as xtd::collections::generic::ienumerable <type_t>.
 
auto average () const noexcept
 Computes the average of a sequence of source_t values.
 
const ienumerable< result_t > & cast () const noexcept
 Casts the elements of an xtd::collections::generic::ienumerable to the specified type.
 
const ienumerable< xtd::array< type_t > > & chunk (size_t size) const
 Splits the elements of a sequence into chunks of size at most size.
 
const ienumerable< type_t > & concat (const ienumerable< type_t > &second) const noexcept
 Concatenates two sequences.
 
bool contains (const type_t &value) const noexcept
 Determines whether a sequence contains a specified element by using the default equality comparer.
 
bool contains (const type_t &value, const xtd::collections::generic::iequality_comparer< type_t > &comparer) const noexcept
 Determines whether a sequence contains a specified element by using a specified equality comparer.
 
size_t count () const noexcept
 Returns the number of elements in current sequence.
 
size_t count (const std::function< bool(const type_t &)> &predicate) const noexcept
 Returns a number that represents how many elements in the specified sequence satisfy a condition.
 
xtd::size count (const type_t &value) const noexcept
 Returns the number of elements with the specified value.
 
const ienumerable< key_value_pair< key_t, xtd::size > > & count_by (const std::function< key_t(const type_t &)> &key_selector) const noexcept
 Returns the count of elements in the current sequence grouped by key.
 
const ienumerable< key_value_pair< key_t, xtd::size > > & count_by (const std::function< key_t(const type_t &)> &key_selector, const iequality_comparer< key_t > &key_comparer) const noexcept
 Returns the count of elements in the current sequence grouped by key.
 
const ienumerable< type_t > & default_if_empty () const noexcept
 Returns the elements of the specified sequence or the type parameter's default value in a singleton collection if the current sequence is empty.
 
const ienumerable< type_t > & default_if_empty (const type_t &default_value) const noexcept
 Returns the elements of the specified sequence or the specified value in a singleton collection if the current sequence is empty.
 
type_t first_or_default (const std::function< bool(const type_t &)> &predicate, const type_t &default_value) const noexcept
 Returns the first element of the sequence that satisfies a condition, or a specified default value if no such element is found.
 
type_t first_or_default (const std::function< bool(const type_t &)> &predicate) const noexcept
 Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.
 
type_t first_or_default (const type_t default_value) const noexcept
 Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.
 
type_t first_or_default () const noexcept
 Returns the first element of the sequence that satisfies a condition or a default value if no such element is found.
 
const ienumerable< result_t > & select (const std::function< result_t(const type_t &)> &selector) const
 Projects each element of a sequence into a new form.
 
const ienumerable< type_t > & select (const std::function< type_t(const type_t &)> &selector) const
 Projects each element of a sequence into a new form.
 
const ienumerable< result_t > & select (const std::function< result_t(const type_t &, size_t index)> &selector) const
 Projects each element of a sequence into a new form by incorporating the element's index.
 
const ienumerable< type_t > & select (const std::function< type_t(const type_t &, size_t index)> &selector) const
 Projects each element of a sequence into a new form by incorporating the element's index.
 
const list< type_t > & to_list () const noexcept
 Creates a xtd::collections::generic::list <type_t> from an xtd::collections::generic::ienumerable <type_t>.
 
const ienumerable< type_t > & where (const std::function< bool(const type_t &)> &predicate) const
 Filters a sequence of values based on a predicate.
 
const ienumerable< type_t > & where (const std::function< bool(const type_t &, size_t)> &predicate) const
 Filters a sequence of values based on a predicate. Each element's index is used in the logic of the predicate function.
 
- Public Member Functions inherited from xtd::collections::generic::extensions::collection_operators< type_t, collection_t >
virtual collection_t & operator<< (const type_t &item)
 The shift left operator adds an item to the xtd::collections::generic::icollection <type_t>.
 
virtual collection_t & operator>> (const type_t &item)
 The shift right operator removes tthe first occurrence of a specific object from the xtd::collections::generic::icollection <type_t>.
 
- Public Member Functions inherited from xtd::iclonable
- Static Public Member Functions inherited from xtd::object
template<class object_a_t , class object_b_t >
static bool equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
template<class object_a_t , class object_b_t >
static bool reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 
- Static Public Member Functions inherited from xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >
static target_collection_t::const_iterator to_iterator (typename source_collection_t::const_iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept
 Converts source iterator to target iterator.
 
static target_collection_t::iterator to_iterator (typename source_collection_t::iterator &value, const source_collection_t &source_collection, const target_collection_t &target_collection) noexcept
 Converts source iterator to target iterator.
 
static target_collection_t::const_iterator to_iterator (typename source_collection_t::const_iterator &value, source_collection_t &source_collection, target_collection_t &target_collection) noexcept
 Converts source iterator to target iterator.
 
static target_collection_t::iterator to_iterator (typename source_collection_t::iterator &value, source_collection_t &source_collection, target_collection_t &target_collection) noexcept
 Converts source iterator to target iterator.
 

Member Typedef Documentation

◆ value_type

Represents the list value type.

◆ allocator_type

Represents the list allocator type.

◆ base_type

Represents the list base type.

◆ size_type

Represents the list size type (usually xtd::size).

◆ difference_type

Represents the list difference type (usually xtd::ptrdiff).

◆ reference

Represents the reference of list value type.

◆ const_reference

Represents the const reference of list value type.

◆ pointer

Represents the pointer of list value type.

◆ const_pointer

Represents the const pointer of list value type.

◆ iterator

Represents the iterator of list value type.

◆ const_iterator

Represents the const iterator of list value type.

Constructor & Destructor Documentation

◆ bit_array() [1/8]

xtd::collections::bit_array::bit_array ( xtd::size  length)
explicitnoexcept

Initializes a new instance of the xtd::collections::bit_array class that can hold the specified number of bit values, which are initially set to false.

Parameters
length_The number of bit values in the new xtd::collections::bit_array.
Exceptions
xtd::argument_out_of_range_exceptionlength_ is less than 0.
Remarks
This constructor is an O(n) operation, where n is length_.

◆ bit_array() [2/8]

xtd::collections::bit_array::bit_array ( xtd::size  length,
bool  defaultValue 
)
noexcept

Initializes a new instance of the xtd::collections::bit_array class that can hold the specified number of bit values, which are initially set to the specified value.

Parameters
length_The number of bit values in the new xtd::collections::bit_array.
defaultValueThebool value to assign to each bit.
Exceptions
xtd::argument_out_of_range_exceptionlength_ is less than 0.
Remarks
This constructor is an O(n) operation, where n is length_.

◆ bit_array() [3/8]

xtd::collections::bit_array::bit_array ( std::initializer_list< bool >  il)
noexcept

Initializes a new instance of the xtd::collections::bit_array class that contains bit values copied from the specified initializer list of booleans.

Parameters
valuesAn array of booleans to copy.
Remarks
This constructor is an O(n) operation, where n is the number of elements in values.

◆ bit_array() [4/8]

xtd::collections::bit_array::bit_array ( const xtd::array< bool > &  values)
noexcept

Initializes a new instance of the xtd::collections::bit_array class that contains bit values copied from the specified array of booleans.

Parameters
valuesAn initializer list of booleans to copy.
Remarks
This constructor is an O(n) operation, where n is the number of elements in values.

◆ bit_array() [5/8]

xtd::collections::bit_array::bit_array ( const xtd::array< xtd::byte > &  values)
noexcept

Initializes a new instance of the xtd::collections::bit_array class that contains bit values copied from the specified array of bytes.

Parameters
valuesAn array of bytes containing the values to copy, where each byte represents eight consecutive bits.
Remarks
The first byte in the array represents bits 0 through 7, the second byte represents bits 8 through 15, and so on. The Least Significant Bit of each byte represents the lowest index value: " bytes [0] & 1" represents bit 0, " bytes [0] & 2" represents bit 1, " bytes [0] & 4" represents bit 2, and so on.
This constructor is an O(n) operation, where n is the number of elements in values.

◆ bit_array() [6/8]

xtd::collections::bit_array::bit_array ( const xtd::array< int32 > &  values)
noexcept

Initializes a new instance of the xtd::collections::bit_array class that contains bit values copied from the specified array of 32-bit integers.

Parameters
valuesAn array of integers containing the values to copy, where each integer represents 32 consecutive bits.
Remarks
The number in the first values array element represents bits 0 through 31, the second number in the array represents bits 32 through 63, and so on. The Least Significant Bit of each integer represents the lowest index value: " values [0] & 1" represents bit 0, " values [0] & 2" represents bit 1, " values [0] & 4" represents bit 2, and so on.
This constructor is an O(n) operation, where n is the number of elements in values.

◆ bit_array() [7/8]

template<xtd::size length>
xtd::collections::bit_array::bit_array ( const std::bitset< length > &  bit_set)
inlinenoexcept

Initializes a new instance of the xtd::collections::bit_array class that contains bit values copied from the specified bitset.

Parameters
valuesA std::bitset object that contains bit values.
Remarks
This constructor is an O(n) operation, where n is the number of elements in values.

◆ bit_array() [8/8]

xtd::collections::bit_array::bit_array ( const std::vector< bool > &  booleans)
noexcept

Initializes a new instance of the xtd::collections::bit_array class that contains bit values copied from the specified std::vector<bool>.

Parameters
valuesA std::vector<bool> object that contains bit values.
Remarks
This constructor is an O(n) operation, where n is the number of elements in values.

Member Function Documentation

◆ begin() [1/2]

const_iterator xtd::collections::bit_array::begin ( ) const
inlineoverridevirtualnoexcept

Returns an iterator to the first element of the enumarable.

Returns
Iterator to the first element.

Reimplemented from xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >.

◆ begin() [2/2]

iterator xtd::collections::bit_array::begin ( )
inlineoverridevirtualnoexcept

Returns an iterator to the first element of the enumarable.

Returns
Iterator to the first element.

Reimplemented from xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >.

◆ bits() [1/2]

template<xtd::size length>
std::bitset< length > xtd::collections::bit_array::bits ( ) const
inlinenoexcept

Returns a std::bitset object containing the Booleans contained in the current xtd::collections::bit_array.

Returns
The std::bitset object.

◆ bits() [2/2]

std::vector< bool > xtd::collections::bit_array::bits ( ) const
inlinenoexcept

Returns a std::vector<bool> object containing the Booleans contained in the current xtd::collections::bit_array.

Returns
The std::vector<bool> object.

◆ cbegin()

const_iterator xtd::collections::bit_array::cbegin ( ) const
inlineoverridevirtualnoexcept

Returns an iterator to the first element of the enumarable.

Returns
Iterator to the first element.

Reimplemented from xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >.

◆ cend()

const_iterator xtd::collections::bit_array::cend ( ) const
inlineoverridevirtualnoexcept

Returns an iterator to the element following the last element of the enumarable.

Returns
Iterator to the element following the last element.

Reimplemented from xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >.

◆ count()

xtd::size xtd::collections::bit_array::count ( ) const
overridevirtualnoexcept

Gets the number of elements contained in the xtd::collections::bit_array.

Returns
The number of elements contained in the xtd::collections::bit_array.
Remarks
Retrieving the value of this property is an O(1) operation; setting the property is an O(n) operation, where n is the new capacity.

Implements xtd::collections::generic::icollection< bool >.

◆ empty()

virtual bool xtd::collections::bit_array::empty ( ) const
inlinevirtualnoexcept

Checks if the container has no elements, i.e. whether xtd::collections::bit_array::begin() == xtd::collections::bit_array::end().

Returns
true if the container is empty, false otherwise.

◆ end() [1/2]

const_iterator xtd::collections::bit_array::end ( ) const
inlineoverridevirtualnoexcept

Returns an iterator to the element following the last element of the enumarable.

Returns
Iterator to the element following the last element.

Reimplemented from xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >.

◆ end() [2/2]

iterator xtd::collections::bit_array::end ( )
inlineoverridevirtualnoexcept

Returns an iterator to the element following the last element of the enumarable.

Returns
Iterator to the element following the last element.

Reimplemented from xtd::collections::generic::extensions::enumerable_iterators< type_t, xtd::collections::generic::ienumerable< type_t > >.

◆ length() [1/2]

xtd::size xtd::collections::bit_array::length ( ) const
noexcept

Gets the number of elements contained in the xtd::collections::bit_array.

Returns
The number of elements contained in the xtd::collections::bit_array.
Remarks
xtd::collections::bit_array::length and xtd::collections::bit_array::count return the same value. xtd::collections::bit_array::length can be set to a specific value.

◆ length() [2/2]

void xtd::collections::bit_array::length ( xtd::size  value)

Sets the number of elements contained in the xtd::collections::bit_array.

Parameters
valueThe number of elements contained in the xtd::collections::bit_array.
Remarks
xtd::collections::bit_array::length and xtd::collections::bit_array::count return the same value. xtd::collections::bit_array::length can be set to a specific value.

◆ is_read_only()

bool xtd::collections::bit_array::is_read_only ( ) const
overridevirtualnoexcept

Gets a value indicating whether the xtd::collections::bit_array is read-only.

Returns
true if the xtd::collections::bit_array is read-only; otherwise, false.
Remarks
A collection that is read-only does not allow the addition or removal of elements after the collection is created. Note that read-only in this context does not indicate whether individual elements of the collection can be modified, since the xtd::collections::generic::icollection <type_t> interface only supports addition and removal operations. For example, the xtd::collections::generic::icollection::is_read_only property of an array that is cast or converted to an xtd::collections::generic::icollection <type_t> object returns true, even though individual array elements can be modified.

Implements xtd::collections::generic::icollection< bool >.

◆ is_synchronized()

bool xtd::collections::bit_array::is_synchronized ( ) const
overridevirtualnoexcept

Gets a value indicating whether access to the xtd::collections::generic::icollection <type_t> is synchronized (thread safe).

Returns
true if access to the xtd::collections::generic::icollection <type_t> is synchronized (thread safe); otherwise, false.
Remarks
xtd::collections::generic::icollection::sync_root returns an object, which can be used to synchronize access to the xtd::collections::generic::icollection <type_t>.
Most collection classes in the xtd::collections namespace also implement a synchronized method, which provides a synchronized wrapper around the underlying collection.
Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.
The following code example shows how to lock the collection using the xtd::collections::generic::icollection::sync_root property during the entire enumeration.
icollection& my_collection = some_collection;
lock_(my_collection.sync_root()) {
for (auto item : my_collection) {
// Insert your code here.
}
}
virtual const xtd::object & sync_root() const noexcept=0
Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollecti...
#define lock_(object)
The lock_ keyword marks a statement block as a critical section by obtaining the mutual-exclusion loc...
Definition lock.hpp:85

Implements xtd::collections::generic::icollection< bool >.

◆ sync_root()

const object & xtd::collections::bit_array::sync_root ( ) const
overridevirtualnoexcept

Gets an object that can be used to synchronize access to the the xtd::collections::generic::icollection <type_t>.

Returns
An object that can be used to synchronize access to the the xtd::collections::generic::icollection <type_t>.
Remarks
For collections whose underlying store is not publicly available, the expected implementation is to return the current instance. Note that the pointer to the current instance might not be sufficient for collections that wrap other collections; those should return the underlying collection's sync_root property.
Most collection classes in the xts::.collections namespace also implement a synchronized method, which provides a synchronized wrapper around the underlying collection. However, derived classes can provide their own synchronized version of the collection using the xtd::collections::generic::icollection::sync_root property. The synchronizing code must perform operations on the xtd::collections::generic::icollection::sync_root property of the collection, not directly on the collection. This ensures proper operation of collections that are derived from other objects. Specifically, it maintains proper synchronization with other threads that might be simultaneously modifying the collection instance.
In the absence of a synchronized method on a collection, the expected usage for the xtd::collections::generic::icollection::sync_root looks as follows:
icollection& my_collection = some_collection;
lock_(my_collection.sync_root()) {
// Some operation on the collection, which is now thread safe.
}
@encode
@remarks Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.
@remarks The following code example shows how to lock the collection using the xtd::collections::generic::icollection::sync_root property during the entire enumeration.
@code
icollection& my_collection = some_collection;
lock_(my_collection.sync_root()) {
for (auto item : my_collection) {
// Insert your code here.
}
}
Defines the base class for predefined exceptions in the xtd namespace.
Definition exception.hpp:28
Provides a mechanism that synchronizes access to objects with xtd::threading::monitor.
Definition lock_guard.hpp:32
bool is(std::any value)
Checks if the result of an expression is compatible with a given type.
Definition is.hpp:365
@ other
The operating system is other.
@ a
The A key.
Supports a simple iteration over a generic collection.
Definition enumerator.hpp:38

Implements xtd::collections::generic::icollection< bool >.

◆ and_()

const bit_array & xtd::collections::bit_array::and_ ( const bit_array value)

Performs the bitwise AND operation on the elements in the current xtd::collections::bit_array against the corresponding elements in the specified xtd::collections::bit_array.

Parameters
valueThe xtd::collections::bit_array with which to perform the bitwise AND operation.
Returns
The current instance containing the result of the bitwise AND operation on the elements in the current xtd::collections::bit_array against the corresponding elements in the specified xtd::collections::bit_array.
Exceptions
xtd::argument_exceptionvalue and the current xtd::collections::bit_array do not have the same number of elements.
Remarks
The bitwise AND operation returns true if both operands are true, and returns false if one or both operands are false.
This method is an O(n) operation, where n is count.

◆ at() [1/2]

bool xtd::collections::bit_array::at ( xtd::size  index) const

Gets the value of the bit at a specific position in the xtd::collections::bit_array.

Parameters
indexThe zero-based index of the value to get.
Returns
The value of the bit at position index.
Exceptions
xtd::argument_out_of_range_exceptionindex is less than zero. -or- index is greater than or equal to the number of elements in the xtd::collections::bit_array.
Remarks
This method is an O(1) operation.

◆ at() [2/2]

bool & xtd::collections::bit_array::at ( xtd::size  index)

Gets the value of the bit at a specific position in the xtd::collections::bit_array.

Parameters
indexThe zero-based index of the value to get.
Returns
The value of the bit at position index.
Exceptions
xtd::argument_out_of_range_exceptionindex is less than zero. -or- index is greater than or equal to the number of elements in the xtd::collections::bit_array.
Remarks
This method is an O(1) operation.

◆ clone()

xtd::uptr< xtd::object > xtd::collections::bit_array::clone ( ) const
overridevirtual

Creates a new object that is a copy of the current instance.

Returns
A new object that is a copy of this instance.

Implements xtd::iclonable.

◆ copy_to()

void xtd::collections::bit_array::copy_to ( xtd::array< bool > &  array,
xtd::size  index 
) const
overridevirtual

Copies the elements of the xtd::collections::bit_array to an xtd::array, starting at a particular xtd::array index.

Parameters
arrayThe one-dimensional xtd::array that is the destination of the elements copied from xtd::collections::bit_array. The xtd::array must have zero-based indexing.
indexThe zero-based index in array at which copying begins;
Returns
Number of elements copied.

Implements xtd::collections::generic::icollection< bool >.

◆ equals() [1/2]

bool xtd::collections::bit_array::equals ( const bit_array value) const
overridenoexcept

Determines whether this instance of xtd::collections::bit_array and a specified object, which must also be a xtd::collections::bit_array object, have the same value.

Parameters
valueThe xtd::collections::bit_array to compare with the current object.
Returns
true if the specified value is equal to the current object. otherwise, false.

◆ equals() [2/2]

bool xtd::collections::bit_array::equals ( const object obj) const
overridevirtualnoexcept

Determines whether this instance of xtd::collections::bit_array and a specified object, which must also be a xtd::collections::bit_array object, have the same value.

Parameters
objThe object to compare with the current object.
Returns
true if the specified object is equal to the current object. otherwise, false.

Reimplemented from xtd::object.

◆ get() [1/2]

bool xtd::collections::bit_array::get ( xtd::size  index) const

Gets the value of the bit at a specific position in the xtd::collections::bit_array.

Parameters
indexThe zero-based index of the value to get.
Returns
The value of the bit at position index.
Exceptions
xtd::argument_out_of_range_exceptionindex is less than zero. -or- index is greater than or equal to the number of elements in the xtd::collections::bit_array.
Remarks
This method is an O(1) operation.

◆ get() [2/2]

bool & xtd::collections::bit_array::get ( xtd::size  index)

Gets the value of the bit at a specific position in the xtd::collections::bit_array.

Parameters
indexThe zero-based index of the value to get.
Returns
The value of the bit at position index.
Exceptions
xtd::argument_out_of_range_exceptionindex is less than zero. -or- index is greater than or equal to the number of elements in the xtd::collections::bit_array.
Remarks
This method is an O(1) operation.

◆ get_enumerator()

xtd::collections::generic::enumerator< bool > xtd::collections::bit_array::get_enumerator ( ) const
overridevirtual

Returns an enumerator that iterates through a collection.

Returns
An xtd::collections::generic::ienumerator object that can be used to iterate through the collection.

Implements xtd::collections::generic::ienumerable< type_t >.

◆ has_all_set()

bool xtd::collections::bit_array::has_all_set ( ) const
noexcept

Determines whether all bits in the xtd::collections::bit_array are set to true.

Returns
true if every bit in the xtd::collections::bit_array is set to true, or if xtd::collections::bit_array is empty; otherwise, false.

◆ has_any_set()

bool xtd::collections::bit_array::has_any_set ( ) const
noexcept

Determines whether any bit in the xtd::collections::bit_array is set to true.

Returns
true if xtd::collections::bit_array is not empty and at least one of its bit is set to true; otherwise, false.

◆ left_shift()

bit_array & xtd::collections::bit_array::left_shift ( xtd::size  count)
noexcept

Shifts all the bit values of the current xtd::collections::bit_array to the left on count bits.

Parameters
countThe number of shifts to make for each bit.
Returns
The current xtd::collections::bit_array.
Remarks
The current xtd::collections::bit_array is updated and returned.

◆ not_()

const bit_array & xtd::collections::bit_array::not_ ( )

Inverts all the bit values in the current xtd::collections::bit_array, so that elements set to true are changed to false, and elements set to false are changed to true.

Returns
The current instance with inverted bit values.
Remarks
This method is an O(n) operation, where n is count.

◆ or_()

const bit_array & xtd::collections::bit_array::or_ ( const bit_array value)

Performs the bitwise OR operation on the elements in the current xtd::collections::bit_array against the corresponding elements in the specified xtd::collections::bit_array.

Parameters
valueThe xtd::collections::bit_array with which to perform the bitwise OR operation.
Returns
The current instance containing the result of the bitwise OR operation on the elements in the current xtd::collections::bit_array against the corresponding elements in the specified xtd::collections::bit_array.
Exceptions
xtd::argument_exceptionvalue and the current xtd::collections::bit_array do not have the same number of elements.
Remarks
The bitwise OR operation returns true if one or both operands are true, and returns false if both operands are false.
This method is an O(n) operation, where n is count.

◆ right_shift()

bit_array & xtd::collections::bit_array::right_shift ( xtd::size  count)
noexcept

Shifts all the bit values of the current xtd::collections::bit_array to the right on count bits.

Parameters
countThe number of shifts to make for each bit.
Returns
The current xtd::collections::bit_array.
Remarks
The current xtd::collections::bit_array is updated and returned.

◆ set()

void xtd::collections::bit_array::set ( xtd::size  index,
bool  value 
)

Sets the value of the bit at a specific position in the xtd::collections::bit_array.

Parameters
indexThe zero-based index of the value to get.
valueThe bool value to assign to the bit.
Exceptions
xtd::argument_out_of_range_exceptionindex is less than zero. -or- index is greater than or equal to the number of elements in the xtd::collections::bit_array.
Remarks
This method is an O(1) operation.

◆ set_all()

void xtd::collections::bit_array::set_all ( bool  value)

Sets all bits in the xtd::collections::bit_array to the specified value.

Parameters
valueThe bool value to assign to all bits.
Remarks
This method is an O(n) operation, where n is count.

◆ to_string()

xtd::string xtd::collections::bit_array::to_string ( ) const
overridevirtualnoexcept

Returns a xtd::string that represents the current object.

Returns
A string that represents the current object.

Reimplemented from xtd::object.

◆ xor_()

const bit_array & xtd::collections::bit_array::xor_ ( const bit_array value)

Performs the bitwise exclusive OR operation on the elements in the current xtd::collections::bit_array against the corresponding elements in the specified xtd::collections::bit_array.

Parameters
valueThe xtd::collections::bit_array with which to perform the bitwise exclusive OR operation.
Returns
The current instance containing the result of the bitwise exclusive OR operation on the elements in the current xtd::collections::bit_array against the corresponding elements in the specified xtd::collections::bit_array.
Exceptions
xtd::argument_exceptionvalue and the current xtd::collections::bit_array do not have the same number of elements.
Remarks
The bitwise exclusive OR operation returns true if exactly one operand is true, and returns false if both operands have the same bool value.
This method is an O(n) operation, where n is count.

◆ operator[]() [1/2]

const bool & xtd::collections::bit_array::operator[] ( xtd::size  index) const

Gets the element at the specified index.

Parameters
indexThe zero-based index of the element to get.
Returns
The element at the specified index.
Exceptions
xtd::argument_out_of_range_exceptionindex is less than 0 or index is equal to or greater than count.

◆ operator[]() [2/2]

bool & xtd::collections::bit_array::operator[] ( xtd::size  index)

Gets or Sets the element at the specified index.

Parameters
indexThe zero-based index of the element to get.
Returns
The element at the specified index.
Exceptions
xtd::argument_out_of_range_exceptionindex is less than 0 or index is equal to or greater than count.

◆ operator>>()

bit_array xtd::collections::bit_array::operator>> ( xtd::size  count) const
noexcept

The right shift operator shifts all the bit values of the current xtd::collections::bit_array to the right on count bits.

Parameters
countThe number of shifts to make for each bit.
Returns
The new shifted xtd::collections::bit_array.
Remarks
The current xtd::collections::bit_array is not updated.

◆ operator>>=()

bit_array & xtd::collections::bit_array::operator>>= ( xtd::size  count)
noexcept

The right shift operator shifts all the bit values of the current xtd::collections::bit_array to the right on count bits.

Parameters
countThe number of shifts to make for each bit.
Returns
The current xtd::collections::bit_array.
Remarks
The current xtd::collections::bit_array is updated and returned.

◆ operator<<()

bit_array xtd::collections::bit_array::operator<< ( xtd::size  count) const
noexcept

The left shift operator shifts all the bit values of the current xtd::collections::bit_array to the left on count bits.

Parameters
countThe number of shifts to make for each bit.
Returns
The new shifted xtd::collections::bit_array.
Remarks
The current xtd::collections::bit_array is not updated.

◆ operator<<=()

bit_array & xtd::collections::bit_array::operator<<= ( xtd::size  count)
noexcept

The left shift operator shifts all the bit values of the current xtd::collections::bit_array to the left on count bits.

Parameters
countThe number of shifts to make for each bit.
Returns
The current xtd::collections::bit_array.
Remarks
The current xtd::collections::bit_array is updated and returned.

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