Cannot construct constexpr array from braced-init-list

后端 未结 2 776
说谎
说谎 2021-02-05 15:30

I\'ve implemented a constexpr array like this:

template 
class const_array {
  const T* p;
  unsigned n;
public:
  template 

        
2条回答
  •  既然无缘
    2021-02-05 15:46

    The problem was that you cannot imbue the constant nature of the pointer to T in the inner template through the outer template's T parameter.

    template  class const_array {
        const T * p;
        unsigned n;
    public:
        template 
            constexpr const_array(const T(& a)[N]): p(a), n(N) { }
    };
    
    int main(int argc, char* argv[]) {
        constexpr const_array ca{(const double []) { 1., 2. }};
        return 0;
    }
    

    I tried a few dozen permutations to get rid of the cast without success.

提交回复
热议问题