Invalid explicitly-specified argument for template parameter which is constexpr

后端 未结 2 1112
生来不讨喜
生来不讨喜 2021-01-23 08:08

I have a static_loop construct like this

template  void static_loop(F&& f) {
    static_assert(n <= 8 &a         


        
2条回答
  •  旧时难觅i
    2021-01-23 08:41

    Change

    template 
    constexpr size_t tupleSize(T) { return tuple_size_v; }
    

    to:

    template 
    constexpr size_t tupleSize(T const&) { return tuple_size_v; }
    

    That is, take the argument by reference to const, not by value. As-is, you're trying to copy a non-constexpr tuple in a constant expression - that can't work. By reference is fine since you're not actually reading the tuple.

提交回复
热议问题