iterator
iterator copied to clipboard
function_output_iterator does not support specialization
I have a vector of std::byte and I want to call boost::unhex for this vector by creating a custom output iterator with my own unary function to convert unsiged char to std::byte. Note that std::byte is not an integral type so I cannot pass it directly to boost::unhex
It is possible to create a function_output_iterator where we can specify the value_type (ex, function_output_iterator<unsigned char>)?
The alternative I have is to create a vector of unsigned char then copy it into a vector of std::byte but this is what I want to avoid.
This is what I tried:
const std::string hexString = "0A";
auto outputVector = std::vector<std::byte>{};
auto unary_func = [&](const unsigned char& c) { outputVector .push_back(std::byte{c}); };
auto func_out_iterator = boost::make_function_output_iterator(unary_func);
boost::algorithm::unhex(hexString, func_out_iterator );
and I got:
error C2893: Failed to specialize function template 'boost::enable_if<boost::is_integral<hex_iterator_traits<OutputIterator>::value_type>,OutputIterator>::type boost::algorithm::detail::decode_one(InputIterator &,InputIterator,OutputIterator,EndPred)'