because neither the function nor my member variable are static.
Right The problem is that static assert cannot refer to a non-static member, because some_array.size() equivalent to this->some_array.size() , and there is no this pointer in the class scope (only inside function declarators and element initializers by default) .
However, it is okay to say decltype(array_size) , because in fact it is not trying to reference the array_size object or call its member functions, it just asks for the type of name declared in the class.
It looks like it creates a rvalue value by default, which I thought was not constexpr.
array<int, N> is a literal type, so it can be built in constant expressions. The fact that you are building an rvalue does not matter, you can build a literal and call the constexpr function on it in a constant expression.
It is impossible to use something like array<std::string, N> because std::string not a literal type and therefore is not array<string, N> .
Is there a cleaner way to achieve a static statement?
The standard flag std::tuple_size specialized for std::array so you can:
static_assert( std::tuple_size<decltype(some_array)>::value % 256) == 0, "Size must be multiple of 256" );
source share