[C++] Add mutable version of LookupByKey and test (#6826)

* [C++] Add mutable version of LookupByKey and test

This adds an overload of LookupByKey to allow lookup in sorted Vectors to
return a mutable instance of the object (or nullptr if not found).

* Fix naming
This commit is contained in:
Tyler Denniston
2021-08-31 17:17:20 -04:00
committed by GitHub
parent db6eae5c42
commit 74c3d7eba2
2 changed files with 13 additions and 0 deletions

View File

@@ -376,6 +376,10 @@ template<typename T> class Vector {
return IndirectHelper<T>::Read(element, 0);
}
template<typename K> mutable_return_type MutableLookupByKey(K key) {
return const_cast<mutable_return_type>(LookupByKey(key));
}
protected:
// This class is only used to access pre-existing data. Don't ever
// try to construct these manually.