]> git.tdb.fi Git - builder.git/commitdiff
Replace basic for loops with range-based loops or algorithms
authorMikko Rasa <tdb@tdb.fi>
Mon, 19 Dec 2022 12:32:43 +0000 (14:32 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 19 Dec 2022 17:19:08 +0000 (19:19 +0200)
In remaining cases use auto as a shortcut for the iterator type.

60 files changed:
source/analyzer.cpp
source/androidapplicationcomponent.cpp
source/androidassetpackagingtool.cpp
source/androidmanifestgenerator.cpp
source/androidpackagefile.cpp
source/androidresourcebundle.cpp
source/androidtools.cpp
source/apkbuilder.cpp
source/architecture.cpp
source/binary.cpp
source/binarycomponent.cpp
source/binarypackage.cpp
source/booleanevaluator.cpp
source/builder.cpp
source/buildercli.cpp
source/buildgraph.cpp
source/buildinfo.cpp
source/cache.cpp
source/chainedtask.cpp
source/compilecommandsgenerator.cpp
source/compilecommandsjson.cpp
source/component.cpp
source/config.cpp
source/csourcefile.cpp
source/datacollection.cpp
source/datapack.cpp
source/datapackcomponent.cpp
source/datatool.cpp
source/datatransform.cpp
source/exportdefinitions.cpp
source/externaltask.cpp
source/filetarget.cpp
source/gnuarchiver.cpp
source/gnucompiler.cpp
source/gnulinker.cpp
source/installcomponent.cpp
source/installmap.cpp
source/mingwdlltool.cpp
source/msvcarchiver.cpp
source/msvccompiler.cpp
source/msvclinker.cpp
source/objectfile.cpp
source/package.cpp
source/packagemanager.cpp
source/pattern.cpp
source/pkgconfiggenerator.cpp
source/sharedlibrary.cpp
source/sourcearchivecomponent.cpp
source/sourcegenerator.cpp
source/sourcepackage.cpp
source/staticlibrary.cpp
source/tar.cpp
source/target.cpp
source/task.cpp
source/toolchain.cpp
source/vcxprojectgenerator.cpp
source/virtualfilesystem.cpp
source/virtualtarget.cpp
source/vssolutionfile.cpp
source/vssolutiongenerator.cpp

index 2c9cf058d7a565d3849acca028e150d878f4e85c..4cebafad175ae6d7cc3a1a2459ffbba4c4d1709e 100644 (file)
@@ -24,15 +24,12 @@ void Analyzer::analyze()
        if(mode==RDEPS)
        {
                rdepends.clear();
-               const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets();
-               for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
+               for(const auto &kvp: builder.get_build_graph().get_targets())
                {
-                       const Target::Dependencies &depends = i->second->get_dependencies();
-                       for(Target::Dependencies::const_iterator j=depends.begin(); j!=depends.end(); ++j)
-                               rdepends[*j].insert(i->second);
-                       const Target::Dependencies &tdepends = i->second->get_transitive_dependencies();
-                       for(Target::Dependencies::const_iterator j=tdepends.begin(); j!=tdepends.end(); ++j)
-                               rdepends[*j].insert(i->second);
+                       for(Target *d: kvp.second->get_dependencies())
+                               rdepends[d].insert(kvp.second);
+                       for(Target *d: kvp.second->get_transitive_dependencies())
+                               rdepends[d].insert(kvp.second);
                }
        }
 
@@ -49,9 +46,8 @@ void Analyzer::analyze()
        Target &goals = builder.get_build_graph().get_goals();
        if(mode==RDEPS)
        {
-               const Target::Dependencies &deps = goals.get_dependencies();
-               for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
-                       build_depend_table(**i, 0);
+               for(Target *d: goals.get_dependencies())
+                       build_depend_table(*d, 0);
        }
        else
                build_depend_table(goals, 0);
@@ -120,8 +116,8 @@ void Analyzer::build_depend_table(Target &tgt, unsigned depth)
 
                depends.sort(full_paths ? target_order_full : target_order);
 
-               for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
-                       build_depend_table(**i, depth+1);
+               for(Target *d: depends)
+                       build_depend_table(*d, depth+1);
        }
 }
 
@@ -130,22 +126,22 @@ void Analyzer::print_table() const
        vector<string::size_type> col_width;
 
        // Determine column widths
-       for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
+       for(const vector<string> &r: table)
        {
-               if(col_width.size()<i->size())
-                       col_width.resize(i->size(), 0);
-               for(unsigned j=0; j<i->size(); ++j)
-                       col_width[j] = max(col_width[j], (*i)[j].size());
+               if(col_width.size()<r.size())
+                       col_width.resize(r.size(), 0);
+               for(unsigned j=0; j<r.size(); ++j)
+                       col_width[j] = max(col_width[j], r[j].size());
        }
 
-       for(Table::const_iterator i=table.begin(); i!=table.end(); ++i)
+       for(const vector<string> &r: table)
        {
                string line;
-               for(unsigned j=0; j<i->size(); ++j)
+               for(unsigned j=0; j<r.size(); ++j)
                {
                        if(j>0)
                                line += "  ";
-                       line += lexical_cast<string>((*i)[j], Fmt("%-s").width(col_width[j]));
+                       line += lexical_cast<string>(r[j], Fmt("%-s").width(col_width[j]));
                }
                IO::print("%s\n", line);
        }
index 99f14408d8e05ebe6d6c50e9348c3a956433a5c8..26277c8c02450fd8c75c065cc4f1e0a3ec090e0e 100644 (file)
@@ -21,27 +21,25 @@ void AndroidApplicationComponent::create_targets() const
        Builder &builder = package.get_builder();
        BuildGraph &build_graph = builder.get_build_graph();
 
-       const BuildGraph::TargetMap &targets = build_graph.get_targets();
        list<Target *> contents;
-       for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
-               if(i->second->get_package()==&package)
-                       if(InstalledFile *inst = dynamic_cast<InstalledFile *>(i->second))
+       for(const auto &kvp: build_graph.get_targets())
+               if(kvp.second->get_package()==&package)
+                       if(InstalledFile *inst = dynamic_cast<InstalledFile *>(kvp.second))
                                contents.push_back(inst->get_real_target());
 
        AndroidManifestFile *manifest = new AndroidManifestFile(builder, *this);
        manifest->set_orientation(orientation);
-       for(set<string>::const_iterator i=permissions.begin(); i!=permissions.end(); ++i)
-               manifest->add_permission(*i);
+       for(const string &p: permissions)
+               manifest->add_permission(p);
 
        list<Target *> resource_sources;
        resource_sources.push_back(manifest);
 
        const Toolchain &toolchain = builder.get_toolchain();
        Tool &copy = toolchain.get_tool("CP");
-       SourceList source_filenames = collect_source_files();
-       for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i)
+       for(const FS::Path &s: collect_source_files())
        {
-               Target *tgt = new AndroidResourceFile(builder, *this, *i);
+               Target *tgt = new AndroidResourceFile(builder, *this, s);
                resource_sources.push_back(copy.create_target(*tgt, "//"));
        }
 
@@ -63,16 +61,16 @@ void AndroidApplicationComponent::create_targets() const
                lib_dir += arch.get_type();
 
        string assets_dir = "//"+name+"/assets";
-       for(list<Target *>::const_iterator i=contents.begin(); i!=contents.end(); ++i)
+       for(Target *t: contents)
        {
                Target *staged = 0;
-               if(SharedLibrary *shlib = dynamic_cast<SharedLibrary *>(*i))
+               if(SharedLibrary *shlib = dynamic_cast<SharedLibrary *>(t))
                {
                        manifest->set_native_library(shlib);
-                       staged = copy.create_target(**i, lib_dir);
+                       staged = copy.create_target(*t, lib_dir);
                }
                else
-                       staged = copy.create_target(**i, assets_dir);
+                       staged = copy.create_target(*t, assets_dir);
                apk_sources.push_back(staged);
        }
 
