Skip to content

Commit ac87bd6

Browse files
committed
Fix C++98 incompatibility
1 parent 7ccfa1f commit ac87bd6

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

tests/testgecko.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1+
#include <cstdio>
12
#include <cstdlib>
23
#include <iomanip>
34
#include <iostream>
5+
#include <sstream>
46
#include <string>
57
#include "gecko.h"
68
#include "gecko/graph.h"
79

810
using namespace Gecko;
911

12+
template <typename T>
13+
static std::string
14+
stringize(T val)
15+
{
16+
std::ostringstream s;
17+
s << val;
18+
return s.str();
19+
}
20+
1021
// print library version info
1122
static bool
1223
init()
@@ -66,7 +77,7 @@ path_test(
6677
Node::Index i = graph.permutation(rank + 0);
6778
Node::Index j = graph.permutation(rank + 1);
6879
if (!graph.arc_index(i, j))
69-
return std::string("{") + std::to_string(i) + std::string(", ") + std::to_string(j) + std::string("} is not an edge");
80+
return std::string("{") + stringize(i) + std::string(", ") + stringize(j) + std::string("} is not an edge");
7081
}
7182

7283
return std::string();
@@ -111,7 +122,7 @@ hypercube_test(
111122
Node::Index i = graph.permutation(rank + 0);
112123
Node::Index j = graph.permutation(rank + 1);
113124
if (!graph.arc_index(i, j))
114-
return std::string("{") + std::to_string(i) + std::string(", ") + std::to_string(j) + std::string("} is not an edge");
125+
return std::string("{") + stringize(i) + std::string(", ") + stringize(j) + std::string("} is not an edge");
115126
}
116127

117128
return std::string();
@@ -170,7 +181,7 @@ grid_test(
170181
if (cost <= Float(1 + epsilon) * mincost)
171182
return std::string();
172183
else
173-
return std::to_string(cost) + " > " + std::to_string(mincost);
184+
return stringize(cost) + " > " + stringize(mincost);
174185
}
175186

176187
// report the result of a test and return 1 if it failed
@@ -224,14 +235,14 @@ int main(int argc, char* argv[])
224235
// order hypercubes
225236
for (uint dims = 1; dims <= maxdims; dims++) {
226237
std::string error = hypercube_test(dims);
227-
failures += report(std::string("hypercube test #") + std::to_string(dims), error);
238+
failures += report(std::string("hypercube test #") + stringize(dims), error);
228239
tests++;
229240
}
230241

231242
// order grids
232243
for (uint size = 1; size <= maxsize; size++) {
233244
std::string error = grid_test(size);
234-
failures += report(std::string("grid test #") + std::to_string(size), error);
245+
failures += report(std::string("grid test #") + stringize(size), error);
235246
tests++;
236247
}
237248

0 commit comments

Comments
 (0)