If I want to use some convenience stuff like make_array
I have no chance to declare my array first and later make the definition as done in "earlier" times because the type of my var is not available before definition.
So I found this answer:
Undefined reference to static constexpr char[]
In the following example I wrote this solution which compiles fine with gcc and I am not sure that this is really valid c++ code, because it is more or less a declaration with definition and later a definition without any content. Is this allowed? ( Compiles fine is not a guarantee that the code is valid c++ )
#include <experimental/array>
#include <iostream>
class Foo
{
private:
static decltype(auto) constexpr Bar =
std::experimental::make_array(
std::experimental::make_array( 1,2,3 ),
std::experimental::make_array( 4,5,6 )
);
public:
using ARR_TYPE = decltype( Bar );
static auto& GetArr( int idx )
{
// range check ...
return Bar[idx];
}
};
constexpr Foo::ARR_TYPE Foo::Bar;
int main()
{
for ( auto el: Foo::GetArr(0))
{
std::cout << el << std::endl;
}
}