Skip to content

Commit 57dd44d

Browse files
committed
[C++] Use universal ref in forEach and set min to C++11. Issue #903.
1 parent 6afe100 commit 57dd44d

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

sbe-tool/src/main/java/uk/co/real_logic/sbe/generation/cpp/CppGenerator.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -378,27 +378,14 @@ private static void generateGroupClassHeader(
378378
.append(indent).append(" }\n");
379379

380380
sb.append("\n")
381-
.append(indent).append("#if __cplusplus < 201103L\n")
382-
.append(indent).append(" template<class Func> inline void forEach(Func &func)\n")
383-
.append(indent).append(" {\n")
384-
.append(indent).append(" while (hasNext())\n")
385-
.append(indent).append(" {\n")
386-
.append(indent).append(" next();\n")
387-
.append(indent).append(" func(*this);\n")
388-
.append(indent).append(" }\n")
389-
.append(indent).append(" }\n\n")
390-
391-
.append(indent).append("#else\n")
392381
.append(indent).append(" template<class Func> inline void forEach(Func &&func)\n")
393382
.append(indent).append(" {\n")
394383
.append(indent).append(" while (hasNext())\n")
395384
.append(indent).append(" {\n")
396385
.append(indent).append(" next();\n")
397386
.append(indent).append(" func(*this);\n")
398387
.append(indent).append(" }\n")
399-
.append(indent).append(" }\n\n")
400-
401-
.append(indent).append("#endif\n");
388+
.append(indent).append(" }\n\n");
402389
}
403390

404391
private static void generateGroupProperty(
@@ -2655,20 +2642,19 @@ private CharSequence appendDisplay(
26552642
new Formatter(sb).format(
26562643
indent + "{\n" +
26572644
indent + " bool atLeastOne = false;\n" +
2658-
indent + " builder << R\"(\"%3$s\": [)\";\n" +
2659-
indent + " writer.%2$s().forEach(\n" +
2660-
indent + " [&](%1$s &%2$s)\n" +
2645+
indent + " builder << R\"(\"%2$s\": [)\";\n" +
2646+
indent + " writer.%1$s().forEach(\n" +
2647+
indent + " [&](auto &&%1$s)\n" +
26612648
indent + " {\n" +
26622649
indent + " if (atLeastOne)\n" +
26632650
indent + " {\n" +
26642651
indent + " builder << \", \";\n" +
26652652
indent + " }\n" +
26662653
indent + " atLeastOne = true;\n" +
2667-
indent + " builder << %2$s;\n" +
2654+
indent + " builder << %1$s;\n" +
26682655
indent + " });\n" +
26692656
indent + " builder << ']';\n" +
26702657
indent + "}\n\n",
2671-
formatClassName(groupToken.name()),
26722658
formatPropertyName(groupToken.name()),
26732659
groupToken.name());
26742660

@@ -3122,8 +3108,7 @@ private CharSequence generateMessageLength(final List<Token> groups, final List<
31223108
}
31233109

31243110
new Formatter(sbSkip).format(
3125-
indent + " %2$s().forEach([](%1$s &e){ e.skip(); });\n",
3126-
formatClassName(groupToken.name()),
3111+
indent + " %1$s().forEach([](auto &&e){ e.skip(); });\n",
31273112
formatPropertyName(groupToken.name()));
31283113

31293114
i = endSignal;

sbe-tool/src/test/cpp/Issue835Test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,15 @@ TEST_F(Issue835Test, shouldCompileWithSkipper)
6969
BUFFER_LEN);
7070

7171
EXPECT_EQ(decoder.decodeLength(), encoder.encodedLength());
72+
73+
MDIncrementalRefreshOrderBook47 decoder2;
74+
decoder2.wrapForDecode(
75+
buffer,
76+
offset,
77+
MDIncrementalRefreshOrderBook47::sbeBlockLength(),
78+
MDIncrementalRefreshOrderBook47::sbeSchemaVersion(),
79+
BUFFER_LEN);
80+
81+
decoder2.skip();
82+
EXPECT_EQ(decoder2.encodedLength(), encoder.encodedLength());
7283
}

0 commit comments

Comments
 (0)