Skip to content

Commit 49e240e

Browse files
author
Andrew Ford
committed
Add rvalue-reference handling of forEach
1 parent f4302a8 commit 49e240e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,22 @@ private static void generateGroupClassHeader(
294294
dimensionHeaderLength, blockLength, formatClassName(groupName)));
295295

296296
sb.append(
297-
indent + " template<class Func> inline void forEach(Func func)\n" +
297+
indent + " template<class Func> inline void forEach(Func& func)\n" +
298298
indent + " {\n" +
299299
indent + " while (hasNext())\n" +
300300
indent + " {\n" +
301301
indent + " next(); func(*this);\n" +
302302
indent + " }\n" +
303-
indent + " }\n\n");
303+
indent + " }\n" +
304+
indent + "#if __cplusplus >= 201103L\n" +
305+
indent + " template<class Func> inline void forEach(Func&& func)\n" +
306+
indent + " {\n" +
307+
indent + " while (hasNext())\n" +
308+
indent + " {\n" +
309+
indent + " next(); func(*this);\n" +
310+
indent + " }\n" +
311+
indent + " }\n" +
312+
indent + "#endif\n\n
304313
}
305314
306315
private static CharSequence generateGroupProperty(

0 commit comments

Comments
 (0)