Zero-length C-array binds to pointer type

前端 未结 6 1206
误落风尘
误落风尘 2020-12-17 20:10

I recently wrote a function template which takes a reference to a C-array:

template 
void foo(T(&c_array)[N]);

6条回答
  •  不思量自难忘°
    2020-12-17 21:16

    Zero-length arrays do not exist in C++. However if they did, here is how you could handle the case:

    template 
    struct disable_if;
    
    template 
    struct disable_if
    {
        typedef T type;
    };
    
    template 
    typename disable_if::type foo(T(&c_array)[N])
    {
        std::cout << "inside template\n";
    }
    

提交回复
热议问题