Skip to content

Commit 4017df6

Browse files
authored
Merge pull request aeron-io#503 from skizzay/c++11-fixes
Remove inefficiencies created by introducing specific C++11
2 parents c523039 + 523ebeb commit 4017df6

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

sbe-benchmarks/src/main/cpp/SbeCarCodecBench.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ class SbeCarCodecBench : public CodecBench<SbeCarCodecBench>
8383
{
8484
car.wrapForDecode((char *)buffer, 0, Car::sbeBlockLength(), Car::sbeSchemaVersion(), bufferLength);
8585

86+
#pragma GCC diagnostic push
87+
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
8688
int64_t tmpInt;
8789
const char *tmpChar;
8890
double tmpDouble;
@@ -132,6 +134,7 @@ class SbeCarCodecBench : public CodecBench<SbeCarCodecBench>
132134

133135
tmpChar = car.manufacturer();
134136
tmpChar = car.model();
137+
#pragma GCC diagnostic pop
135138

136139
return car.encodedLength();
137140
};

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

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

296296
sb.append(
297-
indent + "#if __cplusplus < 201103L\n" +
298297
indent + " template<class Func> inline void forEach(Func& func)\n" +
299298
indent + " {\n" +
300299
indent + " while (hasNext())\n" +
301300
indent + " {\n" +
302301
indent + " next(); func(*this);\n" +
303302
indent + " }\n" +
304-
indent + " }\n\n" +
305-
indent + "#else\n" +
303+
indent + " }\n" +
304+
indent + "#if __cplusplus >= 201103L\n" +
306305
indent + " template<class Func> inline void forEach(Func&& func)\n" +
307306
indent + " {\n" +
308307
indent + " while (hasNext())\n" +
309308
indent + " {\n" +
310309
indent + " next(); func(*this);\n" +
311310
indent + " }\n" +
312-
indent + " }\n\n" +
311+
indent + " }\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" +
313319
indent + "#endif\n\n");
314320
}
315321

@@ -1285,17 +1291,21 @@ private static CharSequence generateFixedFlyweightCode(final String className, f
12851291
" m_offset(codec.m_offset),\n" +
12861292
" m_actingVersion(codec.m_actingVersion){}\n\n" +
12871293
"#if __cplusplus >= 201103L\n" +
1288-
" %1$s(%1$s&& codec) :\n" +
1294+
" %1$s(%1$s&& codec) SBE_NOEXCEPT :\n" +
12891295
" m_buffer(codec.m_buffer),\n" +
12901296
" m_bufferLength(codec.m_bufferLength),\n" +
12911297
" m_offset(codec.m_offset),\n" +
1292-
" m_actingVersion(codec.m_actingVersion){}\n\n" +
1298+
" m_actingVersion(codec.m_actingVersion)\n" +
1299+
" {\n" +
1300+
" codec.reset(%1$s())\n" +
1301+
" }\n\n" +
12931302
" %1$s& operator=(%1$s&& codec) SBE_NOEXCEPT\n" +
12941303
" {\n" +
1295-
" m_buffer = codec.m_buffer;\n" +
1296-
" m_bufferLength = codec.m_bufferLength;\n" +
1297-
" m_offset = codec.m_offset;\n" +
1298-
" m_actingVersion = codec.m_actingVersion;\n" +
1304+
" if (this != &codec);\n" +
1305+
" {\n" +
1306+
" reset(codec);\n" +
1307+
" codec.reset(%1$s());\n" +
1308+
" }\n" +
12991309
" return *this;\n" +
13001310
" }\n\n" +
13011311
"#endif\n\n" +
@@ -1350,22 +1360,27 @@ private static CharSequence generateConstructorsAndOperators(final String classN
13501360
" {\n" +
13511361
" reset(codec);\n" +
13521362
" }\n\n" +
1353-
"#if __cplusplus >= 201103L\n" +
1354-
" %1$s(%1$s&& codec)\n" +
1363+
" %1$s& operator=(const %1$s& codec) SBE_NOEXCEPT\n" +
13551364
" {\n" +
13561365
" reset(codec);\n" +
1366+
" return *this;\n" +
13571367
" }\n\n" +
1358-
" %1$s& operator=(%1$s&& codec)\n" +
1368+
"#if __cplusplus >= 201103L\n" +
1369+
" %1$s(%1$s&& codec) SBE_NOEXCEPT : \n" +
13591370
" {\n" +
13601371
" reset(codec);\n" +
1361-
" return *this;\n" +
1372+
" codec.reset(%1$s());\n" +
13621373
" }\n\n" +
1363-
"#endif\n\n" +
1364-
" %1$s& operator=(const %1$s& codec)\n" +
1374+
" %1$s& operator =(%1$s&& codec) SBE_NOEXCEPT : \n" +
13651375
" {\n" +
1366-
" reset(codec);\n" +
1376+
" if (this != &codec)\n" +
1377+
" {\n" +
1378+
" reset(codec);\n" +
1379+
" codec.reset(%1$s());\n" +
1380+
" }\n" +
13671381
" return *this;\n" +
1368-
" }\n\n",
1382+
" }\n" +
1383+
"#endif\n\n",
13691384
className);
13701385
}
13711386

0 commit comments

Comments
 (0)