From 50f38c21affefdd1a130604c0adb9e380ca5765c Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 17 May 2019 10:50:09 +1000 Subject: [PATCH] map/fixed: add a const index operator --- map/fixed.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/map/fixed.hpp b/map/fixed.hpp index 2e46e659..bff0803a 100644 --- a/map/fixed.hpp +++ b/map/fixed.hpp @@ -112,6 +112,17 @@ namespace cruft::map { } + //--------------------------------------------------------------------- + mapped_type const& operator[] (KeyT const &key) const + { + ComparatorT cmp {}; + for (auto &i: *this) + if (cmp (i.first, key)) + return i.second; + throw std::out_of_range ("Invalid key"); + } + + //--------------------------------------------------------------------- mapped_type& operator[] (KeyT const &key) {