Explicitly use std::deque for the missing node handler stack:

We need to ensure that pointers and/or references to existing
elements will not be invalidated during the course of element
insertion and removal.

Containers like std::vector do not offer this guarantee, and
cannot be used as the underlying container for the stack.

By choosing to explicitly specify std::deque as the underlying
cotnainer, we avoid:

- the unlikely possibility of the C++ standards committee
  changing the default template parameter to a container;
- the more likely possibility of an accidental change by
  a programmer, without fully considering the consequences.
This commit is contained in:
Nikolaos D. Bougalis
2017-10-25 16:38:24 -07:00
committed by Brad Chase
parent c11e186659
commit f0e1024ad6

View File

@@ -352,7 +352,13 @@ private:
int, // while child we check first
int, // which child we check next
bool>; // whether we've found any missing children yet
std::stack <StackEntry> stack_;
// We explicitly choose to specify the use of std::deque here, because
// we need to ensure that pointers and/or references to existing elements
// will not be invalidated during the course of element insertion and
// removal. Containers that do not offer this guarantee, such as
// std::vector, can't be used here.
std::stack <StackEntry, std::deque<StackEntry>> stack_;
// nodes we may acquire from deferred reads
std::vector <std::tuple <SHAMapInnerNode*, SHAMapNodeID, int>> deferredReads_;