나는 언젠가 제네릭 클래스와 함수 선언 및 Boost 라이브러리를 직접 가르치려고합니다. 예를 발견했는데 실제로 의미가 무엇인지 이해하지 못했습니다. typename f=...
. =
기호로 템플릿 선언을 사용하는 개념을 이해하는 데 도움을 주시겠습니까? template <typename T, typename F=ublas::row_major>
? 여기 제가 이해하려고하는 전체 프로그램이 있습니다.C++ 템플릿 정의와 함께 제공되는 것은 무엇을 의미합니까?
#include <algorithm>
#include <vector>
#include <boost/numeric/ublas/storage.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
namespace ublas = boost::numeric::ublas;
template <typename T, typename F=ublas::row_major>
ublas::matrix<T, F> makeMatrix(std::size_t m, std::size_t n, const std::vector<T> & v)
{
if(m*n!=v.size()) {
; // Handle this case
}
ublas::unbounded_array<T> storage(m*n);
std::copy(v.begin(), v.end(), storage.begin());
return ublas::matrix<T>(m, n, storage);
}
'F = ublas :: row_major' 기본 템플릿 인수에 대한
– Niall