ArrowProxy vs existing (PairView-based) implementation:
Pros:
No API discrepancy
Cons:
Does not return an l-value reference, but a value. This means:
1) Need to suppress -Wrange-loop-bind-reference globally because they trigger on common loops (in contrast to std::map):
for (const auto& key_and_value : s) { }
for (const auto& [key, value] : s) { }
2) These non-cost & don't work at all (in contrast to std::map):
// error: non-const lvalue reference to type 'pair<...>' cannot bind to a temporary of type
// 'pair<...>'
for (auto& key_and_value : s) { }
// error: non-const lvalue reference to type 'pair<...>' cannot bind to a temporary of type
// 'pair<...>'
for (auto& [key, value] : s) { }
3) range-v3 has issues (but not std::ranges, std::map works with either):
int first_entry = (*f.begin()).second; // Can't use arrow with range-v3 because it requires
// l-value. Note that std::ranges works
ArrowProxy
vs existing (PairView-based) implementation:Pros:
Cons:
Does not return an l-value reference, but a value. This means: 1) Need to suppress
-Wrange-loop-bind-reference
globally because they trigger on common loops (in contrast tostd::map
):Relevant: https://quuxplusone.github.io/blog/2020/08/26/wrange-loop-analysis/ https://quuxplusone.github.io/blog/2018/12/15/autorefref-always-works/
flat_map
work the same way: https://godbolt.org/z/r187d7zn72) These
non-cost &
don't work at all (in contrast tostd::map
):3) range-v3 has issues (but not std::ranges,
std::map
works with either):All of the above is demo'ed in the unit tests.
Other option that returns l-value was explored: https://github.com/teslamotors/fixed-containers/pull/38 Comparison of the l-value approach with
ArrowProxy
https://github.com/teslamotors/fixed-containers/pull/39