On 05/13/14 11:23, Javier Dehesa wrote:> I was testing for_each and range_c and I've discovered that there's a
hard limit in the range_c template.
I'm attaching an example (copied from the for_each docs
http://www.boost.org/doc/libs/1_55_0/libs/mpl/doc/refmanual/for-each.html)
to illustrate it. This program compiles fine for me (g++ 4.9.0), but if I set NUM to a number over 890, the compilation fails. I receive an error about template instantiation depth, so I guess I could tune it in the compiler to make it work. But, anyway, why is this template recursively defined? Is it on purpose?
On purpose: http://www.boost.org/doc/libs/1_31_0/libs/mpl/doc/paper/mpl_paper.html The reason for only using recursion is that an imperative like loop: std::vector<int> int_list; for(unsigned i=0; i<890; ++i) int_list.push_back(i); the value of i and int_list are modified during each iteration of the loop. TMP is a pure *functional* language, meaning there is no changing of the value of a variable. Once it's calculated, the value cannot be changed. HTH. -regards, Larry