why sizeof…(T) so slow? implement C++14 make_index_sequence without sizeof…(T)

后端 未结 1 1676
感情败类
感情败类 2021-01-06 03:51

I found implement of C++14 make_index_sequence \'algorithm\':

template< int ... > struct index_sequence{   using type = index_sequence; };

template&l         


        
1条回答
  •  北海茫月
    2021-01-06 04:28

    The compilation is slow and uses a lot of memory because you are recursively expanding templates. This is being done at compile time, it creates a large number of types, and this can use a lot of memory. It is not caused by sizeof or any other individual statement. It is the recursion that causes every bit of the template expansion to be expensive.

    I've hit this exact same problem with VC++ -- I found that my compiles would get arbitrarily slow as I passed in larger constants to a template function that I wrote.

    Of course, in my case I was trying to make the compiler run slowly. But still, maybe this will be helpful:

    https://randomascii.wordpress.com/2014/03/10/making-compiles-slow/

    0 讨论(0)
提交回复
热议问题