From 2d47875b44e312125b120808dcf42bc49d504216 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 9 Feb 2021 09:39:36 +1000 Subject: [PATCH] map/multi_fixed: add `erase_item` --- map/multi_fixed.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/map/multi_fixed.hpp b/map/multi_fixed.hpp index 9208fce7..1495251c 100644 --- a/map/multi_fixed.hpp +++ b/map/multi_fixed.hpp @@ -261,6 +261,23 @@ namespace cruft::map { return tally; } + void + erase_item (value_type const &kv) + { + auto [first, last] = equal_range (kv.first); + + auto const pos = std::find_if ( + first, + last, + [&kv] (auto const &candidate) { return candidate.second == kv.second; } + ); + + if (pos == last) + throw std::out_of_range ("unknown key-value"); + + erase (pos); + } + std::size_t erase (key_type const&);