diff options
author | Artur Ryt <artur.ryt@gmail.com> | 2019-02-14 19:39:24 (GMT) |
---|---|---|
committer | Artur Ryt <artur.ryt@gmail.com> | 2019-02-15 22:40:30 (GMT) |
commit | 706b93fa558c5a2e0e45a7068b5039d1f40fbc90 (patch) | |
tree | 6f0e1695ac30f5e4d18eb12ac45094456ca401a4 /Source/cmcmd.cxx | |
parent | 8c4de819449bbb1710b1cc2440357757e5cb757c (diff) | |
download | CMake-706b93fa558c5a2e0e45a7068b5039d1f40fbc90.zip CMake-706b93fa558c5a2e0e45a7068b5039d1f40fbc90.tar.gz CMake-706b93fa558c5a2e0e45a7068b5039d1f40fbc90.tar.bz2 |
Modernize: C-arrays and loops over them
It replaces C arrays with deduced std::initializer_lists
or std::array what makes enables for-loop over them.
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r-- | Source/cmcmd.cxx | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 4415ba6..4171624 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -37,6 +37,7 @@ #include "cmsys/Process.h" #include "cmsys/Terminal.h" #include <algorithm> +#include <array> #include <iostream> #include <iterator> #include <memory> // IWYU pragma: keep @@ -350,12 +351,13 @@ struct CoCompiler bool NoOriginalCommand; }; -static CoCompiler CoCompilers[] = { // Table of options and handlers. - { "--cppcheck=", HandleCppCheck, false }, - { "--cpplint=", HandleCppLint, false }, - { "--iwyu=", HandleIWYU, false }, - { "--lwyu=", HandleLWYU, true }, - { "--tidy=", HandleTidy, false } +static const std::array<CoCompiler, 5> CoCompilers = { + { // Table of options and handlers. + { "--cppcheck=", HandleCppCheck, false }, + { "--cpplint=", HandleCppLint, false }, + { "--iwyu=", HandleIWYU, false }, + { "--lwyu=", HandleLWYU, true }, + { "--tidy=", HandleTidy, false } } }; struct CoCompileJob @@ -386,16 +388,15 @@ int cmcmd::HandleCoCompileCommands(std::vector<std::string>& args) doing_options = false; } else if (doing_options) { bool optionFound = false; - for (CoCompiler const* cc = cm::cbegin(CoCompilers); - cc != cm::cend(CoCompilers); ++cc) { - size_t optionLen = strlen(cc->Option); - if (arg.compare(0, optionLen, cc->Option) == 0) { + for (CoCompiler const& cc : CoCompilers) { + size_t optionLen = strlen(cc.Option); + if (arg.compare(0, optionLen, cc.Option) == 0) { optionFound = true; CoCompileJob job; job.Command = arg.substr(optionLen); - job.Handler = cc->Handler; + job.Handler = cc.Handler; jobs.push_back(std::move(job)); - if (cc->NoOriginalCommand) { + if (cc.NoOriginalCommand) { runOriginalCmd = false; } } @@ -419,9 +420,8 @@ int cmcmd::HandleCoCompileCommands(std::vector<std::string>& args) if (jobs.empty()) { std::cerr << "__run_co_compile missing command to run. " "Looking for one or more of the following:\n"; - for (CoCompiler const* cc = cm::cbegin(CoCompilers); - cc != cm::cend(CoCompilers); ++cc) { - std::cerr << cc->Option << "\n"; + for (CoCompiler const& cc : CoCompilers) { + std::cerr << cc.Option << "\n"; } return 1; } |