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)
怎么样的
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)
| 归档时间: |
|
| 查看次数: |
636 次 |
| 最近记录: |