具有未知长度的std :: array作为模板函数规范的类型

Cre*_*roD 0 c++ templates c++11 template-argument-deduction

我想传递std::array具有已知类型的类,但模板函数专门化的大小未知:

class foo {
public:
void bar<class T>(T arg1, int arg2, int arg3) {
    //For any other T
}
void bar<std::array<rs::float3, size>>(T arg1, arg2) { 
    //Specific function for type std::array of rs::float3's and unknown length (size is not a type, just variable).
}
Run Code Online (Sandbox Code Playgroud)

max*_*x66 6

怎么样的

template <typename T>
void foo (T const &)
 { std::cout << "foo generic" << std::endl; }

template <std::size_t Dim>
void foo (std::array<float, Dim> const &)
 { std::cout << "foo float array dim " << Dim << std::endl; }
Run Code Online (Sandbox Code Playgroud)

以下是一个完整的工作示例

#include <array>
#include <iostream>

template <typename T>
void foo (T const &)
 { std::cout << "foo generic" << std::endl; }

template <std::size_t Dim>
void foo (std::array<float, Dim> const &)
 { std::cout << "foo floar array dim " << Dim << std::endl; }

int main ()
 {
   foo(0);
   foo(std::array<float, 12U>{}); 
 }
Run Code Online (Sandbox Code Playgroud)