teslamotors / fixed-containers

C++ Fixed Containers
MIT License
395 stars 38 forks source link

[FixedMap/EnumMap] PairView -> std::pair #48

Closed alexkaratarakis closed 1 year ago

alexkaratarakis commented 1 year ago

Now that the iterators return a value (instead of a reference) of references, there is no reason to have the first()/second() API discrepancy when compared to std::map.

Replace PairView<const K, V> with std::pair<const K&, V&>.

One downside vs PairView is that iterating via const auto& no longer propagates const to the value, i.e.:

for (const auto& [key, value] : non_const_map)
{
   // Can mutate value in here
}

because the const applies to the pointer, not the pointee.


Change from PairView& to PairView occurred in an earlier PR: https://github.com/teslamotors/fixed-containers/pull/45

Discussions and other attempts: https://github.com/teslamotors/fixed-containers/pull/38 https://github.com/teslamotors/fixed-containers/pull/39 https://github.com/teslamotors/fixed-containers/pull/40