What I want to achieve is to get base64 string from std::vector<bool>. Basing on examples of boost::archive::iterator::base64_from_binary I've created the following implementation, but is has some drawbacks:
std::string get_as_base64(const std::vector<bool> &sequence) {
namespace bai = boost::archive::iterators;
std::ostringstream stream;
typedef bai::base64_from_binary<bai::transform_width<std::vector<bool>::const_iterator, 6, 1, char>> base64_encoder;
std::copy(base64_encoder(sequence.cbegin()), base64_encoder(sequence.cend()), bai::ostream_iterator<char>(stream));
return stream.str();
}
First thing, it requires the container to has the size as the multiple of 6 (in other case it encounters infinite loop possibly by some misimplementation). Next thing, it causes some compiler warnings to occur because of mangling bool and char types. I've just think that transform_width is not the right tool because it was designed to operate on strings...
Could you propose some better implementation?