forked from boostorg/unordered
documented [c]visit_(until|while)
This commit is contained in:
@@ -154,7 +154,34 @@ m.visit_all(std::execution::par, [](auto& x) { // run in parallel
|
||||
});
|
||||
----
|
||||
|
||||
There is another whole-table visitation operation, `erase_if`:
|
||||
Traversal can be interrupted midway:
|
||||
|
||||
[source,c++]
|
||||
----
|
||||
// finds the key to a given (unique value)
|
||||
|
||||
int key = 0;
|
||||
int value = ...;
|
||||
bool found = m.visit_until([&](const auto& x) {
|
||||
if(x.second == value) {
|
||||
key = x.first;
|
||||
return true; // finish
|
||||
}
|
||||
else {
|
||||
return false; // keep on visiting
|
||||
}
|
||||
});
|
||||
|
||||
if(found) { ... }
|
||||
|
||||
// check if all values are != 0
|
||||
|
||||
bool all_ok = m.visit_while([&](const auto& x) {
|
||||
return x.second != 0;
|
||||
});
|
||||
----
|
||||
|
||||
There is one last whole-table visitation operation, `erase_if`:
|
||||
|
||||
[source,c++]
|
||||
----
|
||||
@@ -163,8 +190,8 @@ m.erase_if([](auto& x) {
|
||||
});
|
||||
----
|
||||
|
||||
`erase_if` can also be parallelized. Note that, in order to increase efficiency,
|
||||
these operations do not block the table during execution: this implies that elements
|
||||
`visit_until`, `visit_while` and `erase_if` can also be parallelized. Note that, in order to increase efficiency,
|
||||
whole-table visitation operations do not block the table during execution: this implies that elements
|
||||
may be inserted, modified or erased by other threads during visitation. It is
|
||||
advisable not to assume too much about the exact global state of a `boost::concurrent_flat_map`
|
||||
at any point in your program.
|
||||
|
||||
Reference in New Issue
Block a user