From d606c3183ba3a748a22e96b7adfbdbe9441ddd32 Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Sun, 18 Jul 2021 17:33:25 -0400 Subject: [PATCH] Replace hr::find_or_null with hr::at_or_null. --- hyper.h | 4 ++-- util.cpp | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/hyper.h b/hyper.h index ddac8031..63cad3d2 100644 --- a/hyper.h +++ b/hyper.h @@ -848,9 +848,9 @@ template array make_array(T a, T b) { array x; x[0] = a; x[1 // Find in a std::map or std::unordered_map, or return null. template -const typename Map::value_type *find_or_null(const Map& map, const Key& key) { +const typename Map::mapped_type *at_or_null(const Map& map, const Key& key) { auto it = map.find(key); - return (it == map.end()) ? nullptr : &*it; + return (it == map.end()) ? nullptr : &it->second; } namespace daily { diff --git a/util.cpp b/util.cpp index 9072203d..c48581d4 100644 --- a/util.cpp +++ b/util.cpp @@ -207,10 +207,10 @@ cld exp_parser::parse(int prio) { cld c = rparse(0); force_eat(")"); - if (auto *it = hr::find_or_null(extra_params, "angleunit")) { - a *= it->second; - b *= it->second; - c *= it->second; + if (auto *angleunit = hr::at_or_null(extra_params, "angleunit")) { + a *= *angleunit; + b *= *angleunit; + c *= *angleunit; } return edge_of_triangle_with_angles(real(a), real(b), real(c)); @@ -237,14 +237,14 @@ cld exp_parser::parse(int prio) { test.compute_sum(); test.compute_geometry(); res = test.edgelength; - if (auto *it = hr::find_or_null(extra_params, "distunit")) - res /= it->second; + if (auto *distunit = hr::at_or_null(extra_params, "distunit")) + res /= *distunit; } #endif else if(eat("regangle(")) { cld edgelen = parse(0); - if (auto *it = hr::find_or_null(extra_params, "distunit")) { - edgelen = edgelen * it->second; + if (auto *distunit = hr::at_or_null(extra_params, "distunit")) { + edgelen *= *distunit; } force_eat(","); @@ -260,14 +260,14 @@ cld exp_parser::parse(int prio) { if(arb::legacy) { res = M_PI - result; - if (auto *it = hr::find_or_null(extra_params, "angleofs")) - res -= it->second; + if (auto *angleofs = hr::at_or_null(extra_params, "angleofs")) + res -= *angleofs; } else res = result; - if (auto *it = hr::find_or_null(extra_params, "angleunit")) - res /= it->second; + if (auto *angleunit = hr::at_or_null(extra_params, "angleunit")) + res /= *angleunit; } else if(eat("test(")) { res = parsepar(); @@ -318,8 +318,8 @@ cld exp_parser::parse(int prio) { else if(next() == '(') at++, res = parsepar(); else { string number = next_token(); - if (auto *it = hr::find_or_null(extra_params, number)) res = it->second; - else if (auto *it = hr::find_or_null(params, number)) res = it->second->get_cld(); + if (auto *p = hr::at_or_null(extra_params, number)) res = *p; + else if (auto *p = hr::at_or_null(params, number)) res = (*p)->get_cld(); else if(number == "e") res = exp(1); else if(number == "i") res = cld(0, 1); else if(number == "p" || number == "pi") res = M_PI;