[glibmm] C++11: Use range-based for loops.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] C++11: Use range-based for loops.
- Date: Thu, 9 Jul 2015 21:37:52 +0000 (UTC)
commit 2cad48817914213f41fd7b85cac0f650b0f9d7ce
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Jun 26 10:46:22 2013 +0200
C++11: Use range-based for loops.
examples/dbus/client_bus_listnames.cc | 4 ++--
examples/keyfile/main.cc | 4 ++--
examples/markup/parser.cc | 4 ++--
examples/network/resolver.cc | 16 +++++++---------
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 b46fdcf..0a49d73 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 533bc53..2f56b21 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 30423a6..54bac45 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 4112c14..ca630d9 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 1ef290b..baa3615 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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]