Page MenuHomePhabricator

Improve std::bitset support in Channel/Stringify
Closed, ResolvedPublic3 Energy Points (d+f*r)

Description

The documentation promises the following will work:

std::bitset<32> foo = std::bitset<32>(12345678);
channel << IOFormatMemSep::all << foo << IOCtrl::endl;
/* OUTPUT:
4e 61 bc 00
*/

This feature is missing from Channel 2.0. It either needs to be implemented in the code (preferred) or dropped from the docs.

Details

Task Type
Feature
Proposed Urgency
Established
Gravity
g3: Major
Friction
Triage Friction
Relativity
Triage Relativity
Volatility (Caught At)
Not a Bug
Origin
Not a Bug/Unknown

Event Timeline

jcmcdonald triaged this task as p4: Now priority.EditedNov 28 2020, 12:52 PM
jcmcdonald created this task.

My initial thought on implementing this is adding the following to Channel:

	template<size_t S>
	Channel& operator<<(const std::bitset<S>& rhs) {
		if (!can_parse()) {
			return *this;
		}

		// Bitsets should always be rendered via memory
		auto prior_mem_view = this->fmt.ptr();
		this->fmt << IOFormatPtr::memory;
		inject(stringify(&rhs, this->fmt));

		// Restore prior memory view.
		this->fmt << prior_mem_view;

		return *this;
	}

Thanks to @ardunster for the help!!