Support any truncating store in endian_store

This commit is contained in:
Peter Dimov
2019-04-30 20:39:17 +03:00
parent b0cc5e64d3
commit 8df14956d4
2 changed files with 424 additions and 305 deletions

View File

@ -74,6 +74,92 @@ template<class T, std::size_t N, BOOST_SCOPED_ENUM(order) O1, BOOST_SCOPED_ENUM(
} }
}; };
// truncating store 2 -> 1
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 2, Order, 1, order::little>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 2 ];
boost::endian::endian_store<T, 2, order::little>( tmp, v );
p[0] = tmp[0];
}
};
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 2, Order, 1, order::big>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 2 ];
boost::endian::endian_store<T, 2, order::big>( tmp, v );
p[0] = tmp[1];
}
};
// truncating store 4 -> 1
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 4, Order, 1, order::little>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 4 ];
boost::endian::endian_store<T, 4, order::little>( tmp, v );
p[0] = tmp[0];
}
};
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 4, Order, 1, order::big>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 4 ];
boost::endian::endian_store<T, 4, order::big>( tmp, v );
p[0] = tmp[3];
}
};
// truncating store 4 -> 2
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 4, Order, 2, order::little>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 4 ];
boost::endian::endian_store<T, 4, order::little>( tmp, v );
p[0] = tmp[0];
p[1] = tmp[1];
}
};
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 4, Order, 2, order::big>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 4 ];
boost::endian::endian_store<T, 4, order::big>( tmp, v );
p[0] = tmp[2];
p[1] = tmp[3];
}
};
// truncating store 4 -> 3 // truncating store 4 -> 3
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 4, Order, 3, order::little> template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 4, Order, 3, order::little>
@ -106,6 +192,130 @@ template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 4,
} }
}; };
// truncating store 8 -> 1
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 1, order::little>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 8 ];
boost::endian::endian_store<T, 8, order::little>( tmp, v );
p[0] = tmp[0];
}
};
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 1, order::big>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 8 ];
boost::endian::endian_store<T, 8, order::big>( tmp, v );
p[0] = tmp[7];
}
};
// truncating store 8 -> 2
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 2, order::little>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 8 ];
boost::endian::endian_store<T, 8, order::little>( tmp, v );
p[0] = tmp[0];
p[1] = tmp[1];
}
};
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 2, order::big>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 8 ];
boost::endian::endian_store<T, 8, order::big>( tmp, v );
p[0] = tmp[6];
p[1] = tmp[7];
}
};
// truncating store 8 -> 3
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 3, order::little>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 8 ];
boost::endian::endian_store<T, 8, order::little>( tmp, v );
p[0] = tmp[0];
p[1] = tmp[1];
p[2] = tmp[2];
}
};
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 3, order::big>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 8 ];
boost::endian::endian_store<T, 8, order::big>( tmp, v );
p[0] = tmp[5];
p[1] = tmp[6];
p[2] = tmp[7];
}
};
// truncating store 8 -> 4
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 4, order::little>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 8 ];
boost::endian::endian_store<T, 8, order::little>( tmp, v );
p[0] = tmp[0];
p[1] = tmp[1];
p[2] = tmp[2];
p[3] = tmp[3];
}
};
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 4, order::big>
{
inline void operator()( unsigned char * p, T const & v ) const BOOST_NOEXCEPT
{
BOOST_STATIC_ASSERT( is_integral<T>::value || is_enum<T>::value );
unsigned char tmp[ 8 ];
boost::endian::endian_store<T, 8, order::big>( tmp, v );
p[0] = tmp[4];
p[1] = tmp[5];
p[2] = tmp[6];
p[3] = tmp[7];
}
};
// truncating store 8 -> 5 // truncating store 8 -> 5
template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 5, order::little> template<class T, BOOST_SCOPED_ENUM(order) Order> struct endian_store_impl<T, 8, Order, 5, order::little>

View File

