Skip to content

Commit 005527a

Browse files
committed
fix(c2c_ir): add static_assert to constrain template type parameters
1 parent dd2a4ff commit 005527a

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

flagcx/runner/include/c2c_ir.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <list>
1212
#include <map>
1313
#include <string>
14+
#include <type_traits>
1415
#include <unordered_map>
1516

1617
// Max line length for reading xml
@@ -132,6 +133,10 @@ template <typename T>
132133
void serializeFunc2DVector(FILE *file, size_t chunksize,
133134
const std::vector<std::vector<T>> &steps,
134135
const char *tagName, int indent = 2) {
136+
static_assert(std::is_same<T, flagcxC2cHomoFunc>::value ||
137+
std::is_same<T, flagcxC2cHeteroFunc>::value,
138+
"serializeFunc2DVector only supports flagcxC2cHomoFunc or "
139+
"flagcxC2cHeteroFunc");
135140
fprintf(file, "%*s<%s>\n", indent, "", tagName);
136141
for (const auto &stepVec : steps) {
137142
if (stepVec.size() == 0) {
@@ -164,6 +169,10 @@ inline void readFuncStep(FILE *file, size_t chunksize, const char *line,
164169
template <typename T>
165170
std::vector<std::vector<T>> readFunc2DVector(FILE *file, size_t chunksize,
166171
const char *tagName) {
172+
static_assert(std::is_same<T, flagcxC2cHomoFunc>::value ||
173+
std::is_same<T, flagcxC2cHeteroFunc>::value,
174+
"readFunc2DVector only supports flagcxC2cHomoFunc or "
175+
"flagcxC2cHeteroFunc");
167176
std::vector<std::vector<T>> result;
168177
char line[LINE_LEN];
169178

0 commit comments

Comments
 (0)