'C++17: std::is_same_v fails unexpectedly
Can someone explain to me, why this code fails to compile
friend
std::ostream& operator<<(std::ostream& os, const Matrix<T> &matrix) {
os << matrix.rows();
os << "x";
os << matrix.cols();
os << std::endl;
for (int i = 0; i < matrix.M * matrix.N; ++i) {
float value;
if constexpr (std::is_same_v<T, half>) {
value = __half2float(matrix.dataOnCPU[i]);
} else {
value = matrix.dataOnCPU[i];
}
if ( (i + 1) % matrix.N == 0 ) {
os << value;
os << std::endl;
} else {
os << value << ",";
}
}
return os;
}
with internal error: assertion failed at: "statements.c", line 4170 in if_statement
but this code compiles fine
friend
std::ostream& operator<<(std::ostream& os, const Matrix<T> &matrix) {
for (int i = 0; i < matrix.M * matrix.N; ++i) {
float value;
if constexpr (std::is_same_v<T, half>) {
value = __half2float(matrix.dataOnCPU[i]);
} else {
value = matrix.dataOnCPU[i];
}
if ( (i + 1) % matrix.N == 0 ) {
os << value;
os << std::endl;
} else {
os << value << ",";
}
}
return os;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
