std::bitset has a to_string() method for serializing as a char-based string of 1s and 0s. Obviously, this us
Answering my own question for completeness.
Apparently, there is no simple and portable way of doing this.
For simplicity (though not efficiency), I ended up using to_string, and then creating consecutive 32-bit bitsets from all 32-bit chunks of the string (and the remainder*), and using to_ulong on each of these to collect the bits into a binary buffer.
This approach leaves the bit-twiddling to the STL itself, though it is probably not the most efficient way to do this.
* Note that since std::bitset is templated on the total bit-count, the remainder bitset needs to use some simple template meta-programming arithmetic.