diff --git a/cpp/src/aztec/common/container.hpp b/cpp/src/aztec/common/container.hpp index 6418be1461..1c87bb1224 100644 --- a/cpp/src/aztec/common/container.hpp +++ b/cpp/src/aztec/common/container.hpp @@ -48,4 +48,16 @@ InnerCont flatten(Cont const& in) result.insert(result.end(), e.begin(), e.end()); } return result; +} + +// Return the first index at which a given item can be found in the vector. +// Only safe for vectors with length less than the size_t overflow size. +template long index_of(std::vector const& vec, T const& item) +{ + auto const& begin = vec.begin(); + auto const& end = vec.end(); + + auto const& itr = std::find(begin, end, item); + + return itr == end ? -1 : std::distance(begin, itr); } \ No newline at end of file diff --git a/cpp/src/aztec/common/map.hpp b/cpp/src/aztec/common/map.hpp index a78c81ca62..79205f2bda 100644 --- a/cpp/src/aztec/common/map.hpp +++ b/cpp/src/aztec/common/map.hpp @@ -10,13 +10,29 @@ template