adapting a non-constexpr integral value to a non-type template parameter, and code bloat

前端 未结 4 1445
梦毁少年i
梦毁少年i 2021-01-13 03:03

Consider a function object F taking a constexpr size_t argument I

struct F
{
    template 
    constex         


        
4条回答
  •  耶瑟儿~
    2021-01-13 03:25

    This is not exactly an answer and my question still stands, yet I have found a workaround that gives an impressive boost in compilation. It is a minor tweak of the solution given in the question, where parameter R is moved from operator() outside to structure idx, and the terminating condition now includes both R and N:

    template <
        typename F, size_t L,
        size_t R = 1, size_t N = 0, bool = (R < 2 * L && N < L)
    >
    struct idx //...
    

    The entire code is given in this new live example.

    This approach apparently cuts down a huge number of unnecessary specialization combinations for R. Compile times and executable sizes drop dramatically. For instance, I have been able to compile in 10.7/18.7 seconds with Clang/GCC for L = 1<<12 (4096), yielding an executable of 220/239 KB. In this case, nm -C shows 546/250 versions of operator().

提交回复
热议问题