On 04/28/16 09:07, Marcel Mueller wrote:
> I have a POD structure that should be initialized at compile time.
> For this purpose I created a derived type with a constructor. This seems
> to be impossible with C++11. At least I did not find a trick so far.
> I get an error "constexpr constructor does not have an empty body".
>
> The base type must be POD because it is also part of unions.
Do you need pod, or just standard layout?
If the latter, you could skip the helper and give rPUp constexpr
constructors, something like
enum Pack : uint8_t
{ P_16a
, P_16b
//...
};
enum Unpack : uint8_t
{ U_8a = 0x80
//...
};
struct rPUp
{
uint8_t Mode;
constexpr rPUp(Pack pack) : Mode{ pack } {}
constexpr rPUp(Unpack unpack): Mode {unpack|0x80} {}
constexpr bool isUnpack() const { return (Mode & 0x80) != 0; }
constexpr operator int() const { return Mode; }
// other member functions...
};
--
Ian Collins