use auto instead of iterators
This commit is contained in:
parent
c35d00e155
commit
59c5eed635
10
ml.cpp
10
ml.cpp
|
|
@ -643,7 +643,7 @@ const char * MlError::what() const noexcept {
|
||||||
void MlEnvironment::combine(MlEnvironment const &other) {
|
void MlEnvironment::combine(MlEnvironment const &other) {
|
||||||
// Normally, I would use the `insert` method of the `map` class,
|
// Normally, I would use the `insert` method of the `map` class,
|
||||||
// but it doesn't overwrite previously declared values for keys.
|
// but it doesn't overwrite previously declared values for keys.
|
||||||
std::map<std::string, MlValue>::const_iterator itr = other.defs.begin();
|
auto itr = other.defs.begin();
|
||||||
for (; itr != other.defs.end(); itr++) {
|
for (; itr != other.defs.end(); itr++) {
|
||||||
// Iterate through the keys and assign each value.
|
// Iterate through the keys and assign each value.
|
||||||
defs[itr->first] = itr->second;
|
defs[itr->first] = itr->second;
|
||||||
|
|
@ -651,7 +651,7 @@ void MlEnvironment::combine(MlEnvironment const &other) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream &operator<<(std::ostream &os, MlEnvironment const &e) {
|
std::ostream &operator<<(std::ostream &os, MlEnvironment const &e) {
|
||||||
std::map<std::string, MlValue>::const_iterator itr = e.defs.begin();
|
auto itr = e.defs.begin();
|
||||||
os << "{ ";
|
os << "{ ";
|
||||||
for (; itr != e.defs.end(); itr++) {
|
for (; itr != e.defs.end(); itr++) {
|
||||||
os << '\'' << itr->first << "' : " << itr->second.debug() << ", ";
|
os << '\'' << itr->first << "' : " << itr->second.debug() << ", ";
|
||||||
|
|
@ -667,7 +667,7 @@ void MlEnvironment::set(const std::string &name, MlValue value) {
|
||||||
void MlEnvironment::setX(const std::string &name, MlValue value) {
|
void MlEnvironment::setX(const std::string &name, MlValue value) {
|
||||||
MlEnvironment *e = this;
|
MlEnvironment *e = this;
|
||||||
while (e != nullptr) {
|
while (e != nullptr) {
|
||||||
std::map<std::string, MlValue>::const_iterator itr = e->defs.find(name);
|
auto itr = e->defs.find(name);
|
||||||
if (itr != e->defs.end()) {
|
if (itr != e->defs.end()) {
|
||||||
e->set(name, value);
|
e->set(name, value);
|
||||||
return;
|
return;
|
||||||
|
|
@ -2063,7 +2063,7 @@ void load_std_lib(MlEnvironment &env) {
|
||||||
|
|
||||||
// Does this environment, or its parent environment, have a variable?
|
// Does this environment, or its parent environment, have a variable?
|
||||||
bool MlEnvironment::has(const std::string &name) const {
|
bool MlEnvironment::has(const std::string &name) const {
|
||||||
std::map<std::string, MlValue>::const_iterator itr = defs.find(name);
|
auto itr = defs.find(name);
|
||||||
if (itr != defs.end())
|
if (itr != defs.end())
|
||||||
// If it was found
|
// If it was found
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -2212,7 +2212,7 @@ MlValue MlEnvironment::get(const std::string &name) const {
|
||||||
if (it != builtin_funcs.end())
|
if (it != builtin_funcs.end())
|
||||||
return MlValue(name, it->second);
|
return MlValue(name, it->second);
|
||||||
|
|
||||||
std::map<std::string, MlValue>::const_iterator itr = defs.find(name);
|
auto itr = defs.find(name);
|
||||||
if (itr != defs.end()) return itr->second;
|
if (itr != defs.end()) return itr->second;
|
||||||
else if (parent_scope != nullptr) {
|
else if (parent_scope != nullptr) {
|
||||||
itr = parent_scope->defs.find(name);
|
itr = parent_scope->defs.find(name);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue