c++11 - static constexpr template array member recursively required by itself -
i want static constexpr
array of class-elements inside templated class similar following code:
struct element { unsigned i; constexpr element (unsigned i) : i(i) { } }; template <bool reverse> struct template { static constexpr element element[] = { element (reverse ? 1 : 0), element (reverse ? 0 : 1), }; }; int main (int argc, char **argv) { return template<true>::element[0].i; }
of course, actual element
structure more complex in example, shows problem. if compile wit gcc
error recursive dependency:
test.cc: in instantiation of ‘constexpr element template<true>::element [2]’: test.cc:11:27: recursively required ‘constexpr element template<true>::element [2]’ test.cc:11:27: required ‘constexpr element template<true>::element [2]’ test.cc:20:2: required here test.cc:11:27: fatal error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= increase maximum) static constexpr element element[] = { ^ compilation terminated.
first of curious how circumvent error glade if hint cause of or why such construct should not valid...
you need specify size of element array. element element[]
isn't valid c++.
template <bool reverse> struct template { static constexpr element element[2] = { element (reverse ? 1 : 0), element (reverse ? 0 : 1), }; };
Comments
Post a Comment