@ -59,343 +59,252 @@ public:
} }
}; };
template<class T> void test_1()
{
{
unsigned char v[] = { 0xAA, 0xAA };
boost::endian::endian_store<T, 1, boost::endian::order::little>( v, 0x01 );
unsigned char w[] = { 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA };
boost::endian::endian_store<T, 1, boost::endian::order::big>( v, 0x01 );
unsigned char w[] = { 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
}
template<class T> void test_2()
{
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 2, boost::endian::order::little>( v, 0x0102 );
unsigned char w[] = { 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 2, boost::endian::order::big>( v, 0x0102 );
unsigned char w[] = { 0x01, 0x02, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
}
template<class T> void test_3()
{
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 3, boost::endian::order::little>( v, 0x010203 );
unsigned char w[] = { 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 3, boost::endian::order::big>( v, 0x010203 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
}
template<class T> void test_4()
{
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 4, boost::endian::order::little>( v, 0x01020304 );
unsigned char w[] = { 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 4, boost::endian::order::big>( v, 0x01020304 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
}
template<class T> void test_5()
{
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 5, boost::endian::order::little>( v, 0x0102030405 );
unsigned char w[] = { 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 5, boost::endian::order::big>( v, 0x0102030405 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
}
template<class T> void test_6()
{
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 6, boost::endian::order::little>( v, 0x010203040506 );
unsigned char w[] = { 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 6, boost::endian::order::big>( v, 0x010203040506 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
}
template<class T> void test_7()
{
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 7, boost::endian::order::little>( v, 0x01020304050607 );
unsigned char w[] = { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 7, boost::endian::order::big>( v, 0x01020304050607 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
}
template<class T> void test_8()
{
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 8, boost::endian::order::little>( v, 0x0102030405060708 );
unsigned char w[] = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<T, 8, boost::endian::order::big>( v, 0x0102030405060708 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
}
int main() int main()
{ {
// 1 // 1
{ test_1<boost::int8_t>();
unsigned char v[] = { 0xAA, 0xAA }; test_1<boost::uint8_t>();
boost::endian::endian_store<boost::int8_t, 1, boost::endian::order::little>( v, 0x01 ); test_1<boost::int16_t>();
test_1<boost::uint16_t>();
unsigned char w[] = { 0x01, 0xAA }; test_1<boost::int32_t>();
test_1<boost::uint32_t>();
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) ); test_1<boost::int64_t>();
} test_1<boost::uint64_t>();
{
unsigned char v[] = { 0xAA, 0xAA };
boost::endian::endian_store<boost::uint8_t, 1, boost::endian::order::little>( v, 0x01 );
unsigned char w[] = { 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA };
boost::endian::endian_store<boost::int8_t, 1, boost::endian::order::big>( v, 0x01 );
unsigned char w[] = { 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA };
boost::endian::endian_store<boost::uint8_t, 1, boost::endian::order::big>( v, 0x01 );
unsigned char w[] = { 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
// 2 // 2
{ test_2<boost::int16_t>();
unsigned char v[] = { 0xAA, 0xAA, 0xAA }; test_2<boost::uint16_t>();
boost::endian::endian_store<boost::int16_t, 2, boost::endian::order::little>( v, 0x0102 ); test_2<boost::int32_t>();
test_2<boost::uint32_t>();
unsigned char w[] = { 0x02, 0x01, 0xAA }; test_2<boost::int64_t>();
test_2<boost::uint64_t>();
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint16_t, 2, boost::endian::order::little>( v, 0x0102 );
unsigned char w[] = { 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::int16_t, 2, boost::endian::order::big>( v, 0x0102 );
unsigned char w[] = { 0x01, 0x02, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint16_t, 2, boost::endian::order::big>( v, 0x0102 );
unsigned char w[] = { 0x01, 0x02, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
// 3 // 3
{ test_3<boost::int32_t>();
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA }; test_3<boost::uint32_t>();
boost::endian::endian_store<boost::int32_t, 3, boost::endian::order::little>( v, 0x010203 ); test_3<boost::int64_t>();
test_3<boost::uint64_t>();
unsigned char w[] = { 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint32_t, 3, boost::endian::order::little>( v, 0x010203 );
unsigned char w[] = { 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::int32_t, 3, boost::endian::order::big>( v, 0x010203 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint32_t, 3, boost::endian::order::big>( v, 0x010203 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
// 4 // 4
{ test_4<boost::int32_t>();
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; test_4<boost::uint32_t>();
boost::endian::endian_store<boost::int32_t, 4, boost::endian::order::little>( v, 0x01020304 ); test_4<boost::int64_t>();
test_4<boost::uint64_t>();
unsigned char w[] = { 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint32_t, 4, boost::endian::order::little>( v, 0x01020304 );
unsigned char w[] = { 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::int32_t, 4, boost::endian::order::big>( v, 0x01020304 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint32_t, 4, boost::endian::order::big>( v, 0x01020304 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
// 5 // 5
{ test_5<boost::int64_t>();
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; test_5<boost::uint64_t>();
boost::endian::endian_store<boost::int64_t, 5, boost::endian::order::little>( v, 0x0102030405 );
unsigned char w[] = { 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint64_t, 5, boost::endian::order::little>( v, 0x0102030405 );
unsigned char w[] = { 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::int64_t, 5, boost::endian::order::big>( v, 0x0102030405 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint64_t, 5, boost::endian::order::big>( v, 0x0102030405 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
// 6 // 6
{ test_6<boost::int64_t>();
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; test_6<boost::uint64_t>();
boost::endian::endian_store<boost::int64_t, 6, boost::endian::order::little>( v, 0x010203040506 );
unsigned char w[] = { 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint64_t, 6, boost::endian::order::little>( v, 0x010203040506 );
unsigned char w[] = { 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::int64_t, 6, boost::endian::order::big>( v, 0x010203040506 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint64_t, 6, boost::endian::order::big>( v, 0x010203040506 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
// 7 // 7
{ test_7<boost::int64_t>();
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; test_7<boost::uint64_t>();
boost::endian::endian_store<boost::int64_t, 7, boost::endian::order::little>( v, 0x01020304050607 );
unsigned char w[] = { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint64_t, 7, boost::endian::order::little>( v, 0x01020304050607 );
unsigned char w[] = { 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::int64_t, 7, boost::endian::order::big>( v, 0x01020304050607 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint64_t, 7, boost::endian::order::big>( v, 0x01020304050607 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
// 8 // 8
{ test_8<boost::int64_t>();
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA }; test_8<boost::uint64_t>();
boost::endian::endian_store<boost::int64_t, 8, boost::endian::order::little>( v, 0x0102030405060708 );
unsigned char w[] = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint64_t, 8, boost::endian::order::little>( v, 0x0102030405060708 );
unsigned char w[] = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::int64_t, 8, boost::endian::order::big>( v, 0x0102030405060708 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
{
unsigned char v[] = { 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA };
boost::endian::endian_store<boost::uint64_t, 8, boost::endian::order::big>( v, 0x0102030405060708 );
unsigned char w[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0xAA };
BOOST_TEST_EQ( byte_span( v ), byte_span( w ) );
}
return boost::report_errors(); return boost::report_errors();
} }