Skip to content

Additional constructors/possible-classification for std::bitv #2964

Closed
@Dretch

Description

@Dretch

I have written these functions for my own use, but I would like it better if they were inside std::bitv:

/**
 * Transform a byte-vector into a bitv. Each byte becomes 8 bits,
 * with the most significant bits of each byte coming first. Each
 * bit becomes true if equal to 1 or false if equal to 0.
 */
fn from_bytes(bytes: [u8]) -> bitv;

/**
 * Transform a [bool] into a bitv by converting each bool into a bit.
 */
fn from_bools(bools: [bool]) -> bitv;

/**
 * Create a bitv of the specified length where the value at each
 * index is f(index).
 */
fn from_fn(len: uint, f: fn(index: uint) -> bool) -> bitv;

(there are also corresponding to_bytes/to_bools methods).

As a separate but related issue, I think it would be nice if the bitv type was turned into a class and its internal data marked as private members.

As either of these requests pleasing to you? I can provide pull requests (with tests/docs/etc) if they are.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions