diff options
author | Murray Cumming <murrayc@murrayc.com> | 2013-06-26 10:46:22 +0200 |
---|---|---|
committer | Murray Cumming <murrayc@murrayc.com> | 2015-07-09 23:26:12 +0200 |
commit | 2cad48817914213f41fd7b85cac0f650b0f9d7ce (patch) | |
tree | 8b721ddd53e7d5528e9c38c418b6abc6b6a0f1c3 /examples | |
parent | 1b23397544bd031331b3110be1b790659bdceb24 (diff) | |
download | glibmm-2cad48817914213f41fd7b85cac0f650b0f9d7ce.tar.gz |
C++11: Use range-based for loops.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/dbus/client_bus_listnames.cc | 4 | ||||
-rw-r--r-- | examples/keyfile/main.cc | 4 | ||||
-rw-r--r-- | examples/markup/parser.cc | 4 | ||||
-rw-r--r-- | examples/network/resolver.cc | 16 | ||||
-rw-r--r-- | examples/options/main.cc | 9 |
5 files changed, 18 insertions, 19 deletions
diff --git a/examples/dbus/client_bus_listnames.cc b/examples/dbus/client_bus_listnames.cc index b46fdcf8..0a49d739 100644 --- a/examples/dbus/client_bus_listnames.cc +++ b/examples/dbus/client_bus_listnames.cc @@ -60,8 +60,8 @@ void on_dbus_proxy_available(Glib::RefPtr<Gio::AsyncResult>& result) std::cout << "The names on the message bus are:" << std::endl; - for(unsigned i = 0; i < names.size(); i++) - std::cout << names[i] << "." << std::endl; + for(const auto& i : names) + std::cout << i << "." << std::endl; } catch(const Glib::Error& error) { diff --git a/examples/keyfile/main.cc b/examples/keyfile/main.cc index 533bc532..2f56b21a 100644 --- a/examples/keyfile/main.cc +++ b/examples/keyfile/main.cc @@ -68,8 +68,8 @@ int main(int, char**) { const std::vector<int> values = keyfile.get_integer_list("Another Group", "Numbers"); - for(std::vector<int>::const_iterator p = values.begin(); p != values.end(); ++p) - std::cout << "Number list value: item=" << *p << std::endl; + for(const auto& p : values) + std::cout << "Number list value: item=" << p << std::endl; } catch(const Glib::KeyFileError& ex) { diff --git a/examples/markup/parser.cc b/examples/markup/parser.cc index 30423a66..54bac451 100644 --- a/examples/markup/parser.cc +++ b/examples/markup/parser.cc @@ -84,9 +84,9 @@ void DumpParser::on_start_element(Glib::Markup::ParseContext&, indent(); std::cout << '<' << element_name; - for(AttributeMap::const_iterator p = attributes.begin(); p != attributes.end(); ++p) + for(const auto& p : attributes) { - std::cout << ' ' << p->first << "=\"" << p->second << '"'; + std::cout << ' ' << p.first << "=\"" << p.second << '"'; } std::cout << ">\n"; diff --git a/examples/network/resolver.cc b/examples/network/resolver.cc index 4112c146..ca630d9d 100644 --- a/examples/network/resolver.cc +++ b/examples/network/resolver.cc @@ -95,10 +95,9 @@ print_resolved_addresses (const Glib::ustring& name, { G_LOCK (response); std::cout << Glib::ustring::compose ("Name: %1\n", name); - for (std::list<Glib::RefPtr<Gio::InetAddress> >::const_iterator iter = addresses.begin (); - iter != addresses.end (); ++iter) + for (const auto& i : addresses) { - std::cout << Glib::ustring::compose ("Address: %1\n", (*iter)->to_string ()); + std::cout << Glib::ustring::compose ("Address: %1\n", i->to_string ()); } std::cout << std::endl; @@ -112,15 +111,14 @@ print_resolved_service (const Glib::ustring& service, { G_LOCK (response); std::cout << Glib::ustring::compose ("Service: %1\n", service); - for (std::list<Gio::SrvTarget>::const_iterator iter = targets.begin (); - iter != targets.end (); ++iter) + for (const auto& i : targets) { std::cout << Glib::ustring::compose ("%1:%2 (pri %3, weight %4)\n", - iter->get_hostname (), - iter->get_port (), - iter->get_priority (), - iter->get_weight ()); + i.get_hostname (), + i.get_port (), + i.get_priority (), + i.get_weight ()); } std::cout << std::endl; diff --git a/examples/options/main.cc b/examples/options/main.cc index 1ef290b1..baa36150 100644 --- a/examples/options/main.cc +++ b/examples/options/main.cc @@ -221,17 +221,18 @@ int main(int argc, char** argv) //This one shows the results of multiple instance of the same option, such as --list=1 --list=a --list=b std::cout << " list = "; - for(Glib::OptionGroup::vecustrings::const_iterator iter = group.m_arg_list.begin(); iter != group.m_arg_list.end(); ++iter) + for(const auto& i : group.m_arg_list) + { - std::cout << *iter << ", "; + std::cout << i << ", "; } std::cout << std::endl; //This one shows the remaining arguments on the command line, which had no name= form: std::cout << " remaining = "; - for(Glib::OptionGroup::vecustrings::const_iterator iter = group.m_remaining_list.begin(); iter != group.m_remaining_list.end(); ++iter) + for(const auto& i : group.m_remaining_list) { - std::cout << *iter << ", "; + std::cout << i << ", "; } std::cout << std::endl; |