summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2015-07-15 13:29:24 +0200
committerMurray Cumming <murrayc@murrayc.com>2015-07-15 14:08:54 +0200
commitfc715b2e6bcbe92ae3125026f5e593a73d7bfa70 (patch)
treeb4e1a41994205d700b825a167fdfcfb7814d581c
parente1dba38d6b9a6d08c6ddb868a9dae825f4c10932 (diff)
downloadglibmm-fc715b2e6bcbe92ae3125026f5e593a73d7bfa70.tar.gz
C++11: More uses of range-based for.
-rw-r--r--gio/src/application.ccg6
-rw-r--r--glib/src/optiongroup.ccg9
-rw-r--r--glib/src/variant.ccg5
-rw-r--r--glib/src/variant.hg12
-rw-r--r--tests/glibmm_variant/main.cc14
5 files changed, 19 insertions, 27 deletions
diff --git a/gio/src/application.ccg b/gio/src/application.ccg
index 59f17dd7..8543d201 100644
--- a/gio/src/application.ccg
+++ b/gio/src/application.ccg
@@ -39,11 +39,9 @@ struct ExtraApplicationData
~ExtraApplicationData()
{
- for (std::vector<gchar*>::iterator iter = option_entry_strings.begin();
- iter != option_entry_strings.end(); ++iter)
+ for(auto str : option_entry_strings)
{
- g_free(*iter);
- *iter = 0;
+ g_free(str);
}
}
};
diff --git a/glib/src/optiongroup.ccg b/glib/src/optiongroup.ccg
index cffa3435..42313bcf 100644
--- a/glib/src/optiongroup.ccg
+++ b/glib/src/optiongroup.ccg
@@ -157,10 +157,9 @@ gboolean OptionGroup::post_parse_callback(GOptionContext* context,
//The C args have now been given values by g_option_context_parse().
//Convert C values to C++ values:
- for(type_map_entries::iterator iter = option_group->map_entries_.begin();
- iter != option_group->map_entries_.end(); ++iter)
+ for(auto& the_pair : option_group->map_entries_)
{
- auto& cpp_entry = iter->second;
+ auto& cpp_entry = the_pair.second;
cpp_entry.convert_c_to_cpp();
}
@@ -286,9 +285,9 @@ OptionGroup::OptionGroup(GOptionGroup* castitem)
OptionGroup::~OptionGroup()
{
//Free any C types that were allocated during add_entry():
- for(type_map_entries::iterator iter = map_entries_.begin(); iter != map_entries_.end(); ++iter)
+ for(auto& the_pair : map_entries_)
{
- auto& cpp_entry = iter->second;
+ auto& cpp_entry = the_pair.second;
cpp_entry.release_c_arg();
}
diff --git a/glib/src/variant.ccg b/glib/src/variant.ccg
index fd47549c..af64f619 100644
--- a/glib/src/variant.ccg
+++ b/glib/src/variant.ccg
@@ -451,11 +451,10 @@ Variant<type_vec_ustring>::create(const type_vec_ustring& data)
GVariantBuilder* builder = g_variant_builder_new(array_variant_type.gobj());
// Add the elements of the vector into the builder.
- for(type_vec_ustring::const_iterator iter = data.begin();
- iter < data.end(); iter++)
+ for(const auto& str : data)
{
g_variant_builder_add(builder,
- element_variant_type.get_string().c_str(), iter->c_str());
+ element_variant_type.get_string().c_str(), str.c_str());
}
// Create the variant using the builder.
diff --git a/glib/src/variant.hg b/glib/src/variant.hg
index b92d825a..5f9a440e 100644
--- a/glib/src/variant.hg
+++ b/glib/src/variant.hg
@@ -1090,10 +1090,9 @@ Variant< std::vector<T> >::create(const std::vector<T>& data)
GVariantBuilder* builder = g_variant_builder_new(array_variant_type.gobj());
// Add the elements of the vector into the builder.
- for(typename std::vector<T>::const_iterator iter = data.begin();
- iter < data.end(); iter++)
+ for(const auto& element : data)
{
- Glib::Variant<T> variant = Glib::Variant<T>::create(*iter);
+ Glib::Variant<T> variant = Glib::Variant<T>::create(element);
g_variant_builder_add_value(builder, variant.gobj());
}
@@ -1177,11 +1176,10 @@ Variant< std::map<K, V> >::create(const std::map<K, V>& data)
GVariantBuilder* builder = g_variant_builder_new(array_variant_type.gobj());
// Add the elements of the map into the builder.
- for(typename std::map<K, V>::const_iterator iter = data.begin();
- iter != data.end(); iter++)
+ for(const auto& element : data)
{
- Variant< std::pair<K, V> > dict_entry =
- Variant< std::pair<K, V> >::create(*iter);
+ auto dict_entry =
+ Variant< std::pair<K, V> >::create(element);
g_variant_builder_add_value(builder, dict_entry.gobj());
}
diff --git a/tests/glibmm_variant/main.cc b/tests/glibmm_variant/main.cc
index 484cb8f1..943f75a8 100644
--- a/tests/glibmm_variant/main.cc
+++ b/tests/glibmm_variant/main.cc
@@ -166,10 +166,8 @@ int main(int, char**)
ComplexDictType map = copy_complex_vector[i];
- for(ComplexDictType::const_iterator iter = map.begin();
- iter != map.end(); iter++)
+ for(const auto& entry : map)
{
- std::pair< Glib::ustring, Glib::Variant<int> > entry = *iter;
ostr << entry.first << " -> " << entry.second.get() << "." << std::endl;
}
ostr << std::endl;
@@ -309,12 +307,12 @@ void test_dynamic_cast_composite_types()
ostr << "Cast composite type (get_type_string()=" << derived.get_type_string()
<< ", variant_type().get_string()=" << derived.variant_type().get_string() << "): ";
composite_type var = derived.get();
- for (composite_type::const_iterator iter1 = var.begin(); iter1 != var.end(); ++iter1)
+ for (const auto& the_pair : var)
{
- ostr << "\n " << iter1->first << ":";
- const std::vector<std::string>& vec = iter1->second;
- for (std::vector<std::string>::const_iterator iter2 = vec.begin(); iter2 != vec.end(); ++iter2)
- ostr << " " << *iter2;
+ ostr << "\n " << the_pair.first << ":";
+ const auto& vec = the_pair.second;
+ for (const auto& str : vec)
+ ostr << " " << str;
}
ostr << std::endl;
}