Hi,
I have a bit of code where I am relying on empty base member
optimisation. The bit of code is below:
template<typename Enum>
struct EncodePrefix
{
template<Enum e>
struct Apply
{
struct Type
{
const unsigned char Value;
Type() : Value((unsigned char)e) {}
};
};
template<>
struct Apply<(Enum)ENUM_NONE>
{
//typedef Apply Type;
struct Type {};
};
};
template<EnumRepLockPrefix RepLockPrefix, EnumSegPrefix SegPrefix
,EnumOperandSizePrefix OperandSizePrefix
,EnumAddressSizePrefix AddressSizePrefix
,EnumSimdPrefix SimdPrefix>
struct EncodePrefixes
: EncodePrefix<EnumRepLockPrefix>::Apply<RepLockPref ix>::Type
, EncodePrefix<EnumSegPrefix>::Apply<SegPrefix>::Typ e
, EncodePrefix<EnumOperandSizePrefix>
::Apply<OperandSizePrefix>::Type
, EncodePrefix<EnumAddressSizePrefix>
::Apply<AddressSizePrefix>::Type
, EncodePrefix<EnumSimdPrefix>::Apply<SimdPrefix>::T ype
{
};
So when I define EncodePrefixes like this:
EncodePrefixes<NONE,NONE,NONE,NONE,NONE> ep;
I expect:
std::assert(sizeof(ep) == 1);
Unfortunately this is not the case because the msvc doesn't do empty
base member optimisation for multiple inheritance, in-case you are
wondering, sizeof(ep) == 4.
Does anyone have a work-around for which doesn't involve explicit
specialisation of the EncodePrefix class 5*2 times.
---
David