고유 행렬 라이브러리와 함께 GMP 번호 라이브러리를 사용하려고합니다. 나는 템플릿을 인스턴스화하려고 :C++에서 static_cast를 구현하는 방법
Matrix<typename Scalar, int RowsAtCompileTime, int ColsAtCompileTime>
mpz_class는 GMP 라이브러리의 숫자 클래스입니다
Matrix<mpz_class, 3, 3> matrix;
와 함께. 문제가 mpz_class이 템플릿에서 int로 -ed static_cast 할 수 없다는 것을, 나는 아이겐 라이브러리의 소스 코드를 검사 할 때
/usr/include/eigen3/Eigen/src/Core/MathFunctions.h:409: error:
invalid static_cast from
type ‘const __gmp_expr<__mpz_struct [1], __mpz_struct [1]>’
to type ‘int’
, 내가 알아 :
나는 컴파일러 오류가 발생합니다 :
template<typename OldType, typename NewType>
struct cast_impl
{
static inline NewType run(const OldType& x)
{
return static_cast<NewType>(x);
}
};
어떻게하면이 문제를 피할 수 있습니까? 런타임시 mpz_class를 int로 변환하는 방법을 알고 있지만 static_cast는 컴파일 시간이므로 컴파일러가 수행해야합니다.
당신은 하위 클래스 인 mpz_class를 추가하고이 연산자 int()를 추가합니까? –
아, 정말 좋은 해결책이 될 것입니다. 물론'mpz_class'를 하위 클래스 화하는 것이 안전하다고 가정합니다. – Gorpik
이를 반영하여 답변을 업데이트했습니다. – Gorpik