From f3da54d99c944d993082b24777adb5b2deda2a91 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 16 Sep 2018 15:49:18 -0700 Subject: [PATCH] Convert some iterators to C++-11 range-based loops --- src/builtin_history.cpp | 3 +-- src/fish_tests.cpp | 5 ++--- src/input.cpp | 10 ++++------ src/path.cpp | 3 +-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/builtin_history.cpp b/src/builtin_history.cpp index 29cfc10e2..897acecf8 100644 --- a/src/builtin_history.cpp +++ b/src/builtin_history.cpp @@ -269,8 +269,7 @@ int builtin_history(parser_t &parser, io_streams_t &streams, wchar_t **argv) { status = STATUS_INVALID_ARGS; break; } - for (wcstring_list_t::const_iterator iter = args.begin(); iter != args.end(); ++iter) { - wcstring delete_string = *iter; + for (wcstring delete_string : args) { if (delete_string[0] == '"' && delete_string[delete_string.length() - 1] == '"') { delete_string = delete_string.substr(1, delete_string.length() - 2); } diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 997eec357..ccab557b0 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -1548,12 +1548,11 @@ static bool expand_test(const wchar_t *in, expand_flags_t flags, ...) { if (arg) { wcstring msg = L"Expected ["; bool first = true; - for (wcstring_list_t::const_iterator it = expected.begin(), end = expected.end(); - it != end; ++it) { + for (const wcstring &exp : expected) { if (!first) msg += L", "; first = false; msg += '"'; - msg += *it; + msg += exp; msg += '"'; } msg += L"], found ["; diff --git a/src/input.cpp b/src/input.cpp index e93a267a4..4d90df153 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -328,9 +328,8 @@ static void input_mapping_execute(const input_mapping_t &m, bool allow_commands) // has_commands: there are shell commands that need to be evaluated bool has_commands = false, has_functions = false; - for (wcstring_list_t::const_iterator it = m.commands.begin(), end = m.commands.end(); it != end; - ++it) { - if (input_function_get_code(*it) != INPUT_CODE_NONE) + for (const wcstring &cmd : m.commands) { + if (input_function_get_code(cmd) != INPUT_CODE_NONE) has_functions = true; else has_commands = true; @@ -365,9 +364,8 @@ static void input_mapping_execute(const input_mapping_t &m, bool allow_commands) // FIXME(snnw): if commands add stuff to input queue (e.g. commandline -f execute), we won't // see that until all other commands have also been run. int last_status = proc_get_last_status(); - for (wcstring_list_t::const_iterator it = m.commands.begin(), end = m.commands.end(); - it != end; ++it) { - parser_t::principal_parser().eval(it->c_str(), io_chain_t(), TOP); + for (const wcstring &cmd : m.commands) { + parser_t::principal_parser().eval(cmd.c_str(), io_chain_t(), TOP); } proc_set_last_status(last_status); input_common_next_ch(R_NULL); diff --git a/src/path.cpp b/src/path.cpp index 6cc64048e..a7d5bbe4a 100644 --- a/src/path.cpp +++ b/src/path.cpp @@ -203,9 +203,8 @@ bool path_get_cdpath(const env_var_t &dir_var, wcstring *out, const wchar_t *wd, } bool success = false; - for (wcstring_list_t::const_iterator iter = paths.begin(); iter != paths.end(); ++iter) { + for (const wcstring &dir : paths) { struct stat buf; - const wcstring &dir = *iter; if (wstat(dir, &buf) == 0) { if (S_ISDIR(buf.st_mode)) { success = true;