Let's say I have a type that is neither movable nor copied:
struct foo { explicit foo( size_t ){} ~foo(){} foo( foo const & ) = delete; foo( foo && ) = delete; foo& operator=( foo const & ) = delete; foo& operator=( foo & ) = delete; };
Now, given the number known at compile time (call it N), is there a way I can create a βsequenceβ of them on the stack, each of which is initialized with numbers from 0 to N-1? I would be pleased with the C-style array foo[N] , a std::array< foo, N > or maybe even std::tuple .
I am trying to avoid:
foo f0( 0 ), f1( 1 ), ... fNminus1( N-1 );
when it seems like this is what the compiler should do for me. The best I could come up with was to use boost::optional .
boost::optional< foo > f[N]; for( size_t i = 0U; i < N; ++i ) f[i] = boost::in_place( i );
But it depends on the execution logic, although all the necessary information is available at compile time. Also, I was left with something that behaves like an array of pointers.
c ++ constructor compile-time
Andrew Durward
source share