bitrex
unread,Apr 3, 2016, 5:25:52 PM4/3/16You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
So the following code compiles fine under gcc (C++14), to build an array
of squares:
#define F4(i) F1((i)), F1((i)+1), F1((i)+2), F1((i)+3)
#define F16(i) F4((i)), F4((i)+4), F4((i)+8), F4((i)+12)
#define F64(i) F16((i)), F16((i)+16), F16((i)+32), F16((i)+48)
#define F256(i) F64((i)), F64((i)+64), F64((i)+128), F64((i)+192)
struct Foo {
static constexpr unsigned int bar(char i)
{
return i*i;
}
#define F1(i) blarg(i)
unsigned int baz[256] =
{
F256(0)
};
#undef F1
};
Now suppose I wanted the array to be associated only with the
class/struct Foo, not individual instances. If I change the array
declaration to:
static const unsigned int baz[256] =
{
F256(0)
};
I get an error that the array must be declared "constexpr" for in-class
initialization. So then if I try:
static constexpr unsigned int baz[256] =
{
F256(0)
};
Nope, can't do that either, because it complains that I'm calling a
"constexpr" within a "constexpr."
I'd really only like one copy of the array data to be associated with
the class (i.e. static) and not consume memory for every object
instantiated, as they all require the same data. And I'd like the
contents of the array to be evaluated at compile time via the first
"constexpr."
Is there a way to get at what I'm getting at?