index 9e0fef75a990f8252d226ceda12dd396fe84fe60..0ef99a7dca4ea9d150203b0205aaab8a7f18f356 100644 (file)
@@ -29,11 +29,11 @@ Target *AndroidAssetPackagingTool::create_target(const list<Target *> &sources,
 {
        AndroidManifestFile *manifest = 0;
        list<FileTarget *> resources;
-       for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+       for(Target *s: sources)
        {
-               if(AndroidManifestFile *m = dynamic_cast<AndroidManifestFile *>(*i))
+               if(AndroidManifestFile *m = dynamic_cast<AndroidManifestFile *>(s))
                        manifest = m;
-               else if(FileTarget *f = dynamic_cast<FileTarget *>(*i))
+               else if(FileTarget *f = dynamic_cast<FileTarget *>(s))
                        resources.push_back(f);
        }
 
@@ -61,12 +61,11 @@ Task *AndroidAssetPackagingTool::run(const Target &tgt) const
        argv.push_back("-F");
        argv.push_back(FS::relative(res.get_path(), work_dir).str());
 
-       const Target::Dependencies &depends = res.get_dependencies();
        list<FS::Path> resource_dirs;
-       for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
+       for(Target *d: res.get_dependencies())
        {
-               FileTarget *file = dynamic_cast<FileTarget *>(*i);
-               Target *real = (*i)->get_real_target();
+               FileTarget *file = dynamic_cast<FileTarget *>(d);
+               Target *real = d->get_real_target();
 
                if(dynamic_cast<AndroidManifestFile *>(real))
                {
@@ -81,11 +80,11 @@ Task *AndroidAssetPackagingTool::run(const Target &tgt) const
        }
 
        set<string> seen_dirs;
-       for(list<FS::Path>::const_iterator i=resource_dirs.begin(); i!=resource_dirs.end(); ++i)
-               if(seen_dirs.insert(i->str()).second)
+       for(const FS::Path &d: resource_dirs)
+               if(seen_dirs.insert(d.str()).second)
                {
                        argv.push_back("-S");
-                       argv.push_back(FS::relative(*i, work_dir).str());
+                       argv.push_back(FS::relative(d, work_dir).str());
                }
 
        return new ExternalTask(argv, work_dir);
index a7cda0428dea4ce95954fbccd1cb2ca6ea347358..1d2f330da0f6dbf75ea8053c7fc2e3e27e9bceae 100644 (file)
@@ -60,9 +60,8 @@ void AndroidManifestGenerator::Worker::main()
                out.write("\t\t</activity>\n");
        }
        out.write("\t</application>\n");
-       const set<string> &permissions = manifest.get_permissions();
-       for(set<string>::const_iterator i=permissions.begin(); i!=permissions.end(); ++i)
-               IO::print(out, "\t<uses-permission android:name=\"%s\" />\n", *i);
+       for(const string &p: manifest.get_permissions())
+               IO::print(out, "\t<uses-permission android:name=\"%s\" />\n", p);
        out.write("</manifest>\n");
 
        status = Task::SUCCESS;
index 1400d0f8da8067a5f983ce4f1ca61c84517d1367..22eedec6cca8499d57cfa5ef3fd50bfbfd2d840a 100644 (file)
@@ -11,6 +11,6 @@ AndroidPackageFile::AndroidPackageFile(Builder &b, const Component &c, AndroidRe
        component = &c;
 
        add_dependency(resource_bundle);
-       for(list<FileTarget *>::const_iterator i=other_files.begin(); i!=other_files.end(); ++i)
-               add_dependency(**i);
+       for(FileTarget *f: other_files)
+               add_dependency(*f);
 }
index d3271267632c3ca4f5abf59b8d7b24824afcb387..2918b0532a11ff84a0238fd193909638e4378422 100644 (file)
@@ -11,6 +11,6 @@ AndroidResourceBundle::AndroidResourceBundle(Builder &b, const Component &c, And
        component = &c;
 
        add_dependency(manifest);
-       for(list<FileTarget *>::const_iterator i=resources.begin(); i!=resources.end(); ++i)
-               add_dependency(**i);
+       for(FileTarget *f: resources)
+               add_dependency(*f);
 }
index 118926e1aa3e29dd277d77f138090c65305536b2..5ef2bec5f23b40ec3ff31a58be99d3d1189ece0e 100644 (file)
@@ -53,10 +53,8 @@ AndroidDevKit::AndroidDevKit(Builder &b, const string &type, const FS::Path &def
                return;
 
        builder.get_logger().log("files", format("Traversing %s", platforms_dir.str()));
-       vector<string> platforms = list_filtered(platforms_dir, "^android-[1-9][0-9]*$");
-
-       for(vector<string>::const_iterator i=platforms.begin(); i!=platforms.end(); ++i)
-               supported_api_levels.insert(lexical_cast<unsigned>(i->substr(8)));
+       for(const string &p: list_filtered(platforms_dir, "^android-[1-9][0-9]*$"))
+               supported_api_levels.insert(lexical_cast<unsigned>(p.substr(8)));
 }
 
 void AndroidDevKit::select_api_level(unsigned api)
@@ -84,16 +82,14 @@ void AndroidSdk::find_build_tools_dir()
        }
 
        builder.get_logger().log("files", format("Traversing %s", bt_dir.str()));
-       vector<string> tool_versions = list_files(bt_dir);
-
        string use_tools;
        unsigned latest_version = 0;
-       for(vector<string>::const_iterator i=tool_versions.begin(); i!=tool_versions.end(); ++i)
+       for(const string &v: list_files(bt_dir))
        {
-               unsigned version = parse_version(*i);
+               unsigned version = parse_version(v);
                if(version>latest_version)
                {
-                       use_tools = *i;
+                       use_tools = v;
                        latest_version = version;
                }
        }
@@ -152,13 +148,11 @@ void AndroidNdk::find_toolchain_dir()
 
        builder.get_logger().log("files", format("Traversing %s", toolchains_dir.str()));
        string prefix = architecture.get_cross_prefix()+"-";
-       vector<string> toolchains = list_filtered(toolchains_dir, "^"+prefix);
-
        string use_toolchain;
        unsigned latest_version = 0;
-       for(vector<string>::const_iterator i=toolchains.begin(); i!=toolchains.end(); ++i)
+       for(const string &t: list_filtered(toolchains_dir, "^"+prefix))
        {
-               string version_str = i->substr(prefix.size());
+               string version_str = t.substr(prefix.size());
                string compiler = "gcc";
                if(!isdigit(version_str[0]))
                {
@@ -174,7 +168,7 @@ void AndroidNdk::find_toolchain_dir()
                unsigned version = parse_version(version_str);
                if(version>latest_version)
                {
-                       use_toolchain = *i;
+                       use_toolchain = t;
                        latest_version = version;
                }
        }
@@ -206,8 +200,8 @@ void AndroidNdk::init_api_level(unsigned api)
        FS::Path platform_archs_dir = root/"platforms"/format("android-%d", api);
        builder.get_logger().log("files", format("Traversing %s", platform_archs_dir.str()));
        vector<string> platform_archs = list_filtered(platform_archs_dir, "^arch-");
-       for(vector<string>::iterator i=platform_archs.begin(); i!=platform_archs.end(); ++i)
-               i->erase(0, 5);
+       for(string &a: platform_archs)
+               a.erase(0, 5);
        string use_arch = architecture.best_match(platform_archs);
 
        if(use_arch.empty())
@@ -228,7 +222,7 @@ AndroidTools::AndroidTools(Builder &builder, const Architecture &arch):
        const set<unsigned> &sdk_api_levels = sdk.get_supported_api_levels();
        const set<unsigned> &ndk_api_levels = ndk.get_supported_api_levels();
        unsigned highest_common = 0;
-       for(set<unsigned>::const_reverse_iterator i=sdk_api_levels.rbegin(); (!highest_common && i!=sdk_api_levels.rend()); ++i)
+       for(auto i=sdk_api_levels.rbegin(); (!highest_common && i!=sdk_api_levels.rend()); ++i)
                if(ndk_api_levels.count(*i))
                        highest_common = *i;
 
index 9cd1a16b5b45e878bf194509438e9a06dd26d52b..2568f33e081bce17a8852300ca09bf75da758e4f 100644 (file)
@@ -25,11 +25,11 @@ Target *ApkBuilder::create_target(const list<Target *> &sources, const string &)
 {
        AndroidResourceBundle *resource_bundle = 0;
        list<FileTarget *> other_files;
-       for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+       for(Target *s: sources)
        {
-               if(AndroidResourceBundle *r = dynamic_cast<AndroidResourceBundle *>(*i))
+               if(AndroidResourceBundle *r = dynamic_cast<AndroidResourceBundle *>(s))
                        resource_bundle = r;
-               else if(FileTarget *f = dynamic_cast<FileTarget *>(*i))
+               else if(FileTarget *f = dynamic_cast<FileTarget *>(s))
                        other_files.push_back(f);
        }
        AndroidPackageFile *apk = new AndroidPackageFile(builder, *resource_bundle->get_component(), *resource_bundle, other_files);
@@ -51,13 +51,12 @@ Task *ApkBuilder::run(const Target &tgt) const
        argv.push_back(executable->get_path().str());
        argv.push_back("u");
 
-       const Target::Dependencies &depends = apk.get_dependencies();
        FS::Path input_path;
        list<FS::Path> files;
-       for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
+       for(Target *d: apk.get_dependencies())
        {
-               FileTarget *file = dynamic_cast<FileTarget *>(*i);
-               Target *real = (*i)->get_real_target();
+               FileTarget *file = dynamic_cast<FileTarget *>(d);
+               Target *real = d->get_real_target();
 
                if(dynamic_cast<AndroidResourceBundle *>(real))
                        input_path = file->get_path();
@@ -67,8 +66,8 @@ Task *ApkBuilder::run(const Target &tgt) const
 
        FS::Path work_dir = FS::dirname(input_path);
 
-       for(list<FS::Path>::const_iterator i=files.begin(); i!=files.end(); ++i)
-               argv.push_back(FS::relative(*i, work_dir).str());
+       for(const FS::Path &f: files)
+               argv.push_back(FS::relative(f, work_dir).str());
 
        ExternalTask *task = new ExternalTask(argv, work_dir);
        task->set_stdin(FS::basename(input_path));
index 212f148027d00c5ab4f1465af16dc1bf226d87f5..2efcd5e3e4ee23dc9294cfb04f261ab06ce8f1c8 100644 (file)
@@ -182,11 +182,11 @@ bool Architecture::match_name(const string &pattern) const
        bool negate = (pattern[0]=='!');
        vector<string> parts = split(pattern.substr(negate), "-");
        resolve_aliases(parts);
-       for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+       for(const string &p: parts)
        {
-               if((*i=="32" && bits==32) || (*i=="64" && bits==64))
+               if((p=="32" && bits==32) || (p=="64" && bits==64))
                        ;
-               else if(*i!=type && *i!=cpu && *i!=fpu && *i!=system && *i!=toolchain)
+               else if(p!=type && p!=cpu && p!=fpu && p!=system && p!=toolchain)
                        return negate;
        }
        return !negate;
@@ -196,19 +196,19 @@ string Architecture::best_match(const vector<string> &names) const
 {
        string best;
        unsigned best_size = 0;
-       for(vector<string>::const_iterator i=names.begin(); i!=names.end(); ++i)
-               if(match_name(*i))
+       for(const string &n: names)
+               if(match_name(n))
                {
                        /* TODO Do full parse and alias resolution here?  Otherwise x86 and
                        x86_64 are treated as equally good, even though the latter is more
                        specific. */
                        unsigned size = 1;
-                       for(string::const_iterator j=i->begin(); j!=i->end(); ++j)
-                               size += (*j=='-');
+                       for(char c: n)
+                               size += (c=='-');
 
                        if(size>best_size)
                        {
-                               best = *i;
+                               best = n;
                                best_size = size;
                        }
                }
@@ -255,61 +255,61 @@ void Architecture::parse_specification(const string &spec)
 {
        vector<string> parts = split(spec, "-");
        resolve_aliases(parts);
-       for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+       for(const string &p: parts)
        {
                bool ok = false;
 
                for(unsigned j=0; (!ok && types[j]); ++j)
-                       if(*i==types[j])
+                       if(p==types[j])
                        {
-                               if(!type.empty() && *i!=type)
+                               if(!type.empty() && p!=type)
                                        throw invalid_argument("Conflicting type specification");
-                               type = *i;
+                               type = p;
                                ok = true;
                        }
 
                for(unsigned j=0; (!ok && cpus[j]); j+=2)
-                       if(*i==cpus[j])
+                       if(p==cpus[j])
                        {
                                if(type.empty())
                                        type = cpus[j+1];
                                else if(cpus[j+1]!=type)
                                        throw invalid_argument("Conflicting CPU specification");
-                               cpu = *i;
+                               cpu = p;
                                ok = true;
                        }
 
                for(unsigned j=0; (!ok && fpus[j]); j+=2)
-                       if(*i==fpus[j])
+                       if(p==fpus[j])
                        {
                                if(fpus[j+1]!=type)
                                        throw invalid_argument("Conflicting FPU specification");
-                               fpu = *i;
+                               fpu = p;
                                ok = true;
                        }
 
                for(unsigned j=0; (!ok && systems[j]); ++j)
-                       if(*i==systems[j])
+                       if(p==systems[j])
                        {
-                               system = *i;
+                               system = p;
                                ok = true;
                        }
 
                for(unsigned j=0; (!ok && toolchains[j]); ++j)
-                       if(*i==toolchains[j])
+                       if(p==toolchains[j])
                        {
-                               toolchain = *i;
+                               toolchain = p;
                                ok = true;
                        }
 
-               if(!ok && (*i=="32" || *i=="64"))
+               if(!ok && (p=="32" || p=="64"))
                {
-                       bits = lexical_cast<unsigned>(*i);
+                       bits = lexical_cast<unsigned>(p);
                        ok = true;
                }
 
                if(!ok)
-                       throw invalid_argument("Unrecognized part in arch specification: "+*i);
+                       throw invalid_argument("Unrecognized part in arch specification: "+p);
        }
 }
 
index fcf30f1d1fca03170f868ac7423ced7d37605683..c8011d7c2a24c0cec015d751fca615fc8df23de4 100644 (file)
@@ -1,3 +1,4 @@
+#include <algorithm>
 #include <msp/fs/utils.h>
 #include <msp/strings/format.h>
 #include <msp/strings/utils.h>
@@ -22,8 +23,8 @@ Binary::Binary(Builder &b, const Component &c, const string &p, const list<Objec
        objects(objs)
 {
        component = &c;
-       for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
-               add_dependency(**i);
+       for(ObjectFile *o: objects)
+               add_dependency(*o);
 
        nested_build_sig = true;
        arch_in_build_sig = true;
@@ -31,8 +32,8 @@ Binary::Binary(Builder &b, const Component &c, const string &p, const list<Objec
 
 void Binary::collect_build_info(BuildInfo &binfo) const
 {
-       for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
-               if(const Tool *obj_tool = (*i)->get_tool())
+       for(ObjectFile *o: objects)
+               if(const Tool *obj_tool = o->get_tool())
                        binfo.update_from(obj_tool->get_build_info());
 
        Target::collect_build_info(binfo);
@@ -49,7 +50,7 @@ void Binary::find_dependencies()
        list<Target *> dep_libs;
        set<string> missing_libs;
        queue.push_back(this);
-       for(list<Target *>::iterator j=queue.begin(); j!=queue.end(); ++j)
+       for(auto j=queue.begin(); j!=queue.end(); ++j)
        {
                Target *tgt = *j;
 
@@ -63,15 +64,15 @@ void Binary::find_dependencies()
                                static_binfo.threads = true;
                }
 
-               list<Target *>::iterator insert_pos = j;
+               auto insert_pos = j;
                ++insert_pos;
-               for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
+               for(const string &l: binfo.libs)
                {
-                       if(i->size()>10 && !i->compare(i->size()-10, 10, ".framework"))
+                       if(l.size()>10 && !l.compare(l.size()-10, 10, ".framework"))
                                continue;
 
-                       BuildInfo::LibraryMode libmode = component->get_build_info().get_libmode_for(*i);
-                       Target *lib = builder.get_vfs().find_library(*i, binfo.libpath, libmode);
+                       BuildInfo::LibraryMode libmode = component->get_build_info().get_libmode_for(l);
+                       Target *lib = builder.get_vfs().find_library(l, binfo.libpath, libmode);
                        if(lib)
                        {
                                Target *real = lib->get_real_target();
@@ -80,8 +81,8 @@ void Binary::find_dependencies()
                                else
                                        dep_libs.push_back(lib);
                        }
-                       else if(missing_libs.insert(*i).second)
-                               problems.push_back(format("Required library %s not found", *i));
+                       else if(missing_libs.insert(l).second)
+                               problems.push_back(format("Required library %s not found", l));
                }
        }
 
@@ -90,12 +91,7 @@ void Binary::find_dependencies()
 
        /* Add only the last occurrence of each library to the actual dependencies.
        This ensures that static library ordering is correct. */
-       for(list<Target *>::iterator i=dep_libs.begin(); i!=dep_libs.end(); ++i)
-       {
-               bool last = true;
-               for(list<Target *>::iterator j=i; (last && j!=dep_libs.end()); ++j)
-                       last = (j==i || *j!=*i);
-               if(last)
+       for(auto i=dep_libs.begin(); i!=dep_libs.end(); ++i)
+               if(!any_of(next(i), dep_libs.end(), [i](Target *d){ return d==*i; }))
                        add_dependency(**i);
-       }
 }
index 49c4897ce69d7d25492ebe1521257dca04c77062..2cd6f853ca42db8472e7c4193c1e5f633d5f605f 100644 (file)
@@ -17,22 +17,21 @@ void BinaryComponent::create_build_info()
 {
        Component::create_build_info();
 
-       for(UseList::const_iterator i=uses.begin(); i!=uses.end(); ++i)
+       for(const Component *u: uses)
        {
                /* Select an include path that contains all the sources for this and the
                used component.  This should produce a sensible result in most cases. */
                FS::Path base;
-               for(SourceList::const_iterator j=sources.begin(); j!=sources.end(); ++j)
-                       base = base.empty() ? *j : FS::common_ancestor(base, *j);
-               const SourceList &use_sources = (*i)->get_sources();
-               for(SourceList::const_iterator j=use_sources.begin(); j!=use_sources.end(); ++j)
-                       base = FS::common_ancestor(base, *j);
+               for(const FS::Path &s: sources)
+                       base = base.empty() ? s : FS::common_ancestor(base, s);
+               for(const FS::Path &s: u->get_sources())
+                       base = FS::common_ancestor(base, s);
                build_info.incpath.push_back(base);
-               build_info.libs.push_back((*i)->get_name());
-               if(!(*i)->get_install())
+               build_info.libs.push_back(u->get_name());
+               if(!u->get_install())
                {
-                       build_info.libmodes[(*i)->get_name()] = BuildInfo::STATIC;
-                       build_info.libpath.push_back((*i)->get_package().get_output_directory());
+                       build_info.libmodes[u->get_name()] = BuildInfo::STATIC;
+                       build_info.libpath.push_back(u->get_package().get_output_directory());
                }
        }
 
@@ -56,7 +55,7 @@ void BinaryComponent::create_targets() const
 
        list<Target *> objs;
        SourceList source_filenames = collect_source_files();
-       for(SourceList::iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i)
+       for(auto i=source_filenames.begin(); i!=source_filenames.end(); ++i)
        {
                string ext = FS::extpart(FS::basename(*i));
                Target *src = 0;
@@ -109,10 +108,9 @@ void BinaryComponent::create_targets() const
                                if(dynamic_cast<FileTarget *>(src)->is_installable())
                                        build_graph.add_installed_target(*src);
 
-                               const Target::Dependencies &side_effects = src->get_side_effects();
-                               for(Target::Dependencies::const_iterator j=side_effects.begin(); j!=side_effects.end(); ++j)
-                                       if(dynamic_cast<FileTarget *>(*j)->is_installable())
-                                               build_graph.add_installed_target(**j);
+                               for(Target *s: src->get_side_effects())
+                                       if(dynamic_cast<FileTarget *>(s)->is_installable())
+                                               build_graph.add_installed_target(*s);
                        }
                }
        }
@@ -131,11 +129,11 @@ void BinaryComponent::create_targets() const
        else
                results.push_back(linker.create_target(objs));
 
-       for(list<Target *>::const_iterator i=results.begin(); i!=results.end(); ++i)
+       for(Target *r: results)
        {
-               build_graph.add_primary_target(**i);
+               build_graph.add_primary_target(*r);
                if(install)
-                       build_graph.add_installed_target(**i);
+                       build_graph.add_installed_target(*r);
        }
 }
 
index e48f17cee0c0d3f5987abb0096bf0154bb37aba5..2c32d87769a76a48f7ce9a2bb2a5414486b42ff3 100644 (file)
@@ -23,9 +23,9 @@ BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, c
        process_flags(flags, pkg->export_binfo);
 
        Flags exclusive_static_flags;
-       for(Flags::const_iterator i=static_flags.begin(); i!=static_flags.end(); ++i)
-               if(find(flags.begin(), flags.end(), *i)==flags.end())
-                       exclusive_static_flags.push_back(*i);
+       for(const string &f: static_flags)
+               if(find(flags.begin(), flags.end(), f)==flags.end())
+                       exclusive_static_flags.push_back(f);
        process_flags(exclusive_static_flags, pkg->static_binfo);
 
        return pkg;
@@ -33,34 +33,32 @@ BinaryPackage *BinaryPackage::from_flags(Builder &builder, const string &name, c
 
 void BinaryPackage::process_flags(const Flags &flags, BuildInfo &binfo)
 {
-       for(Flags::const_iterator i=flags.begin(); i!=flags.end(); ++i)
+       for(const string &f: flags)
        {
-               if(!i->compare(0, 2, "-I"))
-                       binfo.incpath.push_back(i->substr(2));
-               else if(!i->compare(0, 2, "-D"))
+               if(!f.compare(0, 2, "-I"))
+                       binfo.incpath.push_back(f.substr(2));
+               else if(!f.compare(0, 2, "-D"))
                {
-                       string::size_type equals = i->find('=');
+                       string::size_type equals = f.find('=');
                        if(equals!=string::npos)
-                               binfo.defines[i->substr(2, equals-2)] = i->substr(equals+1);
+                               binfo.defines[f.substr(2, equals-2)] = f.substr(equals+1);
                        else
-                               binfo.defines[i->substr(2)] = string();
+                               binfo.defines[f.substr(2)] = string();
                }
-               else if(!i->compare(0, 2, "-L"))
-                       binfo.libpath.push_back(i->substr(2));
-               else if(!i->compare(0, 2, "-l"))
-                       binfo.libs.push_back(i->substr(2));
-               else if(*i=="-pthread")
+               else if(!f.compare(0, 2, "-L"))
+                       binfo.libpath.push_back(f.substr(2));
+               else if(!f.compare(0, 2, "-l"))
+                       binfo.libs.push_back(f.substr(2));
+               else if(f=="-pthread")
                        binfo.threads = true;
        }
 }
 
 void BinaryPackage::do_prepare()
 {
-       bool has_relative_paths = false;
-       for(BuildInfo::PathList::const_iterator i=export_binfo.libpath.begin(); (!has_relative_paths && i!=export_binfo.libpath.end()); ++i)
-               has_relative_paths = !i->is_absolute();
-       for(BuildInfo::PathList::const_iterator i=export_binfo.incpath.begin(); (!has_relative_paths && i!=export_binfo.incpath.end()); ++i)
-               has_relative_paths = !i->is_absolute();
+       auto is_relative = [](const FS::Path &p){ return !p.is_absolute(); };
+       bool has_relative_paths = any_of(export_binfo.libpath.begin(), export_binfo.libpath.end(), is_relative) ||
+               any_of(export_binfo.incpath.begin(), export_binfo.incpath.end(), is_relative);
 
        list<FS::Path> bases;
 
@@ -73,9 +71,9 @@ void BinaryPackage::do_prepare()
        bases.push_back(FS::Path());
 
        bool system = false;
-       for(list<FS::Path>::const_iterator i=bases.begin(); i!=bases.end(); ++i)
+       for(const FS::Path &b: bases)
        {
-               FS::Path prefix = *i;
+               FS::Path prefix = b;
                system = prefix.empty();
                if(system)
                {
@@ -88,21 +86,21 @@ void BinaryPackage::do_prepare()
                BuildInfo::PathList libpath = export_binfo.libpath;
                if(!system && libpath.empty())
                        libpath.push_back("lib");
-               for(BuildInfo::PathList::iterator j=libpath.begin(); j!=libpath.end(); ++j)
-                       *j = prefix/ *j;
+               for(FS::Path &p: libpath)
+                       p = prefix/p;
 
                bool all_found = true;
-               for(BuildInfo::WordList::const_iterator j=export_binfo.libs.begin(); j!=export_binfo.libs.end(); ++j)
-                       all_found &= (builder.get_vfs().find_library(*j, libpath, export_binfo.libmode, system)!=0);
+               for(const string &l: export_binfo.libs)
+                       all_found &= (builder.get_vfs().find_library(l, libpath, export_binfo.libmode, system)!=0);
 
                BuildInfo::PathList incpath = export_binfo.incpath;
                if(!system && incpath.empty())
                        incpath.push_back("include");
-               for(BuildInfo::PathList::iterator j=incpath.begin(); j!=incpath.end(); ++j)
-                       *j = prefix/ *j;
+               for(FS::Path &p: incpath)
+                       p = prefix/p;
 
-               for(HeaderList::const_iterator j=headers.begin(); j!=headers.end(); ++j)
-                       all_found &= (builder.get_vfs().find_header(*j, 0, incpath, system)!=0);
+               for(const string &h: headers)
+                       all_found &= (builder.get_vfs().find_header(h, 0, incpath, system)!=0);
 
                if(all_found)
                {
@@ -129,10 +127,10 @@ void BinaryPackage::do_prepare()
 
        if(has_relative_paths)
        {
-               for(BuildInfo::PathList::iterator i=export_binfo.incpath.begin(); i!=export_binfo.incpath.end(); ++i)
-                       *i = base_path/ *i;
-               for(BuildInfo::PathList::iterator i=export_binfo.libpath.begin(); i!=export_binfo.libpath.end(); ++i)
-                       *i = base_path/ *i;
+               for(FS::Path &p: export_binfo.incpath)
+                       p = base_path/p;
+               for(FS::Path &p: export_binfo.libpath)
+                       p = base_path/p;
        }
 
        if(!static_binfo.libs.empty())
@@ -140,14 +138,14 @@ void BinaryPackage::do_prepare()
                BuildInfo::PathList combined_libpath = static_binfo.libpath;
                combined_libpath.insert(combined_libpath.end(), export_binfo.libpath.begin(), export_binfo.libpath.end());
 
-               for(BuildInfo::WordList::const_iterator i=export_binfo.libs.begin(); i!=export_binfo.libs.end(); ++i)
-                       if(Target *lib = builder.get_vfs().find_library(*i, export_binfo.libpath, BuildInfo::FORCE_STATIC, system))
+               for(const string &l: export_binfo.libs)
+                       if(Target *lib = builder.get_vfs().find_library(l, export_binfo.libpath, BuildInfo::FORCE_STATIC, system))
                                if(StaticLibrary *stlib = dynamic_cast<StaticLibrary *>(lib))
                                {
-                                       for(BuildInfo::WordList::const_iterator j=static_binfo.libs.begin(); j!=static_binfo.libs.end(); ++j)
-                                               stlib->add_required_library(*j);
-                                       for(BuildInfo::PathList::const_iterator j=combined_libpath.begin(); j!=combined_libpath.end(); ++j)
-                                               stlib->add_library_path(*j);
+                                       for(const string &s: static_binfo.libs)
+                                               stlib->add_required_library(s);
+                                       for(const FS::Path &p: combined_libpath)
+                                               stlib->add_library_path(p);
                                }
        }
 }
index ecb38fb0d07657e4ed9a1a3e574289e08bccee5b..01037415d2bf36ee9d012f59840e5463151b1cf9 100644 (file)
@@ -14,7 +14,7 @@ bool BooleanEvaluator::evaluate(const string &str)
 {
        string buf;
        last_was_op = true;
-       for(string::const_iterator i=str.begin();; ++i)
+       for(auto i=str.begin();; ++i)
        {
                if(i!=str.end() && (isalnum(*i) || (!buf.empty() && (*i=='_' || *i=='-'))))
                        buf += *i;
index e26c1157ec88ff5b06a3f08710d41a16cfcbf442..5475c7dab99aaa6baf610ec6a6a3529d21b0b5bc 100644 (file)
@@ -65,8 +65,8 @@ vector<string> Builder::get_build_types() const
 {
        vector<string> keys;
        keys.reserve(build_types.size());
-       for(BuildTypeMap::const_iterator i=build_types.begin(); i!=build_types.end(); ++i)
-               keys.push_back(i->first);
+       for(const auto &kvp: build_types)
+               keys.push_back(kvp.first);
        return keys;
 }
 
@@ -112,48 +112,37 @@ list<string> Builder::collect_problems() const
        set<const Component *> broken_components;
        set<const Tool *> broken_tools;
 
-       const BuildGraph::TargetMap &targets = build_graph.get_targets();
-       for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
-               if(i->second->is_broken())
+       for(const auto &kvp: build_graph.get_targets())
+               if(kvp.second->is_broken())
                {
-                       const list<string> &tgt_problems = i->second->get_problems();
-                       for(list<string>::const_iterator j=tgt_problems.begin(); j!=tgt_problems.end(); ++j)
-                               problems.push_back(format("%s: %s", i->second->get_name(), *j));
+                       for(const string &p: kvp.second->get_problems())
+                               problems.push_back(format("%s: %s", kvp.second->get_name(), p));
 
-                       const Package *package = i->second->get_package();
+                       const Package *package = kvp.second->get_package();
                        if(package && !package->get_problems().empty())
                                broken_packages.insert(package);
 
-                       const Component *component = i->second->get_component();
+                       const Component *component = kvp.second->get_component();
                        if(component && !component->get_problems().empty())
                                broken_components.insert(component);
 
-                       const Tool *tool = i->second->get_tool();
+                       const Tool *tool = kvp.second->get_tool();
                        if(tool && !tool->get_problems().empty())
                                broken_tools.insert(tool);
                }
 
        // TODO Sort components after their packages, and targets last
-       for(set<const Package *>::const_iterator i=broken_packages.begin(); i!=broken_packages.end(); ++i)
-       {
-               const list<string> &pkg_problems = (*i)->get_problems();
-               for(list<string>::const_iterator j=pkg_problems.begin(); j!=pkg_problems.end(); ++j)
-                       problems.push_back(format("%s: %s", (*i)->get_name(), *j));
-       }
+       for(const Package *p: broken_packages)
+               for(const string &b: p->get_problems())
+                       problems.push_back(format("%s: %s", p->get_name(), b));
 
-       for(set<const Component *>::const_iterator i=broken_components.begin(); i!=broken_components.end(); ++i)
-       {
-               const list<string> &comp_problems = (*i)->get_problems();
-               for(list<string>::const_iterator j=comp_problems.begin(); j!=comp_problems.end(); ++j)
-                       problems.push_back(format("%s/%s: %s", (*i)->get_package().get_name(), (*i)->get_name(), *j));
-       }
+       for(const Component *c: broken_components)
+               for(const string &b: c->get_problems())
+                       problems.push_back(format("%s/%s: %s", c->get_package().get_name(), c->get_name(), b));
 
-       for(set<const Tool *>::const_iterator i=broken_tools.begin(); i!=broken_tools.end(); ++i)
-       {
-               const list<string> &tool_problems = (*i)->get_problems();
-               for(list<string>::const_iterator j=tool_problems.begin(); j!=tool_problems.end(); ++j)
-                       problems.push_back(format("%s: %s", (*i)->get_tag(), *j));
-       }
+       for(const Tool *t: broken_tools)
+               for(const string &b: t->get_problems())
+                       problems.push_back(format("%s: %s", t->get_tag(), b));
 
        return problems;
 }
@@ -171,9 +160,8 @@ void Builder::load_build_file(const FS::Path &fn, const Config::InputOptions *op
 
 void Builder::save_caches()
 {
-       const PackageManager::PackageMap &packages = package_manager.get_packages();
-       for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
-               i->second->save_caches();
+       for(const auto &kvp: package_manager.get_packages())
+               kvp.second->save_caches();
 }
 
 int Builder::build(unsigned jobs, bool dry_run, bool show_progress)
@@ -282,17 +270,16 @@ int Builder::clean(bool all, bool dry_run)
                if(tgt->is_buildable() && (tgt->get_package()==&package_manager.get_main_package() || all))
                        clean_tgts.insert(tgt);
 
-               const Target::Dependencies &deps = tgt->get_dependencies();
-               for(list<Target *>::const_iterator i=deps.begin(); i!=deps.end(); ++i)
-                       if(!clean_tgts.count(*i))
-                               queue.push_back(*i);
+               for(Target *t: tgt->get_dependencies())
+                       if(!clean_tgts.count(t))
+                               queue.push_back(t);
        }
 
-       for(set<Target *>::iterator i=clean_tgts.begin(); i!=clean_tgts.end(); ++i)
+       for(Target *t: clean_tgts)
        {
-               get_logger().log("tasks", format("RM    %s", (*i)->get_name()));
+               get_logger().log("tasks", format("RM    %s", t->get_name()));
                if(!dry_run)
-                       (*i)->clean();
+                       t->clean();
        }
 
        return 0;
index c7a2817ce4d6315ea99f33c3e414049c49f8b083..bf53c2912dfd59c964a9e8d96f26e14796105eea 100644 (file)
@@ -95,12 +95,9 @@ BuilderCLI::BuilderCLI(int argc, char **argv):
                logger.enable_channel("files");
                logger.enable_channel("auxcommands");
        }
-       for(list<string>::const_iterator i=log_channels.begin(); i!=log_channels.end(); ++i)
-       {
-               vector<string> parts = split(*i, ',');
-               for(vector<string>::const_iterator j=parts.begin(); j!=parts.end(); ++j)
-                       logger.enable_channel(*j);
-       }
+       for(const string &c: log_channels)
+               for(const string &p: split(c, ','))
+                       logger.enable_channel(p);
        builder.set_logger(&logger);
 
        if(!analyze_mode.empty())
@@ -124,7 +121,7 @@ BuilderCLI::BuilderCLI(int argc, char **argv):
        else if(!clean && !create_makefile)
                build = true;
 
-       for(NameList::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); )
+       for(auto i=cmdline_targets.begin(); i!=cmdline_targets.end(); )
        {
                string::size_type equal = i->find('=');
                if(equal!=string::npos)
@@ -154,9 +151,9 @@ BuilderCLI::BuilderCLI(int argc, char **argv):
        list<FS::Path> start_files;
        start_files.push_back(FS::get_sys_data_dir()/"builderrc");
        start_files.push_back(FS::get_user_data_dir()/"rc");
-       for(list<FS::Path>::const_iterator i=start_files.begin(); i!=start_files.end(); ++i)
-               if(FS::exists(*i))
-                       builder.load_build_file(*i);
+       for(const FS::Path &f: start_files)
+               if(FS::exists(f))
+                       builder.load_build_file(f);
 
        if(!prefix.empty())
                builder.set_prefix(cwd/prefix);
@@ -170,7 +167,7 @@ BuilderCLI::BuilderCLI(int argc, char **argv):
        builder.add_default_tools();
 
        const Toolchain &toolchain = builder.get_toolchain();
-       for(Config::InputOptions::iterator i=cmdline_options.begin(); i!=cmdline_options.end(); )
+       for(auto i=cmdline_options.begin(); i!=cmdline_options.end(); )
        {
                if(toolchain.has_tool(i->first))
                {
@@ -233,26 +230,24 @@ int BuilderCLI::main()
 
        BuildGraph &build_graph = builder.get_build_graph();
        PackageManager &package_manager = builder.get_package_manager();
-       const PackageManager::PackageMap &packages = package_manager.get_packages();
        list<string> package_details;
-       for(PackageManager::PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
+       for(const auto &kvp: package_manager.get_packages())
        {
-               if(!i->second->is_prepared())
+               if(!kvp.second->is_prepared())
                        continue;
 
-               string line = i->second->get_name();
-               if(dynamic_cast<SourcePackage *>(i->second))
+               string line = kvp.second->get_name();
+               if(dynamic_cast<SourcePackage *>(kvp.second))
                {
                        line += '*';
 
                        unsigned count = 0;
                        unsigned to_be_built = 0;
-                       const BuildGraph::TargetMap &targets = build_graph.get_targets();
-                       for(BuildGraph::TargetMap::const_iterator j=targets.begin(); j!=targets.end(); ++j)
-                               if(j->second->get_package()==i->second)
+                       for(const auto &kvp2: build_graph.get_targets())
+                               if(kvp2.second->get_package()==kvp.second)
                                {
                                        ++count;
-                                       if(j->second->needs_rebuild())
+                                       if(kvp2.second->needs_rebuild())
                                                ++to_be_built;
                                }
                        if(count)
@@ -268,8 +263,8 @@ int BuilderCLI::main()
        }
 
        logger.log("summary", format("%d active packages, %d targets", package_details.size(), build_graph.get_targets().size()));
-       for(list<string>::const_iterator i=package_details.begin(); i!=package_details.end(); ++i)
-               logger.log("packages", *i);
+       for(const string &d: package_details)
+               logger.log("packages", d);
 
        if(analyzer)
                analyzer->analyze();
@@ -278,8 +273,8 @@ int BuilderCLI::main()
        {
                list<string> problems = builder.collect_problems();
                IO::print(IO::cerr, "The following problems were detected:\n");
-               for(list<string>::const_iterator i=problems.begin(); i!=problems.end(); ++i)
-                       IO::print(IO::cerr, "  %s\n", *i);
+               for(const string &p: problems)
+                       IO::print(IO::cerr, "  %s\n", p);
                if(!analyzer)
                        IO::print(IO::cerr, "Please fix them and try again.\n");
                return 1;
@@ -307,12 +302,12 @@ bool BuilderCLI::prepare_build()
        package_manager.get_main_package().prepare();
 
        // Add targets from command line as goals
-       for(NameList::iterator i=cmdline_targets.begin(); i!=cmdline_targets.end(); ++i)
+       for(const string &t: cmdline_targets)
        {
-               Target *tgt = resolve_target(*i);
+               Target *tgt = resolve_target(t);
                if(!tgt)
                {
-                       IO::print("I don't know anything about %s\n", *i);
+                       IO::print("I don't know anything about %s\n", t);
                        return false;
                }
 
@@ -322,12 +317,12 @@ bool BuilderCLI::prepare_build()
        build_graph.prepare();
 
        // Apply what-ifs
-       for(NameList::iterator i=what_if.begin(); i!=what_if.end(); ++i)
+       for(const string &w: what_if)
        {
-               FileTarget *tgt = dynamic_cast<FileTarget *>(resolve_target(*i));
+               FileTarget *tgt = dynamic_cast<FileTarget *>(resolve_target(w));
                if(!tgt)
                {
-                       IO::print(IO::cerr, "Unknown what-if target %s\n", *i);
+                       IO::print(IO::cerr, "Unknown what-if target %s\n", w);
                        return false;
                }
                tgt->touch();
@@ -367,7 +362,7 @@ void BuilderCLI::package_help()
        if(!requires.empty())
        {
                IO::print("\nRequired packages:\n  ");
-               for(Package::Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i)
+               for(auto i=requires.begin(); i!=requires.end(); ++i)
                {
                        if(i!=requires.begin())
                                IO::print(", ");
@@ -379,19 +374,14 @@ void BuilderCLI::package_help()
        if(!options.empty())
        {
                IO::print("\nPackage configuration:\n");
-               for(Config::OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
+               for(const auto &kvp: options)
                {
-                       const Config::Option &opt = i->second;
+                       const Config::Option &opt = kvp.second;
                        string line = format("  %s: %s (%s)", opt.name, opt.description, opt.value);
                        if(!opt.choices.empty())
                        {
                                line += " {";
-                               for(list<string>::const_iterator j=opt.choices.begin(); j!=opt.choices.end(); ++j)
-                               {
-                                       if(j!=opt.choices.begin())
-                                               line += ' ';
-                                       line += *j;
-                               }
+                               line += join(opt.choices.begin(), opt.choices.end(), " ");
                                line += '}';
                        }
                        else if(opt.value!=opt.default_value)
index 6ae13dcdf304cd5396b02b2a9b3a68bf5af3da0e..a3af685dd9b9cd88ce81d328c744999df0e18027 100644 (file)
@@ -19,8 +19,8 @@ BuildGraph::BuildGraph(Builder &b):
 
 BuildGraph::~BuildGraph()
 {
-       for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
-               delete i->second;
+       for(const auto &kvp: targets)
+               delete kvp.second;
 }
 
 Target *BuildGraph::get_target(const string &n) const
@@ -69,16 +69,16 @@ void BuildGraph::prepare()
 
 void BuildGraph::force_full_rebuild()
 {
-       for(TargetMap::iterator i=targets.begin(); i!=targets.end(); ++i)
-               if(i->second->is_buildable() && !i->second->needs_rebuild())
-                       i->second->force_rebuild();
+       for(const auto &kvp: targets)
+               if(kvp.second->is_buildable() && !kvp.second->needs_rebuild())
+                       kvp.second->force_rebuild();
 }
 
 unsigned BuildGraph::count_rebuild_targets() const
 {
        unsigned count = 0;
-       for(map<string, Target *>::const_iterator i=targets.begin(); i!=targets.end(); ++i)
-               if(i->second->is_buildable() && i->second->needs_rebuild())
+       for(const auto &kvp: targets)
+               if(kvp.second->is_buildable() && kvp.second->needs_rebuild())
                        ++count;
        return count;
 }
index af4865498c5fd61c2105d987f783ff23d21d5466..48b4832bba1139e8209651fa37b97ec5d02a31d9 100644 (file)
@@ -1,5 +1,5 @@
-#include <algorithm>
 #include <set>
+#include <msp/core/algorithm.h>
 #include <msp/strings/format.h>
 #include "buildinfo.h"
 
@@ -14,7 +14,7 @@ template<typename T>
 void unique(list<T> &l)
 {
        set<T> seen;
-       for(typename list<T>::iterator i=l.begin(); i!=l.end(); )
+       for(auto i=l.begin(); i!=l.end(); )
        {
                if(seen.count(*i))
                        l.erase(i++);
@@ -47,22 +47,22 @@ BuildInfo::LibraryMode BuildInfo::get_libmode_for(const string &lib) const
 
 void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
 {
-       for(DefineMap::const_iterator i=bi.defines.begin(); i!=bi.defines.end(); ++i)
-               defines[i->first] = i->second;
+       for(const auto &kvp: bi.defines)
+               defines[kvp.first] = kvp.second;
        incpath.insert(incpath.begin(), bi.incpath.begin(), bi.incpath.end());
        threads = bi.threads;
 
-       for(StandardMap::const_iterator i=bi.standards.begin(); i!=bi.standards.end(); ++i)
+       for(const auto &kvp: bi.standards)
        {
-               StandardMap::iterator j = standards.find(i->first);
+               StandardMap::iterator j = standards.find(kvp.first);
                if(j==standards.end())
-                       standards.insert(*i);
-               else if(i->second.type!=j->second.type || i->second.year!=j->second.year)
+                       standards.insert(kvp);
+               else if(kvp.second.type!=j->second.type || kvp.second.year!=j->second.year)
                {
-                       if(!i->second.type.compare(0, 3, "gnu"))
-                               j->second.type = i->second.type;
-                       if(i->second.year>j->second.year)
-                               j->second.year = i->second.year;
+                       if(!kvp.second.type.compare(0, 3, "gnu"))
+                               j->second.type = kvp.second.type;
+                       if(kvp.second.year>j->second.year)
+                               j->second.year = kvp.second.year;
                }
        }
 
@@ -78,8 +78,8 @@ void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
                local_incpath.insert(local_incpath.begin(), bi.local_incpath.begin(), bi.local_incpath.end());
                libmode = bi.libmode;
                rpath_mode = bi.rpath_mode;
-               for(LibModeMap::const_iterator i=bi.libmodes.begin(); i!=bi.libmodes.end(); ++i)
-                       libmodes[i->first] = i->second;
+               for(const auto &kvp: bi.libmodes)
+                       libmodes[kvp.first] = kvp.second;
                keep_symbols.insert(keep_symbols.end(), bi.keep_symbols.begin(), bi.keep_symbols.end());
                debug = bi.debug;
                optimize = bi.optimize;
@@ -98,10 +98,8 @@ void BuildInfo::update_from(const BuildInfo &bi, UpdateLevel level)
 
 BuildInfo::LanguageStandard::LanguageStandard(const string &std)
 {
-       string::size_type num = string::npos;
-       for(string::size_type i=0; (num==string::npos && i<std.size()); ++i)
-               if(isdigit(static_cast<unsigned char>(std[i])))
-                       num = i;
+       auto i = find_if(std, [](char c){ return isdigit(static_cast<unsigned char>(c)); });
+       string::size_type num = i-std.begin();
        type = std.substr(0, num);
        year = lexical_cast<unsigned>(std.substr(num));
        year += (year<70 ? 2000 : 1900);
index de4643c4bf23abe1f9eb640a90756503d2e3313e..b8c71afc6744d7ef886c8483dabaa9d3f7410612 100644 (file)
@@ -141,13 +141,13 @@ void Cache::save() const
        package.get_builder().get_logger().log("files", format("Writing %s", filename));
        IO::BufferedFile out(filename.str(), IO::M_WRITE);
 
-       for(DataMap::const_iterator i=data.begin(); i!=data.end(); ++i)
+       for(const auto &kvp: data)
        {
-               write_string(out, i->first.first);
-               write_string(out, i->first.second);
-               write_count(out, i->second.size());
-               for(ValueList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
-                       write_string(out, *j);
+               write_string(out, kvp.first.first);
+               write_string(out, kvp.first.second);
+               write_count(out, kvp.second.size());
+               for(const string &v: kvp.second)
+                       write_string(out, v);
        }
 
        changed = false;
index 066dc22c3be1f6aba48a7f68adfefa97dfb67287..a5a6d8632d92d81c838fbf0d8c7114c0c2336461 100644 (file)
@@ -1,6 +1,8 @@
+#include <msp/strings/utils.h>
 #include "chainedtask.h"
 
 using namespace std;
+using namespace Msp;
 
 ChainedTask::ChainedTask(Task *t):
        current(0),
@@ -11,8 +13,8 @@ ChainedTask::ChainedTask(Task *t):
 
 ChainedTask::~ChainedTask()
 {
-       for(vector<Task *>::iterator i=tasks.begin(); i!=tasks.end(); ++i)
-               delete *i;
+       for(Task *t: tasks)
+               delete t;
 }
 
 void ChainedTask::add_task(Task *t)
@@ -23,12 +25,8 @@ void ChainedTask::add_task(Task *t)
 string ChainedTask::get_command() const
 {
        string cmd;
-       for(vector<Task *>::const_iterator i=tasks.begin(); i!=tasks.end(); ++i)
-       {
-               if(i!=tasks.begin())
-                       cmd += '\n';
-               cmd += (*i)->get_command();
-       }
+       for(Task *t: tasks)
+               append(cmd, "\n", t->get_command());
        return cmd;
 }
 
index 07ee15e779245f1f9f901ad063b317c20a9be005..2f4e07b4c2dccdc2d6b62f4d07df9999f7ee7380 100644 (file)
@@ -41,13 +41,12 @@ void CompileCommandsGenerator::Worker::main()
        IO::print(out, "[");
 
        bool first = true;
-       const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets();
-       for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
-               if(i->second->is_buildable() && i->second->get_package()==&spkg)
-                       if(ObjectFile *obj = dynamic_cast<ObjectFile *>(i->second))
+       for(const auto &kvp: builder.get_build_graph().get_targets())
+               if(kvp.second->is_buildable() && kvp.second->get_package()==&spkg)
+                       if(ObjectFile *obj = dynamic_cast<ObjectFile *>(kvp.second))
                        {
                                FS::Path src_path = obj->get_source().get_path();
-                               Task *task = i->second->build();
+                               Task *task = kvp.second->build();
                                if(!first)
                                        out.put(',');
                                IO::print(out, "\n\t{\n");
index a8a1929a70f4e9b16a78f833e18d1cab6a589582..ff24d7ee91eff7e7f985c88d8823d64beb7803de 100644 (file)
@@ -11,8 +11,7 @@ CompileCommandsJson::CompileCommandsJson(Builder &b, const SourcePackage &p):
 
 void CompileCommandsJson::find_dependencies()
 {
-       const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets();
-       for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
-               if(i->second->is_buildable() && i->second->get_package()==package && dynamic_cast<ObjectFile *>(i->second))
-                       i->second->prepare();
+       for(const auto &kvp: builder.get_build_graph().get_targets())
+               if(kvp.second->is_buildable() && kvp.second->get_package()==package && dynamic_cast<ObjectFile *>(kvp.second))
+                       kvp.second->prepare();
 }
index 2d09f8a0cd007ed12f9e7c09d2a1c78cc4670b47..0e183b5fc8039e509a0fecc87e9f4f66a8a138f5 100644 (file)
@@ -1,4 +1,4 @@
-#include <algorithm>
+#include <msp/core/algorithm.h>
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
@@ -19,8 +19,8 @@ Component::Component(SourcePackage &p, const string &n):
 
 void Component::prepare()
 {
-       for(Package::Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i)
-               (*i)->prepare();
+       for(Package *r: requires)
+               r->prepare();
 }
 
 void Component::create_build_info()
@@ -32,27 +32,26 @@ void Component::create_build_info()
        direct_reqs.insert(direct_reqs.end(), pkg_reqs.begin(), pkg_reqs.end());
 
        Package::Requirements all_reqs = direct_reqs;
-       for(Package::Requirements::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
+       for(Package *r: all_reqs)
        {
                BuildInfo::UpdateLevel level = BuildInfo::CHAINED;
-               if(find(direct_reqs.begin(), direct_reqs.end(), *i)!=direct_reqs.end())
+               if(find(direct_reqs.begin(), direct_reqs.end(), r)!=direct_reqs.end())
                        level = BuildInfo::DEPENDENCY;
-               final_build_info.update_from((*i)->get_exported_build_info(), level);
+               final_build_info.update_from(r->get_exported_build_info(), level);
 
-               const Package::Requirements &reqs = (*i)->get_required_packages();
-               for(Package::Requirements::const_iterator j=reqs.begin(); j!=reqs.end(); ++j)
-                       if(find(all_reqs.begin(), all_reqs.end(), *j)==all_reqs.end())
-                               all_reqs.push_back(*j);
+               for(Package *q: r->get_required_packages())
+                       if(find(all_reqs.begin(), all_reqs.end(), q)==all_reqs.end())
+                               all_reqs.push_back(q);
        }
 
        final_build_info.update_from(package.get_build_info());
        final_build_info.update_from(build_info);
        build_info = final_build_info;
 
-       for(BuildInfo::PathList::iterator i=build_info.incpath.begin(); i!=build_info.incpath.end(); ++i)
-               *i = (package.get_source_directory() / *i).str();
-       for(BuildInfo::PathList::iterator i=build_info.libpath.begin(); i!=build_info.libpath.end(); ++i)
-               *i = (package.get_source_directory() / *i).str();
+       for(FS::Path &p: build_info.incpath)
+               p = (package.get_source_directory()/p).str();
+       for(FS::Path &p: build_info.libpath)
+               p = (package.get_source_directory()/p).str();
 }
 
 BuildInfo Component::get_build_info_for_path(const FS::Path &path) const
@@ -76,20 +75,15 @@ BuildInfo Component::get_build_info_for_path(const FS::Path &path) const
        {
                FS::Path dir = FS::dirname(path);
                string last = FS::basename(dir);
-               for(OverlayList::const_iterator i=overlays.begin(); i!=overlays.end(); ++i)
-                       if(last==*i)
-                       {
-                               dir = FS::dirname(dir);
-                               break;
-                       }
+               if(any_equals(overlays, last))
+                       dir = FS::dirname(dir);
 
-               for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
-                       if(dir==*i)
-                       {
-                               binfo.local_incpath.push_back(dir);
-                               for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
-                                       binfo.local_incpath.push_back(*i/ *j);
-                       }
+               if(any_equals(sources, dir))
+               {
+                       binfo.local_incpath.push_back(dir);
+                       for(const string &o: overlays)
+                               binfo.local_incpath.push_back(dir/o);
+               }
        }
        return binfo;
 }
@@ -97,33 +91,31 @@ BuildInfo Component::get_build_info_for_path(const FS::Path &path) const
 Component::SourceList Component::collect_source_files() const
 {
        SourceList files;
-       for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+       for(const FS::Path &p: sources)
        {
-               FS::Path path(*i);
-               if(FS::is_dir(path))
+               if(FS::is_dir(p))
                {
                        SourceList dirs;
-                       dirs.push_back(path);
-                       for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
+                       dirs.push_back(p);
+                       for(const string &o: overlays)
                        {
-                               FS::Path opath = path / *j;
+                               FS::Path opath = p/o;
                                if(FS::is_dir(opath))
                                        dirs.push_back(opath);
                        }
                        set<string> overlay_files;
-                       for(SourceList::const_iterator j=dirs.begin(); j!=dirs.end(); ++j)
+                       for(auto j=dirs.begin(); j!=dirs.end(); ++j)
                        {
                                package.get_builder().get_logger().log("files", format("Traversing %s", *j));
-                               vector<string> sfiles = list_files(*j);
-                               for(vector<string>::iterator k=sfiles.begin(); k!=sfiles.end(); ++k)
+                               for(const string &f: list_files(*j))
                                {
                                        if(j!=dirs.begin())
                                        {
-                                               if(overlay_files.count(*k))
+                                               if(overlay_files.count(f))
                                                        continue;
-                                               overlay_files.insert(*k);
+                                               overlay_files.insert(f);
                                        }
-                                       FS::Path fn = *j / *k;
+                                       FS::Path fn = *j/f;
                                        if(!FS::is_dir(fn))
                                                files.push_back(fn);
                                }
@@ -131,10 +123,10 @@ Component::SourceList Component::collect_source_files() const
                }
                else
                {
-                       files.push_back(path);
-                       for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
+                       files.push_back(p);
+                       for(const string &o: overlays)
                        {
-                               FS::Path opath = FS::dirname(path)/ *j/FS::basename(path);
+                               FS::Path opath = FS::dirname(p)/o/FS::basename(p);
                                if(FS::is_reg(opath))
                                        files.push_back(opath);
                        }
index 36e7870683b3bfed9e1474306ee8adde2ce13a84..3e862ecf0b7c221bf0ee4e5a160266da6b6e7356 100644 (file)
@@ -82,8 +82,8 @@ void Config::save() const
        package.get_builder().get_logger().log("files", format("Writing %s", fn));
        IO::BufferedFile out(fn.str(), IO::M_WRITE);
 
-       for(OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
-               IO::print(out, "option \"%s\" \"%s\";\n", i->second.name, i->second.value);
+       for(const auto &kvp: options)
+               IO::print(out, "option \"%s\" \"%s\";\n", kvp.second.name, kvp.second.value);
 
        changed = false;
 }
index 0034ebd0e564870c6ed101835f52cd130ef42506..954fdba72927c8b4417d177094b2de849e3306c8 100644 (file)
@@ -62,12 +62,9 @@ void CSourceFile::find_dependencies()
        Tool *compiler = builder.get_toolchain().get_tool_for_suffix(FS::extpart(FS::basename(path)), true);
        if(compiler)
                compiler->prepare();
-       for(IncludeList::iterator i=includes.begin(); i!=includes.end(); ++i)
-       {
-               Target *hdr = builder.get_vfs().find_header(i->substr(1), compiler, ((*i)[0]=='"' ? local_incpath : incpath));
-               if(hdr)
+       for(const string &i: includes)
+               if(Target *hdr = builder.get_vfs().find_header(i.substr(1), compiler, (i[0]=='"' ? local_incpath : incpath)))
                        add_transitive_dependency(*hdr);
-       }
 }
 
 void CSourceFile::modified()
index 66e9a042012b9d797cfa866b3a70cd3c7b16da86..c34c9cc7949c1d73c657cdf27c8e2520866f19c9 100644 (file)
@@ -22,7 +22,6 @@ Msp::FS::Path DataCollection::generate_target_path(const Component &comp, const
 void DataCollection::find_dependencies()
 {
        source.prepare();
-       const Target::Dependencies &tdeps = source.get_transitive_dependencies();
-       for(Target::Dependencies::const_iterator i=tdeps.begin(); i!=tdeps.end(); ++i)
-               add_dependency(**i);
+       for(Target *d: source.get_transitive_dependencies())
+               add_dependency(*d);
 }
index 2b3d9f2f363573071a02e199825909bc76cb2a25..cb207d44064bd7d727267bf036cf44f5ba373edd 100644 (file)
@@ -9,8 +9,8 @@ DataPack::DataPack(Builder &b, const Component &c, const list<FileTarget *> &f):
        files(f)
 {
        component = &c;
-       for(list<FileTarget *>::const_iterator i=files.begin(); i!=files.end(); ++i)
-               add_dependency(**i);
+       for(FileTarget *t: files)
+               add_dependency(*t);
 
        install_location = Msp::FS::Path("share")/package->get_name();
 }
index 0b8d020eead41c9c0adc50056f60acca3fff6a47..b95770f4e432891b34c303a375d929042c4d4ece 100644 (file)
@@ -18,19 +18,18 @@ void DataPackComponent::create_targets() const
        Tool &dcomp = builder.get_toolchain().get_tool("DATA");
 
        list<Target *> files;
-       SourceList source_filenames = collect_source_files();
-       for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i)
+       for(const FS::Path &s: collect_source_files())
        {
-               string ext = FS::extpart(FS::basename(*i));
+               string ext = FS::extpart(FS::basename(s));
                if(ext==".mdt")
                {
-                       Target *src = dcomp.create_source(*this, *i);
+                       Target *src = dcomp.create_source(*this, s);
                        files.push_back(dcomp.create_target(*src, "collection"));
                }
-               else if(Target *tgt = builder.get_vfs().get_target(*i))
+               else if(Target *tgt = builder.get_vfs().get_target(s))
                        files.push_back(tgt);
                else
-                       files.push_back(new DataSourceFile(builder, *this, *i));
+                       files.push_back(new DataSourceFile(builder, *this, s));
        }
 
        Target *result = dcomp.create_target(files, "pack");
index 75ec2da7b750998d77395ba6ba57e8d77afd87a0..ca2f2e49aaef3738cd2bf2c12171af03d902c746 100644 (file)
@@ -38,8 +38,8 @@ Target *DataTool::create_target(const list<Target *> &sources, const string &arg
        else if(arg=="pack")
        {
                list<FileTarget *> files;
-               for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
-                       files.push_back(&dynamic_cast<FileTarget &>(**i));
+               for(Target *t: sources)
+                       files.push_back(&dynamic_cast<FileTarget &>(*t));
                DataPack *pack = new DataPack(builder, *files.front()->get_component(), files);
                pack->set_tool(*this);
                return pack;
@@ -92,9 +92,8 @@ Task *DataTool::run(const Target &tgt) const
        else if(const DataPack *pack = dynamic_cast<const DataPack *>(&tgt))
        {
                argv.push_back("-p");
-               const DataPack::FileList &files = pack->get_files();
-               for(DataPack::FileList::const_iterator i=files.begin(); i!=files.end(); ++i)
-                       argv.push_back(FS::relative((*i)->get_path(), work_dir).str());
+               for(const FileTarget *f: pack->get_files())
+                       argv.push_back(FS::relative(f->get_path(), work_dir).str());
        }
 
        return new ExternalTask(argv, work_dir);
index 7b221b3c0bc7e16c4cf4088873d12770bfced578..4f5806c4bf79aa2bae99410c2287c38d4897e57e 100644 (file)
@@ -49,12 +49,12 @@ void DataTransform::find_dependencies()
                                        dir_files = list_files(dir);
                                }
 
-                               for(DataFile::Statement::Arguments::const_iterator i=st.args.begin(); i!=st.args.end(); ++i)
+                               for(const DataFile::Value &a: st.args)
                                {
-                                       Regex re(i->get<string>());
-                                       for(vector<string>::const_iterator j=dir_files.begin(); j!=dir_files.end(); ++j)
-                                               if(re.match(*j))
-                                                       files.push_back(*j);
+                                       Regex re(a.get<string>());
+                                       for(const string &f: dir_files)
+                                               if(re.match(f))
+                                                       files.push_back(f);
                                }
                        }
                        else if(st.keyword=="file" && st.args.size()==1)
@@ -64,9 +64,9 @@ void DataTransform::find_dependencies()
                cache.set_values(this, "files", files);
        }
 
-       for(list<string>::iterator i=files.begin(); i!=files.end(); ++i)
+       for(const string &f: files)
        {
-               FS::Path file_path = FS::dirname(path)/ *i;
+               FS::Path file_path = FS::dirname(path)/f;
                if(Target *tgt = builder.get_vfs().get_target(file_path))
                        add_transitive_dependency(*tgt);
                else
index 7e497211ce77fbe2c7cfb7258a37503a36e2d70a..1af76034e5e8c9a4d0be81c9c434c0c050cb7a26 100644 (file)
@@ -10,8 +10,8 @@ ExportDefinitions::ExportDefinitions(Builder &b, const Component &c, const list<
        FileTarget(b, c.get_package(), generate_target_path(c))
 {
        component = &c;
-       for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
-               add_dependency(**i);
+       for(ObjectFile *o: objs)
+               add_dependency(*o);
 }
 
 FS::Path ExportDefinitions::generate_target_path(const Component &comp)
index 16d1df096dd4a23eee3f60b2e54a8cf289de9884..33ffcebc4622889eaed085e371cc19fbb8a348df 100644 (file)
@@ -31,16 +31,16 @@ ExternalTask::~ExternalTask()
 string ExternalTask::get_command() const
 {
        string cmd;
-       for(vector<string>::const_iterator i=argv.begin(); i!=argv.end(); ++i)
+       for(const string &a: argv)
        {
-               if(i!=argv.begin())
+               if(!cmd.empty())
                        cmd += ' ';
 
-               for(string::const_iterator j=i->begin(); j!=i->end(); ++j)
+               for(char c: a)
                {
-                       if(*j=='"' || *j=='\'' || *j==' ' || *j=='\\' || *j=='&')
+                       if(c=='"' || c=='\'' || c==' ' || c=='\\' || c=='&')
                                cmd += '\\';
-                       cmd += *j;
+                       cmd += c;
                }
        }
 
index 51a92d13b1a11f61c34671a1d8c39adfa710bdcc..493f0203ee4f155a6e31a5e821a1a1a72c510c35 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
 #include <msp/strings/format.h>
@@ -79,22 +80,24 @@ void FileTarget::check_rebuild()
                mark_rebuild("Does not exist");
        else
        {
-               for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i)
+               for(Target *d: depends)
                {
-                       FileTarget *ft = dynamic_cast<FileTarget *>(*i);
+                       FileTarget *ft = dynamic_cast<FileTarget *>(d);
                        if(ft && ft->get_mtime()>mtime)
-                               mark_rebuild((*i)->get_name()+" has changed");
-                       else if((*i)->needs_rebuild())
-                               mark_rebuild((*i)->get_name()+" needs rebuilding");
+                               mark_rebuild(d->get_name()+" has changed");
+                       else if(d->needs_rebuild())
+                               mark_rebuild(d->get_name()+" needs rebuilding");
+                       if(needs_rebuild())
+                               break;
                }
        }
 
        if(!needs_rebuild())
        {
                // Some side effects might not exist
-               for(Dependencies::iterator i=side_effects.begin(); (i!=side_effects.end() && !needs_rebuild()); ++i)
-                       if((*i)->needs_rebuild())
-                               mark_rebuild((*i)->get_name()+" needs rebuilding");
+               auto i = find_if(side_effects, [](const Target *s){ return s->needs_rebuild(); });
+               if(i!=side_effects.end())
+                       mark_rebuild((*i)->get_name()+" needs rebuilding");
        }
 
        if(!needs_rebuild() && package)
@@ -124,12 +127,12 @@ string FileTarget::create_build_signature() const
        if(nested_build_sig && component)
        {
                set<const Tool *> depend_tools;
-               for(Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
-                       if((*i)->get_component()==component && (*i)->get_tool())
-                               depend_tools.insert((*i)->get_tool());
+               for(Target *d: depends)
+                       if(d->get_component()==component && d->get_tool())
+                               depend_tools.insert(d->get_tool());
 
-               for(set<const Tool *>::const_iterator i=depend_tools.begin(); i!=depend_tools.end(); ++i)
-                       sigs.push_back((*i)->create_build_signature(binfo));
+               for(const Tool *t: depend_tools)
+                       sigs.push_back(t->create_build_signature(binfo));
                sigs.sort();
                sigs.push_front(tool->create_build_signature(binfo));
        }
index 170007028a5201f26bf64160402a2bab3f8bebd7..7e79ec08d7749efab9a52567df947b2fdf64f545 100644 (file)
@@ -27,9 +27,9 @@ Target *GnuArchiver::create_target(const list<Target *> &sources, const string &
                throw invalid_argument("GnuArchiver::create_target");
 
        list<ObjectFile *> objs;
-       for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+       for(Target *s: sources)
        {
-               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(s))
                        objs.push_back(obj);
                else
                        throw invalid_argument("GnuArchiver::create_target");
@@ -59,9 +59,8 @@ Task *GnuArchiver::run(const Target &target) const
 
        argv.push_back(relative(lib.get_path(), work_dir).str());
 
-       const Target::Dependencies &deps = lib.get_dependencies();
-       for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
-               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+       for(Target *d: lib.get_dependencies())
+               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(d))
                        argv.push_back(relative(obj->get_path(), work_dir).str());
 
        return new ExternalTask(argv, work_dir);
index 2752ff4ed969db58745094d0d38249c752fa976b..3903c6a079983975fa42cc468c6552fd32cf1a4f 100644 (file)
@@ -254,20 +254,20 @@ Task *GnuCompiler::run(const Target &target) const
        const FS::Path &sysroot = binfo.sysroot;
        if(!sysroot.empty())
                argv.push_back("--sysroot="+sysroot.str());
-       for(BuildInfo::PathList::const_iterator i=binfo.local_incpath.begin(); i!=binfo.local_incpath.end(); ++i)
+       for(const FS::Path &p: binfo.local_incpath)
        {
                argv.push_back("-iquote");
-               argv.push_back(i->str());
+               argv.push_back(p.str());
        }
-       for(BuildInfo::PathList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
-               argv.push_back("-I"+i->str());
+       for(const FS::Path &p: binfo.incpath)
+               argv.push_back("-I"+p.str());
 
-       for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
+       for(const auto &kvp: binfo.defines)
        {
-               if(i->second.empty())
-                       argv.push_back(format("-D%s", i->first));
+               if(kvp.second.empty())
+                       argv.push_back(format("-D%s", kvp.first));
                else
-                       argv.push_back(format("-D%s=%s", i->first, i->second));
+                       argv.push_back(format("-D%s=%s", kvp.first, kvp.second));
        }
 
        if(binfo.debug)
index 2d37a4d93533b4486d865a043f691f3725ff4aa5..c592cc86cf1e7bd888eefa753957f5988bea2e0b 100644 (file)
@@ -45,9 +45,9 @@ Target *GnuLinker::create_target(const list<Target *> &sources, const string &ar
                throw invalid_argument("GnuLinker::create_target");
        list<ObjectFile *> objs;
        Linker *linker = default_linker;
-       for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+       for(Target *s: sources)
        {
-               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(s))
                {
                        objs.push_back(obj);
                        if(obj->get_tool()->get_tag()=="CXX")
@@ -280,8 +280,8 @@ Task *GnuLinker::Linker::run(const Target &target) const
                argv.push_back("-Wl,-rpath-link,"+lib_dir.str());
        }
 
-       for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
-               argv.push_back("-L"+i->str());
+       for(const FS::Path &p: binfo.libpath)
+               argv.push_back("-L"+p.str());
        if(binfo.strip)
                argv.push_back("-s");
        if(binfo.threads && architecture->get_system()!="windows" && architecture->get_system()!="darwin")
@@ -294,16 +294,15 @@ Task *GnuLinker::Linker::run(const Target &target) const
        argv.push_back("-o");
        argv.push_back(relative(bin.get_path(), work_dir).str());
 
-       for(BuildInfo::WordList::const_iterator i=binfo.keep_symbols.begin(); i!=binfo.keep_symbols.end(); ++i)
-               argv.push_back("-u"+*i);
+       for(const string &s: binfo.keep_symbols)
+               argv.push_back("-u"+s);
 
        bool static_link_ok = (binfo.libmode<=BuildInfo::STATIC);
 
-       const Target::Dependencies &depends = target.get_dependencies();
-       for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
+       for(Target *d: target.get_dependencies())
        {
-               FileTarget *file = dynamic_cast<FileTarget *>(*i);
-               Target *tgt = (*i)->get_real_target();
+               FileTarget *file = dynamic_cast<FileTarget *>(d);
+               Target *tgt = d->get_real_target();
 
                if(ObjectFile *obj = dynamic_cast<ObjectFile *>(tgt))
                        argv.push_back(relative(obj->get_path(), work_dir).str());
@@ -325,11 +324,11 @@ Task *GnuLinker::Linker::run(const Target &target) const
                }
        }
 
-       for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
-               if(i->size()>10 && !i->compare(i->size()-10, 10, ".framework"))
+       for(const string &l: binfo.libs)
+               if(l.size()>10 && !l.compare(l.size()-10, 10, ".framework"))
                {
                        argv.push_back("-framework");
-                       argv.push_back(i->substr(0, i->size()-10));
+                       argv.push_back(l.substr(0, l.size()-10));
                }
 
        if(static_link_ok)
index ed3c191cd7769a1cb95ca77d5f2fb99adab9a41d..319053f0ba42bbfbbf7c27fc0a112a63b2d6ac75 100644 (file)
@@ -5,6 +5,7 @@
 #include "tool.h"
 
 using namespace std;
+using namespace Msp;
 
 InstallComponent::InstallComponent(SourcePackage &p, const string &n):
        Component(p, n)
@@ -16,12 +17,11 @@ void InstallComponent::create_targets() const
        Target *inst = builder.get_build_graph().get_target("install");
        Tool &copy = builder.get_toolchain().get_tool("CP");
 
-       SourceList source_filenames = collect_source_files();
-       for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i)
+       for(const FS::Path &s: collect_source_files())
        {
-               Target *tgt = builder.get_vfs().get_target(*i);
+               Target *tgt = builder.get_vfs().get_target(s);
                if(!tgt)
-                       tgt = new File(builder, package, *i);
+                       tgt = new File(builder, package, s);
                inst->add_dependency(*copy.create_target(*tgt, name));
        }
 }
index 8f1995bc905c3a4a6d38dfea113958570191712e..448f997b2e0822381707238e556be304a7c808d2 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/fs/utils.h>
 #include "component.h"
 #include "filetarget.h"
@@ -23,11 +24,9 @@ FS::Path InstallMap::get_install_location(const FileTarget &target) const
        if(comp && !comp->get_overlays().empty())
        {
                // Check if the target resides in an overlay directory
-               const Component::OverlayList &overlays = comp->get_overlays();
                string last_dir = FS::basename(FS::dirname(target.get_path()));
-               for(Component::OverlayList::const_iterator i=overlays.begin(); i!=overlays.end(); ++i)
-                       if(last_dir==*i)
-                               overlay_depth = 1;
+               if(any_equals(comp->get_overlays(), last_dir))
+                       overlay_depth = 1;
        }
 
        FS::Path source = target.get_path();
@@ -40,9 +39,8 @@ FS::Path InstallMap::get_install_location(const FileTarget &target) const
                if(temp_depth>0)
                {
                        // If it is, use the generating template's directory instead
-                       const Target::Dependencies &deps = target.get_dependencies();
-                       for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
-                               if(const TemplateFile *tmpl = dynamic_cast<const TemplateFile *>(*i))
+                       for(Target *d: target.get_dependencies())
+                               if(const TemplateFile *tmpl = dynamic_cast<const TemplateFile *>(d))
                                {
                                        source = FS::dirname(tmpl->get_path())/FS::basename(source);
                                        break;
@@ -53,15 +51,15 @@ FS::Path InstallMap::get_install_location(const FileTarget &target) const
        /* Look for a mapping entry matching both the target's original location
        and default install location */
        FS::Path install = target.get_install_location();
-       for(list<Entry>::const_iterator i=entries.begin(); i!=entries.end(); ++i)
+       for(const Entry &e: entries)
        {
-               int source_depth = FS::descendant_depth(source, i->source);
+               int source_depth = FS::descendant_depth(source, e.source);
                if(source_depth>=0)
                {
-                       FS::Path install_base = FS::common_ancestor(install, i->install);
+                       FS::Path install_base = FS::common_ancestor(install, e.install);
                        if(install_base.size()>1)
                        {
-                               install = i->install/source.subpath(i->source.size(), source_depth-1-overlay_depth);
+                               install = e.install/source.subpath(e.source.size(), source_depth-1-overlay_depth);
                                break;
                        }
                }
index 03babd4126e09df7ff8869f5da214807094fb530..dc9022e12378c06b56016fbb00e12a0596beb3b1 100644 (file)
@@ -28,9 +28,8 @@ Target *MingwDllTool::create_target(const list<Target *> &sources, const string
        SharedLibrary &shlib = dynamic_cast<SharedLibrary &>(*sources.front());
 
        list<ObjectFile *> objs;
-       const Target::Dependencies &depends = shlib.get_dependencies();
-       for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
-               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+       for(Target *d: shlib.get_dependencies())
+               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(d))
                        objs.push_back(obj);
 
        ExportDefinitions *exp = new ExportDefinitions(builder, *shlib.get_component(), objs);
@@ -100,12 +99,9 @@ Task *MingwDllTool::run(const Target &target) const
        }
        else
        {
-               const Target::Dependencies &depends = exp->get_dependencies();
-               for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
-               {
-                       if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+               for(Target *d: exp->get_dependencies())
+                       if(ObjectFile *obj = dynamic_cast<ObjectFile *>(d))
                                argv.push_back(relative(obj->get_path(), work_dir).str());
-               }
 
                // XXX Should use dllexport, but that has some other problems to solve
                argv.push_back("--export-all-symbols");
index 1481184d52673adb19dae15e020b623410aa7b30..a724eb16577ae0eb9638a9287b485073fa14a227 100644 (file)
@@ -25,9 +25,9 @@ Target *MsvcArchiver::create_target(const list<Target *> &sources, const string
                throw invalid_argument("MsvcArchiver::create_target");
 
        list<ObjectFile *> objs;
-       for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+       for(Target *s: sources)
        {
-               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(s))
                        objs.push_back(obj);
                else
                        throw invalid_argument("MsvcArchiver::create_target");
@@ -57,9 +57,8 @@ Task *MsvcArchiver::run(const Target &target) const
 
        argv.push_back("/OUT:"+relative(lib.get_path(), work_dir).str());
 
-       const Target::Dependencies &deps = lib.get_dependencies();
-       for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
-               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+       for(Target *d: lib.get_dependencies())
+               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(d))
                        argv.push_back(relative(obj->get_path(), work_dir).str());
 
        return new ExternalTask(argv, work_dir);
index 0e1a1f4e94158136737a077bb17d7362d6036875..c676790eb4fddbb126c16fad464f310dafbb9233 100644 (file)
@@ -84,10 +84,10 @@ void MsvcCompiler::do_prepare()
        system_path.push_back(win_sdk_dir/"include"/win_sdk_ver/"um");
 
        string path;
-       for(SearchPath::const_iterator i=system_path.begin(); i!=system_path.end(); ++i)
+       for(const FS::Path &p: system_path)
        {
-               append(path, ";", i->str());
-               builder.get_logger().log("tools", format("Got %s system path: %s", tag, *i));
+               append(path, ";", p.str());
+               builder.get_logger().log("tools", format("Got %s system path: %s", tag, p));
        }
 
        setenv("INCLUDE", path);
@@ -130,24 +130,24 @@ Task *MsvcCompiler::run(const Target &target) const
        else
                argv.push_back("/w");
 
-       for(BuildInfo::PathList::const_iterator i=binfo.local_incpath.begin(); i!=binfo.local_incpath.end(); ++i)
+       for(const FS::Path &p: binfo.local_incpath)
        {
                argv.push_back("/I");
-               argv.push_back(i->str());
+               argv.push_back(p.str());
        }
-       for(BuildInfo::PathList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
+       for(const FS::Path &p: binfo.incpath)
        {
                argv.push_back("/I");
-               argv.push_back(i->str());
+               argv.push_back(p.str());
        }
 
-       for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
+       for(const auto &kvp: binfo.defines)
        {
                argv.push_back("/D");
-               if(i->second.empty())
-                       argv.push_back(i->first);
+               if(kvp.second.empty())
+                       argv.push_back(kvp.first);
                else
-                       argv.push_back(format("%s=%s", i->first, i->second));
+                       argv.push_back(format("%s=%s", kvp.first, kvp.second));
        }
 
        if(binfo.debug)
index 46d89f7194a5565692b0a1c032f0d2a206180cc2..49744288fcc1ffaefb4e57a4eec29430646fe741 100644 (file)
@@ -35,9 +35,9 @@ Target *MsvcLinker::create_target(const list<Target *> &sources, const string &a
                throw invalid_argument("MsvcLinker::create_target");
 
        list<ObjectFile *> objs;
-       for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
+       for(Target *s: sources)
        {
-               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(*i))
+               if(ObjectFile *obj = dynamic_cast<ObjectFile *>(s))
                        objs.push_back(obj);
                else
                        throw invalid_argument("MsvcLinker::create_target");
@@ -80,10 +80,10 @@ void MsvcLinker::do_prepare()
        system_path.push_back(win_sdk_dir/"lib"/win_sdk_ver/"um"/arch_dir);
 
        string path;
-       for(SearchPath::const_iterator i=system_path.begin(); i!=system_path.end(); ++i)
+       for(const FS::Path &p: system_path)
        {
-               append(path, ";", i->str());
-               builder.get_logger().log("tools", format("Got %s system path: %s", tag, *i));
+               append(path, ";", p.str());
+               builder.get_logger().log("tools", format("Got %s system path: %s", tag, p));
        }
 
        setenv("LIB", path);
@@ -105,8 +105,8 @@ Task *MsvcLinker::run(const Target &target) const
        BuildInfo binfo;
        target.collect_build_info(binfo);
 
-       /*for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
-               argv.push_back("/LIBPATH:"+i->str());*/
+       /*for(const FS::Path &p: binfo.libpath)
+               argv.push_back("/LIBPATH:"+p.str());*/
        if(binfo.strip)
                argv.push_back("/INCREMENTAL:NO");
        else
@@ -114,11 +114,10 @@ Task *MsvcLinker::run(const Target &target) const
 
        argv.push_back("/OUT:"+relative(bin.get_path(), work_dir).str());
 
-       const Target::Dependencies &depends = target.get_dependencies();
-       for(Target::Dependencies::const_iterator i=depends.begin(); i!=depends.end(); ++i)
+       for(Target *d: target.get_dependencies())
        {
-               FileTarget *file = dynamic_cast<FileTarget *>(*i);
-               Target *tgt = (*i)->get_real_target();
+               FileTarget *file = dynamic_cast<FileTarget *>(d);
+               Target *tgt = d->get_real_target();
 
                if(ObjectFile *obj = dynamic_cast<ObjectFile *>(tgt))
                        argv.push_back(relative(obj->get_path(), work_dir).str());
index 8196ef7f2c39ac5d1c2da5d3f4c998debcde7484..f78686e3bd999d2bff52ad5c27b53fe367c6fc88 100644 (file)
@@ -1,4 +1,4 @@
-#include <algorithm>
+#include <msp/core/algorithm.h>
 #include <msp/fs/utils.h>
 #include "builder.h"
 #include "component.h"
@@ -28,12 +28,12 @@ FS::Path ObjectFile::generate_target_path(const Component &comp, const FS::Path
        else
                rel_src = FS::relative(src, pkg.get_source_directory());
        string fn;
-       for(FS::Path::Iterator i=rel_src.begin(); i!=rel_src.end(); ++i)
+       for(const string &c: rel_src)
        {
                if(!fn.empty())
                        fn += '_';
-               if(*i!=".")
-                       fn += *i;
+               if(c!=".")
+                       fn += c;
        }
        const Architecture &arch = comp.get_package().get_builder().get_current_arch();
        return temp_dir/comp.get_name()/arch.create_filename<ObjectFile>(FS::basepart(fn));
@@ -52,10 +52,10 @@ void ObjectFile::collect_build_info(BuildInfo &binfo) const
 
 void ObjectFile::find_dependencies()
 {
-       for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
+       for(Target *d: depends)
        {
-               (*i)->prepare();
-               find_dependencies(dynamic_cast<FileTarget *>(*i));
+               d->prepare();
+               find_dependencies(dynamic_cast<FileTarget *>(d));
        }
 }
 
@@ -76,9 +76,9 @@ void ObjectFile::find_dependencies(FileTarget *tgt)
                /* The target has been displaced by installing it.  Displace any
                dependencies that come from the same package as well. */
                const SourcePackage *tpkg = rtgt->get_package();
-               for(Dependencies::const_iterator i=tdeps.begin(); i!=tdeps.end(); ++i)
+               for(Target *d: tdeps)
                {
-                       FileTarget *file = dynamic_cast<FileTarget *>(*i);
+                       FileTarget *file = dynamic_cast<FileTarget *>(d);
                        if(file && file->get_package()==tpkg && FS::descendant_depth(file->get_path(), tpkg->get_source_directory())>=0)
                        {
                                const Component *tcomp = file->get_component();
@@ -88,27 +88,25 @@ void ObjectFile::find_dependencies(FileTarget *tgt)
                                        deps_to_add.push_back(ddep);
                                else
                                {
-                                       const Component::OverlayList &overlays = tcomp->get_overlays();
                                        string last_dir = FS::basename(FS::dirname(displaced));
-                                       for(Component::OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
-                                               if(last_dir==*j)
-                                               {
-                                                       displaced = displaced.subpath(0, displaced.size()-2)/FS::basename(file->get_path());
-                                                       if((ddep = builder.get_vfs().get_target(displaced)))
-                                                               deps_to_add.push_back(ddep);
-                                               }
+                                       if(any_equals(tcomp->get_overlays(), last_dir))
+                                       {
+                                               displaced = displaced.subpath(0, displaced.size()-2)/FS::basename(file->get_path());
+                                               if((ddep = builder.get_vfs().get_target(displaced)))
+                                                       deps_to_add.push_back(ddep);
+                                       }
                                }
                        }
                        else
-                               deps_to_add.push_back(*i);
+                               deps_to_add.push_back(d);
                }
        }
 
-       for(Dependencies::const_iterator i=deps_to_add.begin(); i!=deps_to_add.end(); ++i)
-               if(find(depends.begin(), depends.end(), *i)==depends.end())
+       for(Target *d: deps_to_add)
+               if(find(depends.begin(), depends.end(), d)==depends.end())
                {
-                       add_dependency(**i);
-                       if((*i)->get_real_target()->is_buildable())
-                               (*i)->signal_modified.connect(sigc::mem_fun(this, static_cast<void (ObjectFile::*)()>(&ObjectFile::find_dependencies)));
+                       add_dependency(*d);
+                       if(d->get_real_target()->is_buildable())
+                               d->signal_modified.connect(sigc::mem_fun(this, static_cast<void (ObjectFile::*)()>(&ObjectFile::find_dependencies)));
                }
 }
index e16cd37aa592617a47de4e605d29462170d19896..6e570c8628eb07f5d1bef95190bc1c539b2454d9 100644 (file)
@@ -20,8 +20,8 @@ void Package::prepare()
        if(prepared)
                return;
 
-       for(Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i)
-               (*i)->prepare();
+       for(Package *r: requires)
+               r->prepare();
 
        do_prepare();
        prepared = true;
index 35c752e8e4e056d979e1b55d536f94e66219ea04..f54606f42f1639e09b0e91e11a2b02ecbfd15593 100644 (file)
@@ -1,4 +1,5 @@
 #include <cstdlib>
+#include <msp/core/algorithm.h>
 #include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
@@ -25,8 +26,8 @@ PackageManager::PackageManager(Builder &b):
 
 PackageManager::~PackageManager()
 {
-       for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i)
-               delete i->second;
+       for(const auto &kvp: packages)
+               delete kvp.second;
 }
 
 void PackageManager::append_package_path(const FS::Path &p)
@@ -135,10 +136,7 @@ string PackageManager::run_pkgconfig(const string &pkg, const string &what)
                        if(const char *pcp = getenv("PKG_CONFIG_PATH"))
                        {
                                vector<string> path = split(pcp, ':');
-                               bool found = false;
-                               for(vector<string>::const_iterator i=path.begin(); (!found && i!=path.end()); ++i)
-                                       found = (*i==pcdir.str());
-                               if(!found)
+                               if(!any_equals(path, pcdir.str()))
                                {
                                        path.push_back(pcdir.str());
                                        setenv("PKG_CONFIG_PATH", join(path.begin(), path.end(), ":").c_str(), true);
@@ -190,14 +188,13 @@ FS::Path PackageManager::get_package_location(const string &name)
 
        if(pkg_dirs.empty())
        {
-               for(SearchPath::const_iterator i=pkg_path.begin(); i!=pkg_path.end(); ++i)
+               for(const FS::Path &p: pkg_path)
                {
-                       builder.get_logger().log("files", format("Traversing %s", *i));
-                       vector<string> files = list_files(*i);
+                       builder.get_logger().log("files", format("Traversing %s", p));
                        unsigned count = 0;
-                       for(vector<string>::const_iterator j=files.begin(); j!=files.end(); ++j)
+                       for(const string &f: list_files(p))
                        {
-                               FS::Path full = *i / *j;
+                               FS::Path full = p/f;
                                if(FS::exists(full/"Build"))
                                {
                                        pkg_dirs.push_back(full);
@@ -205,22 +202,22 @@ FS::Path PackageManager::get_package_location(const string &name)
                                }
                        }
 
-                       builder.get_logger().log("packagemgr", format("%d source packages found in %s", count, *i));
+                       builder.get_logger().log("packagemgr", format("%d source packages found in %s", count, p));
                }
 
                builder.get_logger().log("packagemgr", format("%d source packages found", pkg_dirs.size()));
        }
 
        bool msp = !name.compare(0, 3, "msp");
-       for(SearchPath::const_iterator i=pkg_dirs.begin(); i!=pkg_dirs.end(); ++i)
+       for(const FS::Path &p: pkg_dirs)
        {
-               string base = FS::basename(*i);
+               string base = FS::basename(p);
                unsigned dash = base.rfind('-');
 
                if(!base.compare(0, dash, name))
-                       return *i;
+                       return p;
                else if(msp && !base.compare(0, dash, name, 3, string::npos))
-                       return *i;
+                       return p;
        }
 
        return FS::Path();
@@ -232,30 +229,27 @@ FS::Path PackageManager::get_binary_package_file(const string &name)
 
        if(binpkg_files.empty())
        {
-               for(list<FS::Path>::const_iterator i=binpkg_path.begin(); i!=binpkg_path.end(); ++i)
+               for(const FS::Path &p: binpkg_path)
                {
-                       builder.get_logger().log("files", format("Traversing %s", *i));
-                       vector<string> files = list_filtered(*i, "\\.bpk$");
-                       for(vector<string>::const_iterator j=files.begin(); j!=files.end(); ++j)
-                               binpkg_files.push_back(*i / *j);
-                       builder.get_logger().log("packagemgr", format("%d binary packages found in %s", files.size(), *i));
+                       builder.get_logger().log("files", format("Traversing %s", p));
+                       vector<string> files = list_filtered(p, "\\.bpk$");
+                       for(const string &f: files)
+                               binpkg_files.push_back(p/f);
+                       builder.get_logger().log("packagemgr", format("%d binary packages found in %s", files.size(), p));
                }
 
                builder.get_logger().log("packagemgr", format("%d binary packages found", binpkg_files.size()));
        }
 
-       for(SearchPath::const_iterator i=binpkg_files.begin(); i!=binpkg_files.end(); ++i)
-       {
-               string base = FS::basepart(FS::basename(*i));
-               if(base==name)
-                       return *i;
-       }
+       auto i = find_if(binpkg_files, [&name](const FS::Path &p){ return FS::basepart(FS::basename(p))==name; });
+       if(i!=binpkg_files.end())
+               return *i;
 
        return FS::Path();
 }
 
 void PackageManager::save_all_caches() const
 {
-       for(PackageMap::const_iterator i=packages.begin(); i!=packages.end(); ++i)
-               i->second->save_caches();
+       for(const auto &kvp: packages)
+               kvp.second->save_caches();
 }
index 91929f62b0c85a541361af63bc3102b9641d1eba..d910f196276c142dac8b0f573522c4140d409286 100644 (file)
@@ -25,7 +25,7 @@ string Pattern::apply(const string &body) const
 list<string> Pattern::apply_list(const list<Pattern> &patterns, const string &body)
 {
        list<string> result;
-       for(list<Pattern>::const_iterator i=patterns.begin(); i!=patterns.end(); ++i)
-               result.push_back(i->apply(body));
+       for(const Pattern &p: patterns)
+               result.push_back(p.apply(body));
        return result;
 }
index 949a4df589747e7da8b64ec0cc39f53544ba8db0..e9320448b3508a201676eb783ddf2b8d73b87cd2 100644 (file)
@@ -44,30 +44,29 @@ void PkgConfigGenerator::Worker::main()
        IO::print(out, "Version: %s\n", spkg.get_version());
 
        IO::print(out, "Requires:");
-       const Package::Requirements &reqs = spkg.get_required_packages();
-       for(Package::Requirements::const_iterator i=reqs.begin(); i!=reqs.end(); ++i)
-               if((*i)->uses_pkgconfig())
-                       IO::print(out, " %s", (*i)->get_name());
+       for(const Package *r: spkg.get_required_packages())
+               if(r->uses_pkgconfig())
+                       IO::print(out, " %s", r->get_name());
        out.put('\n');
 
        const BuildInfo &binfo = spkg.get_exported_build_info();
        IO::print(out, "Libs:");
-       for(BuildInfo::PathList::const_iterator i=binfo.libpath.begin(); i!=binfo.libpath.end(); ++i)
-               IO::print(out, " -L%s", prefixify(*i, builder.get_prefix()));
-       for(BuildInfo::WordList::const_iterator i=binfo.libs.begin(); i!=binfo.libs.end(); ++i)
-               IO::print(out, " -l%s", *i);
+       for(const FS::Path &p: binfo.libpath)
+               IO::print(out, " -L%s", prefixify(p, builder.get_prefix()));
+       for(const string &l: binfo.libs)
+               IO::print(out, " -l%s", l);
        if(binfo.threads)
                out.write("-pthread");
        out.put('\n');
 
        IO::print(out, "Cflags:");
-       for(BuildInfo::PathList::const_iterator i=binfo.incpath.begin(); i!=binfo.incpath.end(); ++i)
-               IO::print(out, " -I%s", prefixify(*i, builder.get_prefix()));
-       for(BuildInfo::DefineMap::const_iterator i=binfo.defines.begin(); i!=binfo.defines.end(); ++i)
-               if(i->second.empty())
-                       IO::print(out, " -D%s", i->first);
+       for(const FS::Path &p: binfo.incpath)
+               IO::print(out, " -I%s", prefixify(p, builder.get_prefix()));
+       for(const auto &kvp: binfo.defines)
+               if(kvp.second.empty())
+                       IO::print(out, " -D%s", kvp.first);
                else
-                       IO::print(out, " -D%s=%s", i->first, i->second);
+                       IO::print(out, " -D%s=%s", kvp.first, kvp.second);
        out.put('\n');
 
        status = Task::SUCCESS;
index 5e479f3c9f652f64c03a9ab3eb472ae645c807ed..a6e8239524c91fb9775620ac41445d2e08395e8b 100644 (file)
@@ -48,8 +48,8 @@ SharedLibrary::SharedLibrary(Builder &b, const Component &c, const list<ObjectFi
                }
        }
 
-       for(list<ObjectFile *>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
-               (*i)->set_used_in_shared_library(true);
+       for(ObjectFile *o: objects)
+               o->set_used_in_shared_library(true);
 }
 
 string SharedLibrary::generate_filename(const Component &comp)
index 3304e6badff7df162d6a76d77f878d5cdc68b06c..fdf82e53bafb1a966fe56db064d0dfba9f3ef6ff 100644 (file)
@@ -6,6 +6,7 @@
 #include "tool.h"
 
 using namespace std;
+using namespace Msp;
 
 SourceArchiveComponent::SourceArchiveComponent(SourcePackage &p):
        Component(p, p.get_name()+"-source")
@@ -18,21 +19,19 @@ void SourceArchiveComponent::create_targets() const
        list<Target *> files;
        files.insert(files.begin(), &package.get_build_file());
 
-       SourceList source_filenames = collect_source_files();
-       for(SourceList::const_iterator i=source_filenames.begin(); i!=source_filenames.end(); ++i)
+       for(const FS::Path &s: collect_source_files())
        {
-               FileTarget *file = builder.get_vfs().get_target(*i);
+               FileTarget *file = builder.get_vfs().get_target(s);
                if(!file)
-                       file = new File(builder, package, *i);
+                       file = new File(builder, package, s);
                files.push_back(file);
        }
 
        BuildGraph &build_graph = builder.get_build_graph();
-       const BuildGraph::TargetMap &targets = build_graph.get_targets();
-       for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
-               if(i->second->get_package()==&package && !i->second->is_buildable())
-                       if(find(files.begin(), files.end(), i->second)==files.end())
-                               files.push_back(i->second);
+       for(const auto &kvp: build_graph.get_targets())
+               if(kvp.second->get_package()==&package && !kvp.second->is_buildable())
+                       if(find(files.begin(), files.end(), kvp.second)==files.end())
+                               files.push_back(kvp.second);
 
        const Toolchain &toolchain = builder.get_toolchain();
        string archive_name = package.get_name();
index 584822a1074b06a1fb959714cfbb463b63c54bbc..f4b43a82c8c32e7ffa016f9a57f00004174f5875 100644 (file)
@@ -47,23 +47,23 @@ Target *SourceGenerator::create_target(const list<Target *> &sources, const stri
        }
 
        Target *primary = 0;
-       for(list<string>::const_iterator i=out_suffixes.begin(); i!=out_suffixes.end(); ++i)
+       for(const string &s: out_suffixes)
        {
-               Tool *tool = builder.get_toolchain().get_tool_for_suffix(*i, true);
+               Tool *tool = builder.get_toolchain().get_tool_for_suffix(s, true);
                if(tool)
                {
-                       FS::Path fn = pkg->get_temp_directory()/"generated"/subdir/(base+*i);
+                       FS::Path fn = pkg->get_temp_directory()/"generated"/subdir/(base+s);
                        Target *target = tool->create_source(*comp, fn);
                        target->set_tool(*this);
-                       for(list<Target *>::const_iterator j=sources.begin(); j!=sources.end(); ++j)
-                               target->add_dependency(**j);
+                       for(Target *t: sources)
+                               target->add_dependency(*t);
                        if(primary)
                                primary->add_side_effect(*target);
                        else
                                primary = target;
                }
                else
-                       throw runtime_error("No tool found for suffix "+*i);
+                       throw runtime_error("No tool found for suffix "+s);
        }
 
        return primary;
@@ -78,9 +78,8 @@ Task *SourceGenerator::run(const Target &target) const
        args.push_back(executable->get_path().str());
        args.insert(args.end(), arguments.begin(), arguments.end());
 
-       const Target::Dependencies &deps = target.get_dependencies();
-       for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
-               if(const TemplateFile *tmpl = dynamic_cast<const TemplateFile *>(*i))
+       for(const Target *d: target.get_dependencies())
+               if(const TemplateFile *tmpl = dynamic_cast<const TemplateFile *>(d))
                        args.push_back(FS::relative(tmpl->get_path(), work_dir).str());
 
        if(!out_argument.empty())
index b98cd75f02c49108e047b8bebc42b2321d1b86bc..a89feb245c7c13ad50f4ad72920202ba328caed2 100644 (file)
@@ -1,5 +1,5 @@
-#include <algorithm>
 #include <cstdlib>
+#include <msp/core/algorithm.h>
 #include <msp/core/maputils.h>
 #include <msp/fs/utils.h>
 #include <msp/io/print.h>
@@ -42,8 +42,8 @@ SourcePackage::SourcePackage(Builder &b, const string &n, const FS::Path &f):
 
 SourcePackage::~SourcePackage()
 {
-       for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
-               delete *i;
+       for(Component *c: components)
+               delete c;
 }
 
 FS::Path SourcePackage::get_temp_directory() const
@@ -73,9 +73,9 @@ FS::Path SourcePackage::get_output_directory() const
 
 const Component &SourcePackage::get_component(const string &n) const
 {
-       for(ComponentList::const_iterator i=components.begin(); i!=components.end(); ++i)
-               if((*i)->get_name()==n)
-                       return **i;
+       auto i = find_if(components, [&n](const Component *c){ return c->get_name()==n; });
+       if(i!=components.end())
+               return **i;
        throw key_error(n);
 }
 
@@ -106,12 +106,12 @@ void SourcePackage::do_prepare()
        build_info.incpath.push_back((builder.get_prefix()/"include").str());
        build_info.libpath.push_back((builder.get_prefix()/"lib").str());
 
-       for(FeatureList::iterator i=features.begin(); i!=features.end(); ++i)
+       for(const Feature &f: features)
        {
-               string ident = "WITH_"+toupper(i->name);
-               string value = config.get_option("with_"+i->name).value;
+               string ident = "WITH_"+toupper(f.name);
+               string value = config.get_option("with_"+f.name).value;
 
-               if(i->choices.empty())
+               if(f.choices.empty())
                {
                        if(!lexical_cast<bool>(value))
                                continue;
@@ -119,22 +119,22 @@ void SourcePackage::do_prepare()
                }
 
                build_info.defines[ident] = value;
-               if(i->exported)
+               if(f.exported)
                        export_binfo.defines[ident] = value;
        }
 
-       for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
+       for(Component *c: components)
        {
-               (*i)->prepare();
-               (*i)->create_build_info();
+               c->prepare();
+               c->create_build_info();
 
-               (*i)->update_exported_build_info(export_binfo);
+               c->update_exported_build_info(export_binfo);
        }
 
        cache.load();
 
-       for(ComponentList::iterator i=components.begin(); i!=components.end(); ++i)
-               (*i)->create_targets();
+       for(Component *c: components)
+               c->create_targets();
 
        const Architecture &arch = builder.get_native_arch();
        if(!export_binfo.libs.empty())
index 92a3af044cfc1b55de875b3414a25b9226125684..853d1b45c4916557321703b9a58d9862644b309f 100644 (file)
@@ -15,8 +15,8 @@ StaticLibrary::StaticLibrary(Builder &b, const Component &c, const list<ObjectFi
        FileTarget(b, c.get_package(), c.get_package().get_output_directory()/generate_filename(c))
 {
        component = &c;
-       for(list<ObjectFile *>::const_iterator i=objs.begin(); i!=objs.end(); ++i)
-               add_dependency(**i);
+       for(ObjectFile *o: objs)
+               add_dependency(*o);
 
        install_location = "lib";
        nested_build_sig = true;
index 6dee843df7ef4de8bee1baae45509a7fb2f34699..46f95caea31c516d8fb7b6acd6a64d376f39204b 100644 (file)
@@ -23,8 +23,8 @@ Target *Tar::create_target(const list<Target *> &sources, const string &arg)
                throw invalid_argument("Tar::create_target");
 
        TarBall *tarball = new TarBall(builder, *sources.front()->get_package(), arg);
-       for(list<Target *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
-               tarball->add_dependency(**i);
+       for(Target *s: sources)
+               tarball->add_dependency(*s);
 
        tarball->set_tool(*this);
 
@@ -49,10 +49,9 @@ void Tar::Worker::main()
        FS::Path basedir = FS::basepart(FS::basename(tarball.get_path()));
 
        IO::File out(tarball.get_path().str(), IO::M_WRITE);
-       const Target::Dependencies &deps = tarball.get_dependencies();
-       for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
+       for(Target *d: tarball.get_dependencies())
        {
-               FileTarget *ft = dynamic_cast<FileTarget *>(*i);
+               FileTarget *ft = dynamic_cast<FileTarget *>(d);
                if(!ft)
                        continue;
 
index 9006a570cb360f42c00589bd08abc7e54b25ca05..49a769371739044f8ae3200198273979391c15ad 100644 (file)
@@ -59,16 +59,16 @@ Target *Target::get_buildable_target()
                return 0;
 
        bool self_ok = state!=BUILDING;
-       for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
+       for(Target *d: depends)
        {
                // Avoid infinite recursion if a target repends on its own side effect
-               if(find(side_effects.begin(), side_effects.end(), *i)!=side_effects.end())
+               if(find(side_effects.begin(), side_effects.end(), d)!=side_effects.end())
                        continue;
 
-               Target *tgt = (*i)->get_buildable_target();
+               Target *tgt = d->get_buildable_target();
                if(tgt)
                        return tgt;
-               else if((*i)->needs_rebuild())
+               else if(d->needs_rebuild())
                        self_ok = false;
        }
 
@@ -81,8 +81,8 @@ Target *Target::get_buildable_target()
 void Target::set_tool(Tool &t)
 {
        tool = &t;
-       for(Dependencies::const_iterator i=side_effects.begin(); i!=side_effects.end(); ++i)
-               (*i)->set_tool(t);
+       for(Target *s: side_effects)
+               s->set_tool(t);
 }
 
 void Target::collect_build_info(BuildInfo &binfo) const
@@ -146,13 +146,13 @@ void Target::prepare()
                broken |= (component && !component->get_problems().empty());
        }
 
-       for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
+       for(Target *d: depends)
        {
-               (*i)->prepare();
-               broken |= (*i)->is_broken();
+               d->prepare();
+               broken |= d->is_broken();
        }
-       for(Dependencies::iterator i=trans_depends.begin(); i!=trans_depends.end(); ++i)
-               (*i)->prepare();
+       for(Target *d: trans_depends)
+               d->prepare();
 
        check_rebuild();
        if(broken)
@@ -160,8 +160,8 @@ void Target::prepare()
        else if(state==PREPARING)
                state = UPTODATE;
 
-       for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
-               (*i)->signal_bubble_rebuild.connect(sigc::mem_fun(this, &Target::check_rebuild));
+       for(Target *d: depends)
+               d->signal_bubble_rebuild.connect(sigc::mem_fun(this, &Target::check_rebuild));
 }
 
 Task *Target::build()
@@ -174,8 +174,8 @@ Task *Target::build()
        state = BUILDING;
 
        build(*task);
-       for(Dependencies::const_iterator i=side_effects.begin(); i!=side_effects.end(); ++i)
-               (*i)->build(*task);
+       for(Target *s: side_effects)
+               s->build(*task);
 
        return task;
 }
@@ -186,8 +186,8 @@ void Target::build_finished(bool success)
        if(success)
        {
                modified();
-               for(Dependencies::const_iterator i=side_effects.begin(); i!=side_effects.end(); ++i)
-                       (*i)->build_finished(success);
+               for(Target *s: side_effects)
+                       s->build_finished(success);
                signal_modified.emit();
        }
 }
index 75b725ede8657cc760efaa07d0bb92456b51975e..d969a7afa495f4c7076b5a8583b94679b0f25650 100644 (file)
@@ -22,16 +22,16 @@ void Task::set_unlink(bool u)
 
 void Task::prepare()
 {
-       for(list<FS::Path>::const_iterator i=files.begin(); i!=files.end(); ++i)
+       for(const FS::Path &f: files)
        {
-               if(FS::exists(*i))
+               if(FS::exists(f))
                {
                        // If the file exists, the directory it's in must exist too
-                       FS::unlink(*i);
+                       FS::unlink(f);
                }
                else
                {
-                       FS::Path dir = FS::dirname(*i);
+                       FS::Path dir = FS::dirname(f);
                        if(!FS::exists(dir))
                                FS::mkpath(dir, 0755);
                }
index 953fe1147a660df9f429f7a8f7e9f7cef2f709bc..8790c83dca0737e186a868900cc8d2665343484b 100644 (file)
@@ -1,3 +1,4 @@
+#include <algorithm>
 #include <msp/core/maputils.h>
 #include "tool.h"
 #include "toolchain.h"
@@ -7,10 +8,10 @@ using namespace Msp;
 
 Toolchain::~Toolchain()
 {
-       for(ToolMap::iterator i=tools.begin(); i!=tools.end(); ++i)
-               delete i->second;
-       for(ToolchainList::iterator i=chains.begin(); i!=chains.end(); ++i)
-               delete *i;
+       for(const auto &kvp: tools)
+               delete kvp.second;
+       for(Toolchain *c: chains)
+               delete c;
 }
 
 void Toolchain::add_tool(Tool *tool)
@@ -27,19 +28,16 @@ bool Toolchain::has_tool(const string &tag) const
 {
        if(tools.count(tag))
                return true;
-       for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i)
-               if((*i)->has_tool(tag))
-                       return true;
-       return false;
+       return any_of(chains.begin(), chains.end(), [&tag](Toolchain *tc){ return tc->has_tool(tag); });
 }
 
 Tool &Toolchain::get_tool(const string &tag) const
 {
        if(!tools.count(tag))
        {
-               for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i)
-                       if((*i)->has_tool(tag))
-                               return (*i)->get_tool(tag);
+               for(const Toolchain *c: chains)
+                       if(c->has_tool(tag))
+                               return c->get_tool(tag);
        }
 
        return *get_item(tools, tag);
@@ -47,12 +45,12 @@ Tool &Toolchain::get_tool(const string &tag) const
 
 Tool *Toolchain::get_tool_for_suffix(const string &suffix, bool aux) const
 {
-       for(ToolMap::const_iterator i=tools.begin(); i!=tools.end(); ++i)
-               if(i->second->accepts_suffix(suffix, aux))
-                       return i->second;
+       for(const auto &kvp: tools)
+               if(kvp.second->accepts_suffix(suffix, aux))
+                       return kvp.second;
 
-       for(ToolchainList::const_iterator i=chains.begin(); i!=chains.end(); ++i)
-               if(Tool *tool = (*i)->get_tool_for_suffix(suffix, aux))
+       for(const Toolchain *c: chains)
+               if(Tool *tool = c->get_tool_for_suffix(suffix, aux))
                        return tool;
 
        return 0;
index a173829941da9bb0adc18bb2ac103dea9625d354..8535197f03332bd393f8f09a011dc9de0b2d3c59 100644 (file)
@@ -43,13 +43,13 @@ void VcxProjectGenerator::Worker::main()
 
        IO::print(out, "\t<ItemGroup Label=\"ProjectConfigurations\">\n");
        vector<string> build_types = builder.get_build_types();
-       const char *platforms[] = { "Win32", "x64", 0 };
-       for(const char **i=platforms; *i; ++i)
-               for(vector<string>::const_iterator j=build_types.begin(); j!=build_types.end(); ++j)
+       const char *platforms[] = { "Win32", "x64" };
+       for(const char *p: platforms)
+               for(const string &b: build_types)
                {
-                       IO::print(out, "\t\t<ProjectConfiguration Include=\"%s|%s\">\n", *j, *i);
-                       IO::print(out, "\t\t\t<Configuration>%s</Configuration>\n", *j);
-                       IO::print(out, "\t\t\t<Platform>%s</Platform>\n", *i);
+                       IO::print(out, "\t\t<ProjectConfiguration Include=\"%s|%s\">\n", b, p);
+                       IO::print(out, "\t\t\t<Configuration>%s</Configuration>\n", b);
+                       IO::print(out, "\t\t\t<Platform>%s</Platform>\n", p);
                        IO::print(out, "\t\t</ProjectConfiguration>\n");
                }
        IO::print(out, "\t</ItemGroup>\n");
@@ -62,20 +62,19 @@ void VcxProjectGenerator::Worker::main()
 
        IO::print(out, "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n");
 
-       const Target *world = builder.get_build_graph().get_target("world");
-       const Target::Dependencies &world_deps = world->get_dependencies();
        const Executable *exe = 0;
-       for(Target::Dependencies::const_iterator i=world_deps.begin(); (!exe && i!=world_deps.end()); ++i)
-               if((*i)->get_package()==&spkg)
-                       exe = dynamic_cast<const Executable *>(*i);
+       for(const Target *t: builder.get_build_graph().get_target("world")->get_dependencies())
+               if(t->get_package()==&spkg)
+                       if((exe = dynamic_cast<const Executable *>(t)))
+                               break;
 
        const char *argv0 = Application::get_argv0();
        const string &toolchain = builder.get_current_arch().get_toolchain();
-       for(const char **i=platforms; *i; ++i)
-               for(vector<string>::const_iterator j=build_types.begin(); j!=build_types.end(); ++j)
+       for(const char *p: platforms)
+               for(const string &b: build_types)
                {
-                       string base_cmd = format("%s --arch=%s-%s --build-type=%s --prefix=%s", argv0, *i, toolchain, *j, builder.get_prefix());
-                       IO::print(out, "\t<PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='%s|%s'\" Label=\"Configuration\">\n", *j, *i);
+                       string base_cmd = format("%s --arch=%s-%s --build-type=%s --prefix=%s", argv0, p, toolchain, b, builder.get_prefix());
+                       IO::print(out, "\t<PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='%s|%s'\" Label=\"Configuration\">\n", b, p);
                        IO::print(out, "\t\t<ConfigurationType>MakeFile</ConfigurationType>\n");
                        IO::print(out, "\t\t<NMakeBuildCommandLine>%s</NMakeBuildCommandLine>\n", base_cmd);
                        IO::print(out, "\t\t<NMakeCleanCommandLine>%s -c</NMakeCleanCommandLine>\n", base_cmd);
@@ -87,21 +86,20 @@ void VcxProjectGenerator::Worker::main()
 
        IO::print(out, "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n");
 
-       const BuildGraph::TargetMap &targets = builder.get_build_graph().get_targets();
        vector<const FileTarget *> sources;
        vector<const FileTarget *> includes;
        vector<const FileTarget *> others;
        BuildInfo build_info;
-       for(BuildGraph::TargetMap::const_iterator i=targets.begin(); i!=targets.end(); ++i)
-               if(i->second->get_package()==&spkg)
+       for(const auto &kvp: builder.get_build_graph().get_targets())
+               if(kvp.second->get_package()==&spkg)
                {
-                       if(i->second->is_buildable())
+                       if(kvp.second->is_buildable())
                        {
                                BuildInfo tgt_binfo;
-                               i->second->collect_build_info(tgt_binfo);
+                               kvp.second->collect_build_info(tgt_binfo);
                                build_info.update_from(tgt_binfo, BuildInfo::CHAINED);
                        }
-                       else if(const FileTarget *file = dynamic_cast<const FileTarget *>(i->second))
+                       else if(const FileTarget *file = dynamic_cast<const FileTarget *>(kvp.second))
                        {
                                if(dynamic_cast<const CSourceFile *>(file))
                                {
@@ -120,25 +118,25 @@ void VcxProjectGenerator::Worker::main()
        {
                IO::print(out, "\t<PropertyGroup>\n");
                string path_str;
-               for(BuildInfo::PathList::const_iterator i=build_info.incpath.begin(); i!=build_info.incpath.end(); ++i)
-                       append(path_str, ";", i->str());
+               for(const FS::Path &p: build_info.incpath)
+                       append(path_str, ";", p.str());
                IO::print(out, "\t\t<NMakeIncludeSearchPath>%s</NMakeIncludeSearchPath>\n", path_str);
                IO::print(out, "\t</PropertyGroup>\n");
        }
 
        IO::print(out, "\t<ItemGroup>\n");
-       for(vector<const FileTarget *>::const_iterator i=sources.begin(); i!=sources.end(); ++i)
-               IO::print(out, "\t\t<ClCompile Include=\"%s\" />\n", (*i)->get_path());
+       for(const FileTarget *s: sources)
+               IO::print(out, "\t\t<ClCompile Include=\"%s\" />\n", s->get_path());
        IO::print(out, "\t</ItemGroup>\n");
 
        IO::print(out, "\t<ItemGroup>\n");
-       for(vector<const FileTarget *>::const_iterator i=includes.begin(); i!=includes.end(); ++i)
-               IO::print(out, "\t\t<ClInclude Include=\"%s\" />\n", (*i)->get_path());
+       for(const FileTarget *i: includes)
+               IO::print(out, "\t\t<ClInclude Include=\"%s\" />\n", i->get_path());
        IO::print(out, "\t</ItemGroup>\n");
 
        IO::print(out, "\t<ItemGroup>\n");
-       for(vector<const FileTarget *>::const_iterator i=others.begin(); i!=others.end(); ++i)
-               IO::print(out, "\t\t<None Include=\"%s\" />\n", (*i)->get_path());
+       for(const FileTarget *t: others)
+               IO::print(out, "\t\t<None Include=\"%s\" />\n", t->get_path());
        IO::print(out, "\t</ItemGroup>\n");
 
        IO::print(out, "\t<Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n");
index e240fb9e777b74590f39dfe23d2d417d18fb7303..935600de085f6409a157a0303e68b7f39c168da1 100644 (file)
@@ -51,21 +51,21 @@ FileTarget *VirtualFileSystem::find_header(const string &name, Tool *tool, const
                combined_path.insert(combined_path.end(), syspath.begin(), syspath.end());
        }
 
-       for(list<FS::Path>::const_iterator i=combined_path.begin(); i!=combined_path.end(); ++i)
+       for(const FS::Path &p: combined_path)
        {
-               FS::Path filename = *i/name;
+               FS::Path filename = p/name;
                if(FileTarget *tgt = get_target(filename))
                {
-                       builder.get_logger().log("vfs", format("Header %s found in %s as existing %s", name, i->str(), tgt->get_type()));
+                       builder.get_logger().log("vfs", format("Header %s found in %s as existing %s", name, p.str(), tgt->get_type()));
                        return tgt;
                }
                else if(file_exists(filename))
                {
-                       builder.get_logger().log("vfs", format("Header %s found in %s", name, i->str()));
+                       builder.get_logger().log("vfs", format("Header %s found in %s", name, p.str()));
                        return dynamic_cast<FileTarget *>(tool->create_source(filename));
                }
 
-               builder.get_logger().log("vfs", format("Header %s not found in %s", name, i->str()));
+               builder.get_logger().log("vfs", format("Header %s not found in %s", name, p.str()));
        }
 
        return 0;
@@ -97,20 +97,20 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath
        if(mode!=BuildInfo::FORCE_DYNAMIC)
                static_names = Pattern::apply_list(arch.get_patterns<StaticLibrary>(), lib);
 
-       for(list<FS::Path>::const_iterator i=combined_path.begin(); i!=combined_path.end(); ++i)
+       for(const FS::Path &p: combined_path)
        {
                const list<string> *cur_names = (mode>=BuildInfo::DYNAMIC ? &shared_names : &static_names);
-               for(list<string>::const_iterator j=cur_names->begin(); j!=cur_names->end(); )
+               for(auto j=cur_names->begin(); j!=cur_names->end(); )
                {
-                       FS::Path filename = *i / *j;
+                       FS::Path filename = p / *j;
                        if(FileTarget *tgt = get_target(filename))
                        {
-                               builder.get_logger().log("vfs", format("Library %s (%s) found in %s as existing %s", lib, *j, i->str(), tgt->get_type()));
+                               builder.get_logger().log("vfs", format("Library %s (%s) found in %s as existing %s", lib, *j, p.str(), tgt->get_type()));
                                return tgt;
                        }
                        else if(file_exists(filename))
                        {
-                               builder.get_logger().log("vfs", format("Library %s (%s) found in %s", lib, *j, i->str()));
+                               builder.get_logger().log("vfs", format("Library %s (%s) found in %s", lib, *j, p.str()));
                                if(cur_names==&shared_names)
                                {
                                        if(use_import_lib)
@@ -133,7 +133,7 @@ FileTarget *VirtualFileSystem::find_library(const string &lib, const SearchPath
                        }
                }
 
-               builder.get_logger().log("vfs", format("Library %s not found in %s", lib, i->str()));
+               builder.get_logger().log("vfs", format("Library %s not found in %s", lib, p.str()));
        }
 
        return 0;
@@ -149,9 +149,8 @@ FileTarget *VirtualFileSystem::find_binary(const string &name)
                string env_path = Msp::getenv("PATH");
                if(!env_path.empty())
                {
-                       vector<string> parts = split(env_path, ':');
-                       for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
-                               path.push_back(*i);
+                       for(const string &p: split(env_path, ':'))
+                               path.push_back(p);
                }
                else
                {
@@ -160,21 +159,21 @@ FileTarget *VirtualFileSystem::find_binary(const string &name)
                }
        }
 
-       for(SearchPath::const_iterator i=path.begin(); i!=path.end(); ++i)
+       for(const FS::Path &p: path)
        {
-               FS::Path filename = *i/name;
+               FS::Path filename = p/name;
                if(FileTarget *tgt = get_target(filename))
                {
-                       builder.get_logger().log("vfs", format("Binary %s found in %s as existing %s", name, *i, tgt->get_type()));
+                       builder.get_logger().log("vfs", format("Binary %s found in %s as existing %s", name, p, tgt->get_type()));
                        return tgt;
                }
                else if(file_exists(filename))
                {
-                       builder.get_logger().log("vfs", format("Binary %s found in %s", name, *i));
+                       builder.get_logger().log("vfs", format("Binary %s found in %s", name, p));
                        return new Executable(builder, filename);
                }
 
-               builder.get_logger().log("vfs", format("Binary %s not found in %s", name, *i));
+               builder.get_logger().log("vfs", format("Binary %s not found in %s", name, p));
        }
 
        return 0;
index a7b4cd73b35362d2d0586ecda7e570d2abaf8b07..44a352421270c5f7b2581c3c34973d583d6c69c7 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/core/algorithm.h>
 #include <msp/fs/path.h>
 #include <msp/fs/utils.h>
 #include "builder.h"
@@ -13,9 +14,9 @@ VirtualTarget::VirtualTarget(Builder &b, const string &n):
 void VirtualTarget::check_rebuild()
 {
        // Virtual targets are only rebuilt if their dependencies need rebuilding.
-       for(Dependencies::iterator i=depends.begin(); (i!=depends.end() && !needs_rebuild()); ++i)
-               if((*i)->needs_rebuild())
-                       mark_rebuild((*i)->get_name()+" needs rebuilding");
+       auto i = find_if(depends, [](Target *d){ return d->needs_rebuild(); });
+       if(i!=depends.end())
+               mark_rebuild((*i)->get_name()+" needs rebuilding");
 }
 
 Task *VirtualTarget::build()
index fd13d5f8c5f42a0b6035085ab72fb2d7b904d073..c667fc5b245dd2fa4fad60a16a1ab3c5be696b0e 100644 (file)
@@ -18,15 +18,14 @@ void VsSolutionFile::find_dependencies()
                add_dependency(*project);
 
        Package::Requirements reqs = package->get_required_packages();
-       for(Package::Requirements::iterator i=reqs.begin(); i!=reqs.end(); ++i)
+       for(auto i=reqs.begin(); i!=reqs.end(); ++i)
                if(const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(*i))
                {
                        if(FileTarget *project = builder.get_vfs().get_target(spkg->get_source_directory()/(spkg->get_name()+".vcxproj")))
                                add_dependency(*project);
 
-                       const Package::Requirements &rreqs = spkg->get_required_packages();
-                       for(Package::Requirements::const_iterator j=rreqs.begin(); j!=rreqs.end(); ++j)
-                               if(find(reqs, *j)==reqs.end())
-                                       reqs.push_back(*j);
+                       for(Package *r: spkg->get_required_packages())
+                               if(find(reqs, r)==reqs.end())
+                                       reqs.push_back(r);
                }
 }
index 43ed761cb52daa641388ad872596dacaa1ed30ce..0c60689a42094b3777256d1b4da9efa837ea487e 100644 (file)
@@ -33,43 +33,43 @@ VsSolutionGenerator::Worker::Worker(const VsSolutionFile &t):
 
 void VsSolutionGenerator::Worker::main()
 {
-       Builder &builder = target.get_package()->get_builder();
+       const SourcePackage &spkg = *target.get_package();
+       Builder &builder = spkg.get_builder();
 
        IO::BufferedFile out(target.get_path().str(), IO::M_WRITE);
        IO::print(out, "Microsoft Visual Studio Solution File, Format Version 12.00\n");
        IO::print(out, "MinimumVisualStudioVersion = 10.0.40219.1\n");
 
-       const Target::Dependencies &deps = target.get_dependencies();
        vector<const VcxProjectFile *> projects;
-       for(Target::Dependencies::const_iterator i=deps.begin(); i!=deps.end(); ++i)
-               if(const VcxProjectFile *project = dynamic_cast<const VcxProjectFile *>(*i))
+       for(const Target *t: target.get_dependencies())
+               if(const VcxProjectFile *project = dynamic_cast<const VcxProjectFile *>(t))
                        projects.push_back(project);
 
-       for(vector<const VcxProjectFile *>::const_iterator i=projects.begin(); i!=projects.end(); ++i)
+       for(const VcxProjectFile *p: projects)
        {
-               const SourcePackage *pkg = (*i)->get_package();
+               const SourcePackage *pkg = p->get_package();
                IO::print(out, "Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"%s\", \"%s\", \"{%s}\"\nEndProject\n",
-                       pkg->get_name(), (*i)->get_path(), (*i)->get_guid());
+                       pkg->get_name(), p->get_path(), p->get_guid());
        }
 
        vector<string> build_types = builder.get_build_types();
-       const char *platforms[] = { "x86", "x64", 0 };
+       const char *platforms[] = { "x86", "x64" };
 
        IO::print(out, "Global\n");
        IO::print(out, "\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n");
-       for(vector<string>::const_iterator i=build_types.begin(); i!=build_types.end(); ++i)
-               for(const char **j=platforms; *j; ++j)
-                       IO::print(out, "\t\t%s|%s = %s|%s\n", *i, *j, *i, *j);
+       for(const string &t: build_types)
+               for(const char *p: platforms)
+                       IO::print(out, "\t\t%s|%s = %s|%s\n", t, p, t, p);
        IO::print(out, "\tEndGlobalSection\n");
        IO::print(out, "\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n");
-       for(vector<const VcxProjectFile *>::const_iterator i=projects.begin(); i!=projects.end(); ++i)
-               for(vector<string>::const_iterator j=build_types.begin(); j!=build_types.end(); ++j)
-                       for(const char **k=platforms; *k; ++k)
+       for(const VcxProjectFile *p: projects)
+               for(const string &t: build_types)
+                       for(const char *f: platforms)
                        {
-                               const char *project_platform = (!strcmp(*k, "x86") ? "Win32" : *k);
-                               IO::print(out, "\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n", (*i)->get_guid(), *j, *k, *j, project_platform);
-                               if(i==projects.begin())
-                                       IO::print(out, "\t\t{%s}.%s|%s.Build.0 = %s|%s\n", (*i)->get_guid(), *j, *k, *j, project_platform);
+                               const char *project_platform = (!strcmp(f, "x86") ? "Win32" : f);
+                               IO::print(out, "\t\t{%s}.%s|%s.ActiveCfg = %s|%s\n", p->get_guid(), t, f, t, project_platform);
+                               if(p->get_package()==&spkg)
+                                       IO::print(out, "\t\t{%s}.%s|%s.Build.0 = %s|%s\n", p->get_guid(), t, f, t, project_platform);
                        }
        IO::print(out, "\tEndGlobalSection\n");
        IO::print(out, "EndGlobal\n");