Replace hr::find_or_null with hr::at_or_null.

This commit is contained in:
Arthur O'Dwyer 2021-07-18 17:33:25 -04:00
parent 3c8a9e5274
commit d606c3183b
2 changed files with 16 additions and 16 deletions

View File

@ -848,9 +848,9 @@ template<class T> array<T, 2> make_array(T a, T b) { array<T,2> x; x[0] = a; x[1
// Find in a std::map or std::unordered_map, or return null.
template<class Map, class Key>
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 {

View File

@ -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;