오늘 행렬 클래스를 constexpr
으로 다시 작성했습니다. 나는이 클래스에 100 % 단위 테스트 커버리지를 가지고 있지만 거의 모든 함수를 constexpr로 변환 한 후 생성자의 일부가 lcov에 더 이상 적용되지 않는 것으로 표시되었음을 알았다.constexpr 생성자가 적용 범위 데이터를 표시하지 않습니다
다음은 생성자 만있는 클래스입니다.
template<typename T, std::size_t m, std::size_t n>
class Matrix
{
static_assert(std::is_arithmetic<T>::value,
"Matrix can only be declared with a type where "
"std::is_arithmetic is true.");
public:
constexpr Matrix(
std::initializer_list<std::initializer_list<T>> matrix_data)
{
if (matrix_data.size() != m)
{
throw std::invalid_argument("Invalid amount of rows.");
}
for (const auto& col : matrix_data)
{
if (col.size() != n)
{
throw std::invalid_argument("Invalid amount of columns.");
}
}
std::size_t pos_i = 0;
std::size_t pos_j = 0;
for (auto i = matrix_data.begin(); i != matrix_data.end(); ++i)
{
for (auto j = i->begin(); j != i->end(); ++j)
{
this->data[pos_i][pos_j] = *j;
++pos_j;
}
++pos_i;
pos_j = 0;
}
}
private:
std::array<std::array<T, n>, m> data{};
};
int main()
{
Matrix<double, 2, 2> mat = {
{1, 2},
{3, 4}
};
return 0;
}
나는 lcov와 GCC 7.2을 사용하고 1.13
여기에서 묻는 질문은 무엇입니까? –
@ ÖöTiib'constexpr' 코드가'gcov'가 활성화 된 상태에서 어떤 커버리지 데이터도 생성하지 않는 이유는 무엇입니까? – user0042