ProblemsMemory ManagementEleven bits, two bytes, zero heap
AdvancedMemory Management

Eleven bits, two bytes, zero heap

Context

The packed-bits trick from the BitSet task, pushed to its honest limit: the object itself must be at most two bytes, so the storage is one uint16_t member — no pointers, no allocation. sizeof(a) <= 2 in the test is the contract; everything else follows from it.

Task

Bit11Array stores exactly 11 boolean flags and the WHOLE object must fit in two bytes — the test checks sizeof. Reads and writes go through a[i] (a proxy again), and operator! returns a flipped copy. No heap, no bool arrays.

Constraints

  • sizeof(Bit11Array) <= 2 (checked by static_assert)
  • Default-constructed: all 11 bits are zero
  • a[i] reads and writes bit i (0..10) through a proxy
  • !a returns a copy with all 11 bits flipped; the original is unchanged

Before you code

  • Why does a heap pointer instantly break the sizeof contract?
  • How does the proxy differ from the BitSet one? (it can store the object pointer + index)
  • Why does operator! flip only 11 bits and not all 16 of the underlying storage?

Tests

  • #1Two bytes, reads and writes
  • #2operator! flips a copy
  • #3Const read works

Hints

Hint 1

One uint16_t member is the whole storage; the proxy keeps a pointer to it plus the bit index.

Hint 2

For operator!, flip with XOR/NOT and mask to the low 11 bits: 0x07FF.

Editorbit11-array.cpp
Results

Hit Submit (or ⌘/Ctrl + ↵) — test results will show up here.