如何使以下代码编译?
#include "vector"
template<
template<class> class Container
> Container<int> f(int i) {
return Container<int>{i};
}
int main() {
return f<std::vector>(1)[0];
}
GCC-4.8.2 抱怨:
error: no matching function for call to 'f(int)'
note: template<template<class> class Container> Container<int> f(int)
实际的问题是,当代码中的唯一更改是注释时,如何允许调用者指定在函数内部使用哪个特征线性代数求解器(例如http://eigen.tuxfamily.org/dox/classEigen_1_1BiCGSTAB.html )从另一行:
Eigen::BiCGSTAB<Eigen::SparseMatrix<Scalar_T>> solver;
//Eigen::ConjugateGradient<Eigen::SparseMatrix<Scalar_T>> solver;
//Eigen::SimplicialCholesky<Eigen::SparseMatrix<Scalar_T>> solver;
目前该功能开始为:
template<
template<class> class Eigen_Solver_T,
class Scalar_T
> std::vector<Scalar_T> solve(...)
,我不希望调用者也必须给 Eigen::SparseMatrix ,或者只给
Eigen::BiCGSTAB<Eigen::SparseMatrix<Scalar_T>>
作为模板参数。