Created
April 27, 2019 03:56
-
-
Save preshing/561dca75964f284b376b1610b11735fd to your computer and use it in GitHub Desktop.
Testing range-based for loop over explicitly created std::initializer_list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Results of a few quick tests performed in response to: | |
https://twitter.com/Steven_Pigeon/status/1121900020746338305 | |
// This is the original version that HAS the bug (garbage value encountered during iteration): | |
for (const AxisRay& faceRelVedge : std::initializer_list<AxisRay>{ | |
{{0, 0, -1}, Axis3::YNeg}, | |
{{0, 1, 0}, Axis3::ZPos}, | |
{{-2, -1, 0}, Axis3::ZPos}, | |
{{-1, -1, -1}, Axis3::XPos}}) { | |
Topology::UsedVoxelFaceTraits::Key faceKey = {nextVedgeToWorld * (faceRelVedge.pos * (QStep / 2)), nextVedgeToWorld.rot * faceRelVedge.dir}; | |
auto faceCursor = topo.usedVoxelFaces.findOrInsert(faceKey); | |
TURF_ASSERT(!faceCursor.wasFound()); | |
} | |
// This version DOES NOT HAVE the bug: | |
std::initializer_list<AxisRay> tempList{ | |
{{0, 0, -1}, Axis3::YNeg}, | |
{{0, 1, 0}, Axis3::ZPos}, | |
{{-2, -1, 0}, Axis3::ZPos}, | |
{{-1, -1, -1}, Axis3::XPos}}; | |
for (const AxisRay& faceRelVedge : tempList) { | |
Topology::UsedVoxelFaceTraits::Key faceKey = {nextVedgeToWorld * (faceRelVedge.pos * (QStep / 2)), nextVedgeToWorld.rot * faceRelVedge.dir}; | |
auto faceCursor = topo.usedVoxelFaces.findOrInsert(faceKey); | |
TURF_ASSERT(!faceCursor.wasFound()); | |
} | |
// This version DOES NOT HAVE the bug: | |
auto tempList = std::initializer_list<AxisRay>{ | |
{{0, 0, -1}, Axis3::YNeg}, | |
{{0, 1, 0}, Axis3::ZPos}, | |
{{-2, -1, 0}, Axis3::ZPos}, | |
{{-1, -1, -1}, Axis3::XPos}}; | |
for (const AxisRay& faceRelVedge : tempList) { | |
Topology::UsedVoxelFaceTraits::Key faceKey = {nextVedgeToWorld * (faceRelVedge.pos * (QStep / 2)), nextVedgeToWorld.rot * faceRelVedge.dir}; | |
auto faceCursor = topo.usedVoxelFaces.findOrInsert(faceKey); | |
TURF_ASSERT(!faceCursor.wasFound()); | |
} | |
// This version HAS the bug (garbage value again encountered during iteration): | |
auto&& tempList = std::initializer_list<AxisRay>{ | |
{{0, 0, -1}, Axis3::YNeg}, | |
{{0, 1, 0}, Axis3::ZPos}, | |
{{-2, -1, 0}, Axis3::ZPos}, | |
{{-1, -1, -1}, Axis3::XPos}}; | |
for (const AxisRay& faceRelVedge : tempList) { | |
Topology::UsedVoxelFaceTraits::Key faceKey = {nextVedgeToWorld * (faceRelVedge.pos * (QStep / 2)), nextVedgeToWorld.rot * faceRelVedge.dir}; | |
auto faceCursor = topo.usedVoxelFaces.findOrInsert(faceKey); | |
TURF_ASSERT(!faceCursor.wasFound()); | |
} | |
// This version HAS the bug (garbage value again encountered during iteration): | |
const auto& tempList = std::initializer_list<AxisRay>{ | |
{{0, 0, -1}, Axis3::YNeg}, | |
{{0, 1, 0}, Axis3::ZPos}, | |
{{-2, -1, 0}, Axis3::ZPos}, | |
{{-1, -1, -1}, Axis3::XPos}}; | |
for (const AxisRay& faceRelVedge : tempList) { | |
Topology::UsedVoxelFaceTraits::Key faceKey = {nextVedgeToWorld * (faceRelVedge.pos * (QStep / 2)), nextVedgeToWorld.rot * faceRelVedge.dir}; | |
auto faceCursor = topo.usedVoxelFaces.findOrInsert(faceKey); | |
TURF_ASSERT(!faceCursor.wasFound()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment