コンパイラ エラーが発生する
/Developer/boost/boost/numeric/ublas/expression_types.hpp:184:16: fatal error: recursive template instantiation exceeded maximum depth of 512
clang++ から、または g++ 4.2.1 からの 10GB を超えるメモリ使用量での無期限コンパイルから。
ベクトルの各要素からスカラーを減算するヘルパー関数を作成しようとしています。最初は一般的に考えて、特定のベクター ストレージ型をテンプレート パラメーターにすることを計画しました。そうは言っても、この時点で (特殊化せずに)ublas
とベクトルの両方で定義を機能させる方法がわからないことに気付きました。std
しかし、私はまだ何が起こっているのか疑問に思っています/私のコンパイルの問題の理由は?
この問題は、boost ライブラリに準拠している場合、以下のコードで簡単に示されます。
g++ -I/path/boost bug_demo.cpp
ブーストまたはコードにバグはありますか?
// demo code does not compiler, instead error for recursive template instantiation
//---------------------------------------------------------
#include <boost/numeric/ublas/vector.hpp>
namespace ublas = boost::numeric::ublas; // boost ublas will be the implementation for basic vector container
typedef ublas::vector<double> DVEC; // double vector shorthand
// ********* problem function ***********
template <typename vec_t, typename scalar_t>
vec_t operator-( const vec_t & vec, scalar_t scalar )
{
ublas::scalar_vector<scalar_t> scalar_v(vec.size(), scalar);
return vec - scalar_v;
}
// this non-template version works fine.
/* DVEC operator-( const DVEC & vec, double scalar )
{
ublas::scalar_vector<double> scalar_v(vec.size(), scalar);
return vec - scalar_v;
}
*/
DVEC vectorFunc( const DVEC& x )
{
double bnew=0.0;
DVEC x_bnew;
x_bnew = operator-(x,bnew);
return x_bnew;
}
int main()
{
DVEC inputVector(2);
inputVector[0] = 1.0; inputVector[1] = 2.0;
DVEC output = vectorFunc( inputVector );
return 0;
}