Le 26/01/2017 à 00:04, Vicente J. Botet Escriba a écrit :
Hi,
I wanted to put an Int wrapper inside a endian_buffer and I have some compiler errors depending on whether it is aligned ort not.
http://melpon.org/wandbox/permlink/k52wH2A7yagL2vMP
I was expecting that the endian_buffer would make abstraction of the wrapped type and consider it just as a sequence of bytes, but it seems that it instead works only for some builtin integral.
Am I missing something? Was this restriction intended? Could this restriction be removed and if yes, how?
I have reached to fix the aligned case adding the customization
Int endian_reverse(Int x)
{
using boost::endian::endian_reverse;
return Int {endian_reverse(x.value)};
}
However for the unaligned case there is yet the shift error
prog.cc:30:28: required from here
/usr/local/boost-1.61.0/include/boost/endian/buffers.hpp:231:26: error: invalid static_cast from type 'Int' to type 'char'
*(bytes - 1) = static_cast<char>(value);
^~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/boost-1.61.0/include/boost/endian/buffers.hpp:232:59: error: no match for 'operator>>' (operand types are 'Int' and 'int')
next::store_big(bytes - 1, static_cast<T>(value >> 8));
~~~~~~^~~~
/usr/local/boost-1.61.0/include/boost/endian/buffers.hpp:202:5: note: candidate: template