diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-09-05 02:45:49 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-12-17 15:36:04 +0000 |
commit | 38fce0ed44faf5757e195e4025b7bf22b6331aa2 (patch) | |
tree | 39acc1cae0136cfe6c32f3f8121b7084bbcc59de /icespider/core/flatMap.h | |
parent | Add contains to flatmap (diff) | |
download | icespider-38fce0ed44faf5757e195e4025b7bf22b6331aa2.tar.bz2 icespider-38fce0ed44faf5757e195e4025b7bf22b6331aa2.tar.xz icespider-38fce0ed44faf5757e195e4025b7bf22b6331aa2.zip |
Add at to flatmap
Diffstat (limited to 'icespider/core/flatMap.h')
-rw-r--r-- | icespider/core/flatMap.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/icespider/core/flatMap.h b/icespider/core/flatMap.h index e23bd46..db07473 100644 --- a/icespider/core/flatMap.h +++ b/icespider/core/flatMap.h @@ -67,6 +67,21 @@ namespace IceSpider { return lb; } + template<typename Ex = std::out_of_range, typename N> + const auto & + at(const N & n) const + { + if (const auto i = find(n); i != end()) { + return i->second; + } + if constexpr (std::is_constructible_v<Ex, N>) { + throw Ex(n); + } + else { + throw Ex(std::to_string(n)); + } + } + using S::begin; using S::empty; using S::end; |