Subject: [Boost-bugs] [Boost C++ Libraries] #3731: array without padding
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2009-12-08 14:13:41
#3731: array without padding
------------------------------+---------------------------------------------
Reporter: anonymous | Owner:
Type: Feature Requests | Status: new
Milestone: Boost 1.42.0 | Component: None
Version: Boost 1.41.0 | Severity: Problem
Keywords: |
------------------------------+---------------------------------------------
Sometimes you have a struct with array in it:
{{{
#!cpp
#pragma pack(push, 1)
struct X
{
int i[10];
};
#pragma pack(pop)
}}}
And you want to use boost::array :
{{{
#!cpp
#pragma pack(push, 1)
struct X
{
boost::array<int, 10> i;
};
#pragma pack(pop)
}}}
The problem that boost::array is not surrounded with #pragma pack.
It would be nice to add a new class boost::array_no_padding with #pragma
pack surrounded and with static assert for size checking.
{{{
#!cpp
#if !BOOST_SUPPORTS_PRAGMA_PACK &&
!BOOST_SUPPORTS_ALIGNMENT_PREFIX &&
!BOOST_SUPPORTS_ALIGNMENT_SUFFIX
#error Cannot specify alighnemnt
#endif
namespace boost {
#if BOOST_SUPPORTS_PRAGMA_PACK
#define ALIGNMENT_SET
#pramga pack(push, 1)
#endif
template<class T, std::size_t N>
class
#if !defined(ALIGNMENT) && BOOST_SUPPORTS_ALIGNMENT_PREFIX
// Could be __declspec(align(1))
BOOST_ALIGNMENT_PREFIX
#define ALIGNMENT_SET
#endif
array_no_padding
#if !defined(ALIGNMENT) && BOOST_SUPPORTS_ALIGNMENT_SUFFIX
// Could be __attribute__((aligned(1)))
BOOST_ALIGNMENT_SUFFIX
#define ALIGNMENT_SET
#endif
// Can derive from boost::array or copy-paste all the content
: boost::array
{
// ...
// Check class size with the array size
BOOST_STATIC_ASSERT( sizeof(*this) == sizeof(T[N]) );
}
#if BOOST_SUPPORTS_PRAGMA_PACK
#pragma pack(pop)
#endif
}}}
Thanx !
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/3731> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:02 UTC