Skip to content

Commit 993aa62

Browse files
author
Andrew Ford
committed
Add move constructor and assignment operator for C++11 generated code
1 parent 49e240e commit 993aa62

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,14 @@ private static void generateGroupClassHeader(
309309
indent + " next(); func(*this);\n" +
310310
indent + " }\n" +
311311
indent + " }\n" +
312-
indent + "#endif\n\n
312+
indent + " template<class Func> inline void forEach(Func const& func)\n" +
313+
indent + " {\n" +
314+
indent + " while (hasNext())\n" +
315+
indent + " {\n" +
316+
indent + " next(); func(*this);\n" +
317+
indent + " }\n" +
318+
indent + " }\n" +
319+
indent + "#endif\n\n");
313320
}
314321

315322
private static CharSequence generateGroupProperty(
@@ -1316,7 +1323,23 @@ private static CharSequence generateConstructorsAndOperators(final String classN
13161323
" {\n" +
13171324
" reset(codec);\n" +
13181325
" return *this;\n" +
1319-
" }\n\n",
1326+
" }\n\n" +
1327+
"#if __cplusplus >= 201103L\n" +
1328+
" %1$s(%1$s&& codec) : \n" +
1329+
" {\n" +
1330+
" reset(codec);\n" +
1331+
" codec.reset(%1$s());\n" +
1332+
" }\n\n" +
1333+
" %1$s& operator =(%1$s&& codec) : \n" +
1334+
" {\n" +
1335+
" if (this != &codec)\n" +
1336+
" {\n" +
1337+
" reset(codec);\n" +
1338+
" codec.reset(%1$s());\n" +
1339+
" }\n" +
1340+
" return *this;\n" +
1341+
" }\n" +
1342+
"#endif\n\n",
13201343
className);
13211344
}
13221345

0 commit comments

Comments
 (0)